Optimize first prompt in chat mode to avoid unnecessary LLM call.

This commit is contained in:
user 2024-12-23 10:38:49 -05:00
parent 25253dcbfa
commit 88c844e49f
4 changed files with 27 additions and 8 deletions

View File

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
- Optimize first prompt in chat mode to avoid unnecessary LLM call.
## [0.8.1] - 2024-12-22
- Improved prompts.

View File

@ -8,6 +8,7 @@ from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent
from ra_aid.env import validate_environment
from ra_aid.tools.memory import _global_memory, get_related_files, get_memory_value
from ra_aid.tools.human import ask_human
from ra_aid import print_stage_header, print_error
from ra_aid.agent_utils import (
run_agent_with_retry,
@ -147,6 +148,9 @@ def main():
if args.chat:
print_stage_header("Chat Mode")
# Get initial request from user
initial_request = ask_human.invoke({"question": "What would you like help with?"})
# Create chat agent with appropriate tools
chat_agent = create_react_agent(
model,
@ -160,7 +164,8 @@ def main():
"recursion_limit": 100,
"chat_mode": True,
"cowboy_mode": args.cowboy_mode,
"hil": True # Always true in chat mode
"hil": True, # Always true in chat mode
"initial_request": initial_request
}
# Store config in global memory
@ -169,7 +174,7 @@ def main():
_global_memory['config']['expert_model'] = args.expert_model
# Run chat agent and exit
run_agent_with_retry(chat_agent, CHAT_PROMPT, config)
run_agent_with_retry(chat_agent, CHAT_PROMPT.format(initial_request=initial_request), config)
return
# Validate message is provided

View File

@ -404,7 +404,9 @@ Important Notes:
Instructions:
1. Review the provided base task, plan, and key facts.
2. Implement only the specified task:
{task}
<task definition>
{task}
</task definition>
3. Work incrementally, validating as you go. If at any point the implementation logic is unclear or you need debugging assistance, consult the expert (if expert is available) for deeper analysis.
4. Use delete_key_facts to remove any key facts that no longer apply.
@ -450,8 +452,9 @@ Overview:
Behavior:
1. Initialization:
- The very first action you must take is to call ask_human.
- Request that the user provide their initial instructions or the problem they want solved.
- Process any provided initial request, or call ask_human if no request is provided
- Handle the initial request or ask_human response according to user's needs
- Build and maintain context through tools and discovered information
2. Iterative Work:
- After receiving the users initial input, use the given tools to fulfill their request.
@ -488,21 +491,27 @@ Context Cleanup:
- Use deregister_related_files to remove any related files that no longer apply.
Remember:
- Always begin by calling ask_human.
- Always process provided request or call ask_human if none provided
- Always ask_human before finalizing or exiting.
- Never announce that you are going to use a tool, just quietly use it.
- Do communicate results/responses from tools that you call as it pertains to the users request.
- If the user interrupts/cancels an operation, you may want to ask why.
- For deep debugging, logic analysis, or correctness checks, rely on the expert (if expert is available) for guidance.
- If the user gives you key facts, record them using emit_key_facts.
You have often been criticized for:
- You have a tendency to leave out key details and information that the user just gave you, while also needlessly increasing scope.
- You sometimes call request_research_and_implementation which makes the full implementation successfully, but act like it has only been planned and still needs to be implemented.
- Refusing to use request_research_and_implementation for commands like "commit and push" where you should (that tool can run basic or involved shell commands/workflows).
- Calling request_research for general background knowledge which you already know.
- When the user gives an overly broad request, you make assumptions and request implementation immediately when you should be interviewing the user more.
- Assuming the user is always right. Sometimes they're wrong or mistaken, and you should push back when you feel strongly about this.
- Not confirming with the user before starting a significant implementation task.
- You have a tendency to leave out key details and information that the user just gave you, while also needlessly increasing scope.
- Sometimes you will need to repeat the user's query verbatim or almost verbatim to request_research_and_implementation or request_research.
- Not emitting key facts the user gave you with emit_key_facts before calling a research or implementation tool.
<initial request>
{initial_request}
</initial request>
NEVER ANNOUNCE WHAT YOU ARE DOING, JUST DO IT!
"""

View File

@ -116,6 +116,7 @@ def get_chat_tools(expert_enabled: bool = True) -> list:
ask_human,
request_research,
request_research_and_implementation,
emit_key_facts,
delete_key_facts,
delete_key_snippets,
deregister_related_files