Improve prompts and fix web research prompt integration.

This commit is contained in:
AI Christianson 2024-12-27 15:26:54 -05:00
parent b8d231b5a1
commit f2ce6a7ab0
3 changed files with 44 additions and 28 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
- Fix logging on interrupt. - Fix logging on interrupt.
- Fix web research prompt.
## [0.10.2] - 2024-12-26 ## [0.10.2] - 2024-12-26

View File

@ -121,7 +121,7 @@ def run_research_agent(
research_only=research_only, research_only=research_only,
expert_enabled=expert_enabled, expert_enabled=expert_enabled,
human_interaction=hil, human_interaction=hil,
web_research_enabled=config.get('web_research', False) web_research_enabled=config.get('web_research_enabled', False)
) )
# Create agent # Create agent
@ -130,7 +130,7 @@ def run_research_agent(
# Format prompt sections # Format prompt sections
expert_section = EXPERT_PROMPT_SECTION_RESEARCH if expert_enabled else "" expert_section = EXPERT_PROMPT_SECTION_RESEARCH if expert_enabled else ""
human_section = HUMAN_PROMPT_SECTION_RESEARCH if hil else "" human_section = HUMAN_PROMPT_SECTION_RESEARCH if hil else ""
web_research_section = WEB_RESEARCH_PROMPT_SECTION_RESEARCH if config.get('web_research') else "" web_research_section = WEB_RESEARCH_PROMPT_SECTION_RESEARCH if config.get('web_research_enabled') else ""
# Get research context from memory # Get research context from memory
key_facts = _global_memory.get("key_facts", "") key_facts = _global_memory.get("key_facts", "")
@ -303,7 +303,7 @@ def run_planning_agent(
thread_id = str(uuid.uuid4()) thread_id = str(uuid.uuid4())
# Configure tools # Configure tools
tools = get_planning_tools(expert_enabled=expert_enabled, web_research_enabled=config.get('web_research', False)) tools = get_planning_tools(expert_enabled=expert_enabled, web_research_enabled=config.get('web_research_enabled', False))
# Create agent # Create agent
agent = create_react_agent(model, tools, checkpointer=memory) agent = create_react_agent(model, tools, checkpointer=memory)
@ -311,7 +311,7 @@ def run_planning_agent(
# Format prompt sections # Format prompt sections
expert_section = EXPERT_PROMPT_SECTION_PLANNING if expert_enabled else "" expert_section = EXPERT_PROMPT_SECTION_PLANNING if expert_enabled else ""
human_section = HUMAN_PROMPT_SECTION_PLANNING if hil else "" human_section = HUMAN_PROMPT_SECTION_PLANNING if hil else ""
web_research_section = WEB_RESEARCH_PROMPT_SECTION_PLANNING if config.get('web_research') else "" web_research_section = WEB_RESEARCH_PROMPT_SECTION_PLANNING if config.get('web_research_enabled') else ""
# Build prompt # Build prompt
planning_prompt = PLANNING_PROMPT.format( planning_prompt = PLANNING_PROMPT.format(
@ -390,7 +390,7 @@ def run_task_implementation_agent(
thread_id = str(uuid.uuid4()) thread_id = str(uuid.uuid4())
# Configure tools # Configure tools
tools = get_implementation_tools(expert_enabled=expert_enabled, web_research_enabled=config.get('web_research', False)) tools = get_implementation_tools(expert_enabled=expert_enabled, web_research_enabled=config.get('web_research_enabled', False))
# Create agent # Create agent
agent = create_react_agent(model, tools, checkpointer=memory) agent = create_react_agent(model, tools, checkpointer=memory)
@ -407,7 +407,7 @@ def run_task_implementation_agent(
work_log=get_memory_value('work_log'), work_log=get_memory_value('work_log'),
expert_section=EXPERT_PROMPT_SECTION_IMPLEMENTATION if expert_enabled else "", expert_section=EXPERT_PROMPT_SECTION_IMPLEMENTATION if expert_enabled else "",
human_section=HUMAN_PROMPT_SECTION_IMPLEMENTATION if _global_memory.get('config', {}).get('hil', False) else "", human_section=HUMAN_PROMPT_SECTION_IMPLEMENTATION if _global_memory.get('config', {}).get('hil', False) else "",
web_research_section=WEB_RESEARCH_PROMPT_SECTION_CHAT if config.get('web_research') else "" web_research_section=WEB_RESEARCH_PROMPT_SECTION_CHAT if config.get('web_research_enabled') else ""
) )
# Set up configuration # Set up configuration

View File

@ -12,7 +12,7 @@ These updated prompts include instructions to scale complexity:
# Expert-specific prompt sections # Expert-specific prompt sections
EXPERT_PROMPT_SECTION_RESEARCH = """ EXPERT_PROMPT_SECTION_RESEARCH = """
Expert Consultation (if expert is available): Expert Consultation:
If you need additional guidance, analysis, or verification (including code correctness checks and debugging): If you need additional guidance, analysis, or verification (including code correctness checks and debugging):
- Use emit_expert_context to provide all relevant context about what you've found - Use emit_expert_context to provide all relevant context about what you've found
- Wait for the expert response before proceeding with research - Wait for the expert response before proceeding with research
@ -20,7 +20,7 @@ Expert Consultation (if expert is available):
""" """
EXPERT_PROMPT_SECTION_PLANNING = """ EXPERT_PROMPT_SECTION_PLANNING = """
Expert Consultation (if expert is available): Expert Consultation:
If you need additional input, assistance, or any logic verification: If you need additional input, assistance, or any logic verification:
- First use emit_expert_context to provide all relevant context - First use emit_expert_context to provide all relevant context
- Wait for the expert's response before defining tasks in non-trivial scenarios - Wait for the expert's response before defining tasks in non-trivial scenarios
@ -28,7 +28,7 @@ Expert Consultation (if expert is available):
""" """
EXPERT_PROMPT_SECTION_IMPLEMENTATION = """ EXPERT_PROMPT_SECTION_IMPLEMENTATION = """
Expert Consultation (if expert is available): Expert Consultation:
If you have any doubts about logic, debugging, or best approaches (or how to test something thoroughly): If you have any doubts about logic, debugging, or best approaches (or how to test something thoroughly):
- Use emit_expert_context to provide context about your specific concern - Use emit_expert_context to provide context about your specific concern
- Ask the expert to perform deep analysis or correctness checks - Ask the expert to perform deep analysis or correctness checks
@ -36,7 +36,7 @@ Expert Consultation (if expert is available):
""" """
EXPERT_PROMPT_SECTION_CHAT = """ EXPERT_PROMPT_SECTION_CHAT = """
Expert Consultation (if expert is available): Expert Consultation:
If you need expert input during the interactive chat phase, or if any aspect of the logic or debugging is uncertain: If you need expert input during the interactive chat phase, or if any aspect of the logic or debugging is uncertain:
- Use emit_expert_context to provide the current conversation state, user requirements, and discovered details - Use emit_expert_context to provide the current conversation state, user requirements, and discovered details
- Ask the expert for advice on handling ambiguous user requests or complex technical challenges, and to verify correctness - Ask the expert for advice on handling ambiguous user requests or complex technical challenges, and to verify correctness
@ -68,31 +68,41 @@ Human Interaction:
- Wait for responses before proceeding - Wait for responses before proceeding
""" """
WEB_RESEARCH_PROMPT_SECTION_RESEARCH = """ WEB_RESEARCH_PROMPT_SECTION_RESEARCH = """
Web Research: Request web research when working with:
- Scope: Whenever you have questions about the most recent standards, library versions, or if you want to verify a pattern or an approach, request_web_research to gather up-to-date, authoritative information. - Library/framework versions and compatibility
- Action: Wait for the web research results before drawing conclusions or proceeding with your research. - Current best practices and patterns
- Purpose: Web research results can help you confirm patterns, best practices, official documentation references, and version-specific details to ensure your findings are accurate. - API documentation and usage
- Configuration options and defaults
- Recently updated features
Favor checking documentation over making assumptions.
""" """
WEB_RESEARCH_PROMPT_SECTION_PLANNING = """ WEB_RESEARCH_PROMPT_SECTION_PLANNING = """
Web Research: Request web research before finalizing technical plans:
- Scope: If you need to confirm the feasibility of a solution, compare approaches, or validate that a selected architecture aligns with current best practices, request_web_research. - Framework version compatibility
- Action: Hold off on finalizing the plan until you have gathered the relevant data from web search. - Architecture patterns and best practices
- Purpose: Web research can uncover recent changes in frameworks, updated references, and community-verified architectural approaches to guide your planning decisions. - Breaking changes in recent versions
- Community-verified approaches
- Migration guides and upgrade paths
""" """
WEB_RESEARCH_PROMPT_SECTION_IMPLEMENTATION = """ WEB_RESEARCH_PROMPT_SECTION_IMPLEMENTATION = """
Web Research: Request web research before writing code involving:
- Scope: If at any point during implementation youre unsure about API usage, configuration details, compatibility issues, or you suspect that the latest version of a library/framework might have changed usage patterns, request_web_research. - Import statements and dependencies
- Action: Pause development to review the research findings before proceeding with the coding steps. - API method calls and parameters
- Purpose: Web research helps ensure that you are implementing the most current, recommended code patterns, leveraging official documentation, and avoiding deprecated methods. - Configuration objects and options
- Environment setup requirements
- Package version specifications
""" """
WEB_RESEARCH_PROMPT_SECTION_CHAT = """ WEB_RESEARCH_PROMPT_SECTION_CHAT = """
Web Research: Request web research when discussing:
- Scope: In the middle of a conversation, if you need fresh contextsuch as new best practices, updated documentation, or clarifications about recently released versionsrequest_web_research. - Package versions and compatibility
- Action: Incorporate the web research findings into your response before finalizing any advice or explanation. - API usage and patterns
- Purpose: Web research can provide current, authoritative details to enhance the clarity and correctness of your chat-based guidance. - Configuration details
- Best practices
- Recent changes
Prioritize checking current documentation for technical advice.
""" """
# Research stage prompt - guides initial codebase analysis # Research stage prompt - guides initial codebase analysis
@ -223,6 +233,7 @@ You have often been criticized for:
{expert_section} {expert_section}
{human_section} {human_section}
{web_research_section}
NEVER ANNOUNCE WHAT YOU ARE DOING, JUST DO IT! NEVER ANNOUNCE WHAT YOU ARE DOING, JUST DO IT!
""" """
@ -468,6 +479,7 @@ Guidelines:
{expert_section} {expert_section}
{human_section} {human_section}
{web_research_section}
You have often been criticized for: You have often been criticized for:
- Overcomplicating things. - Overcomplicating things.
@ -525,13 +537,16 @@ Testing:
- If the tests have not already been run, run them using run_shell_command to get a baseline of functionality (e.g. were any tests failing before we started working? Do they all pass?) - If the tests have not already been run, run them using run_shell_command to get a baseline of functionality (e.g. were any tests failing before we started working? Do they all pass?)
- If you add or change any unit tests, run them using run_shell_command and ensure they pass (check docs or analyze directory structure/test files to infer how to run them.) - If you add or change any unit tests, run them using run_shell_command and ensure they pass (check docs or analyze directory structure/test files to infer how to run them.)
- Start with running very specific tests, then move to more general/complete test suites. - Start with running very specific tests, then move to more general/complete test suites.
{expert_section}
{human_section}
- Only test UI components if there is already a UI testing system in place. - Only test UI components if there is already a UI testing system in place.
- Only test things that can be tested by an automated process. - Only test things that can be tested by an automated process.
Once the task is complete, ensure all updated files are emitted. Once the task is complete, ensure all updated files are emitted.
{expert_section}
{human_section}
{web_research_section}
You have often been criticized for: You have often been criticized for:
- Overcomplicating things. - Overcomplicating things.
- Doing changes outside of the specific scoped instructions. - Doing changes outside of the specific scoped instructions.