Edit: Team Agent System Prompts
deci committed
May 12, 2025 at 22:23 UTC
cc120beb3d062512bdd1c1a8be9ae62a4e97303e
1 file changed
+102
-65
python/tools/team_agent.py
+102
-65
@@ -635,66 +635,104 @@ SESSION WORKFLOW:
635
- Use the input tool for interactive programs
636
637
ERROR HANDLING STRATEGY:
638
-- If you encounter the same error twice when trying the same approach, switch to an alternative, more reliable method (such as reading the entire file, editing in memory, and writing back as a single multi-line string, or using EOF CAT-style edits). Document the fallback method used in your response.
638
+- If you encounter the same error twice when trying the same approach, switch to an alternative, more reliable method (such as using Python file I/O as described below). Document the fallback method used in your response.
639
- For library/package issues, try a different library or implement a minimal solution from scratch
640
- When installation fails despite multiple attempts, use a fallback implementation as specified in your task
641
- Document environment issues and your workaround strategy in your final response
642
643
PROJECT CREATION PATTERN:
644
1. Create directories and verify structure
645
-2. Create all required files with explicit paths
645
+2. Create all required files with explicit paths (using reliable methods below)
646
3. Verify all files exist before execution
647
4. Run code in separate sessions from creation
648
5. ALWAYS install packages AND run scripts with terminal runtime to maintain environment consistency
649
650
+FILE EDITING STRATEGIES (Use Terminal First):
651
+
652
+Reading Files:
653
+- Use `cat /path/to/file` in the terminal runtime.
654
+
655
+Writing/Overwriting Files (Preferred Method for Reliability):
656
+- Use `cat > /path/to/file << 'EOF' ... EOF` in the terminal runtime. This is the MOST RELIABLE way to write or overwrite entire files, especially multi-line content or code.
657
+```json
658
+{{
659
+ "thoughts": ["Overwriting file with new content using heredoc"],
660
+ "tool_name": "code_execution_tool",
661
+ "tool_args": {{
662
+ "runtime": "terminal",
663
+ "session": 0, // Use session 0 for file ops
664
+ "code": "cat > /path/to/your/file.py << 'EOF'\\n# Your full new file content here\\nprint(\\'Hello Overwritten World!\\')\\nEOF"
665
+ }}
666
+}}
667
+```
668
+
669
+Creating Empty Files or Simple Overwrites (Less Reliable for complex content):
670
+- `echo "single line" > /path/to/file` or `touch /path/to/file`
671
+
672
+Python Fallback (If Terminal Methods Fail Repeatedly):
673
+- ONLY if terminal methods fail, use the `python` runtime with file I/O.
674
+```json
675
+{{
676
+ "thoughts": ["Terminal file write failed, falling back to Python file I/O"],
677
+ "tool_name": "code_execution_tool",
678
+ "tool_args": {{
679
+ "runtime": "python", // Python runtime specifically for this fallback
680
+ "session": 0, // Still use session 0
681
+ "code": "with open('/path/to/your/file.py', 'w') as f:\\n f.write(\\'\\'\\'# Your full new file content here\\nprint(\\\\\\'Hello Python Fallback!\\\\\\')\\n\\'\\'\\')"
682
+ }}
683
+}}
684
+```
685
+
686
+*NEVER* use naive string/line replacements or partial edits, especially for code or structured files. Always read the necessary context, modify the content appropriately, and write back the *entire* corrected content using the `cat > ... << EOF` method or the Python fallback.
687
+
688
AVAILABLE TOOLS:
689
- knowledge_tool: For research and information gathering
652
-- code_execution_tool: For computation, data processing, file operations (prioritize terminal runtime for both package installation AND script execution to maintain environment consistency)
690
+- code_execution_tool: For computation, data processing, file operations (use 'terminal' runtime for commands and file ops; use 'python' runtime ONLY for executing Python logic or the file I/O fallback)
691
- input: For providing input to interactive programs
692
- response_tool: REQUIRED for your final output
693
656
-TOOL USAGE:
694
+TOOL USAGE EXAMPLES (Focus on Runtimes):
695
658
-For file creation ONLY:
696
+Checking File Content (Terminal):
697
```json
698
{{
661
- "thoughts": ["Creating project files"],
699
+ "thoughts": ["Checking the content of main.py"],
700
"tool_name": "code_execution_tool",
701
"tool_args": {{
664
- "runtime": "python", // Python runtime ONLY for file creation
665
- "session": 0, // ALWAYS use session 0 for file operations
666
- "code": "import os\n\n# Create directories\nos.makedirs('project/src', exist_ok=True)\n\n# Create files\nwith open('project/src/main.py', 'w') as f:\n f.write(\"print('Hello world')\")"
702
+ "runtime": "terminal", // Use terminal to run cat
703
+ "session": 0,
704
+ "code": "cat project/src/main.py"
705
}}
706
}}
707
```
708
671
-For executing ANY Python code (imports, tests, etc):
709
+Executing Python Code (Terminal):
710
```json
711
{{
712
"thoughts": ["Testing code/imports"],
675
- "tool_name": "code_execution_tool",
713
+ "tool_name": "code_execution_tool",
714
"tool_args": {{
677
- "runtime": "terminal", // ALWAYS use terminal for running ANY Python code
715
+ "runtime": "terminal", // ALWAYS use terminal for running ANY Python code/scripts
716
"session": 1,
717
"code": "python -c 'import pandas; print(pandas.__version__)'"
718
}}
719
}}
720
```
721
684
-For installing packages:
722
+Installing Packages (Terminal):
723
```json
724
{{
725
"thoughts": ["Installing required packages"],
726
"tool_name": "code_execution_tool",
727
"tool_args": {{
690
- "runtime": "terminal",
728
+ "runtime": "terminal", // Terminal for pip
729
"session": 1,
730
"code": "pip install pandas matplotlib"
731
}}
732
}}
733
```
734
697
-For running and testing code:
735
+Running Scripts (Terminal):
736
```json
737
{{
738
"thoughts": ["Reset session before running"],
@@ -710,27 +748,27 @@ For running and testing code:
748
"thoughts": ["Running the created file"],
749
"tool_name": "code_execution_tool",
750
"tool_args": {{
713
- "runtime": "terminal",
751
+ "runtime": "terminal", // Terminal to execute the python script
752
"session": 1,
753
"code": "python project/src/main.py"
754
}}
755
}}
756
```
757
720
-For checking environment:
758
+Checking Environment (Terminal):
759
```json
760
{{
761
"thoughts": ["Verifying Python environment"],
762
"tool_name": "code_execution_tool",
763
"tool_args": {{
726
- "runtime": "terminal",
764
+ "runtime": "terminal", // Terminal for shell commands
765
"session": 1,
766
"code": "which python && python --version && pip list | grep pandas"
767
}}
768
}}
769
```
770
733
-For research:
771
+Research (Knowledge Tool):
772
```json
773
{{
774
"thoughts": ["Need information about X"],
@@ -741,7 +779,7 @@ For research:
779
}}
780
```
781
744
-For your final response (REQUIRED):
782
+Final Response (Response Tool - REQUIRED):
783
```json
784
{{
785
"thoughts": ["Task complete, delivering results"],
@@ -752,23 +790,17 @@ For your final response (REQUIRED):
790
}}
791
```
792
755
-IMPORTANT: When executing terminal commands, monitor the output carefully for errors, especially ModuleNotFoundError or ImportError. If library imports fail after installation, verify that your terminal commands and Python code are using the same environment.
793
+IMPORTANT: When executing terminal commands, monitor the output carefully for errors, especially `command not found`, `ModuleNotFoundError` or `ImportError`. If library imports fail after installation, verify that your terminal commands and Python code are using the same environment (`which python`).
794
795
EXECUTION STRATEGY:
796
1. UNDERSTAND the task requirements
797
2. PLAN your approach before writing any code
760
-3. CREATE complete project with all necessary files
761
-4. TEST your implementation thoroughly
762
-5. PIVOT quickly if you encounter repeated errors with the same approach
798
+3. CREATE/EDIT files using reliable terminal methods (`cat`, `cat > EOF`)
799
+4. TEST your implementation thoroughly (using `terminal` runtime for execution)
800
+5. PIVOT quickly if you encounter repeated errors (try Python file I/O fallback for edits)
801
6. DELIVER using the response tool
802
765
-Remember: The response_tool is REQUIRED for your final output.
766
-
767
-CODE EDITING BEST PRACTICE:
768
-- Strongly discourage naive string or line replacements for code edits, especially in Python or structured files, as this can easily break indentation, structure, or introduce subtle bugs.
769
-- Read the file to identify the exact issues. After reviewing the content, implement the necessary fixes to ensure proper syntax throughout the file.
770
-- The most reliable and robust approach is to always read the entire file into memory, make your edits there, and write back the full, updated content as a single multi-line string (or using a 'cat' style overwrite). This ensures file integrity and preserves formatting.
771
-- For all file edits, especially in Python or markdown, always prefer this full overwrite method over partial or regex-based replacements.
803
+Remember: The response_tool is REQUIRED for your final output. Avoid complex escaping; use heredocs or the Python fallback for multi-line strings.
804
"""
805
806
# Execute task using call_subordinate pattern
@@ -1350,7 +1382,7 @@ CODE EDITING BEST PRACTICE:
1382
return json.dumps(formatted_response, indent=2)
1383
1384
async def _integrate_results(self, team_id, step=None, review_summary=None, **kwargs):
1353
- """Integrate results from all team members into a final product, now as a two-step process: review, then edit/update.\\n\\nBEST PRACTICE: For all markdown or code section edits, always read the entire file into memory, construct the full updated content, and overwrite the file in one write operation (single multi-line string). After writing, read the file back to confirm the update. Do NOT use regex, partial, or line-by-line replacements for in-place section updates—these are unreliable and discouraged."""
1385
+ """Integrate results from all team members into a final product, now as a two-step process: review, then edit/update.\\n\\nBEST PRACTICE: For all markdown or code section edits, always read the necessary context, construct the full updated content, and overwrite the file in one write operation using the terminal `cat > /path/to/file << 'EOF' ... EOF` method. After writing, read the file back (`cat /path/to/file`) to confirm the update. Do NOT use regex, partial, or line-by-line replacements—these are unreliable."""
1386
# Enhanced progress tracking
1387
progress_prefix = f"Team {team_id} Integration"
1388
self.log.update(progress=f"{progress_prefix}: Starting integration process... Step: {step if step else 'default (review -> edit)'}")
@@ -1634,10 +1666,10 @@ CODE EDITING BEST PRACTICE:
1666
doc_check_prompt = (
1667
f"START OF TEAM PLANNING PHASE.\\n"
1668
f"Step 1: Initial Document Check (Perform ONCE)\\n"
1637
- f"This is the very first step. Check if the file {doc_path} exists.\\n"
1638
- f"- If it exists: Read the entire file and provide a structured summary of its sections and key content.\\n"
1639
- f"- If it does NOT exist: State that clearly, create it from the template at {template_path}, and then summarize the new file.\\n"
1640
- f"CRITICAL: After summarizing or creating the file THIS ONE TIME, you MUST immediately proceed to Step 2 (Project File Review). Do NOT repeat Step 1. Do NOT re-initiate team creation. Your output for Step 1 is just the summary. Now, continue to Step 2."
1669
+ f"This is the very first step. Check if the file {doc_path} exists using `ls {doc_path}`.\\n"
1670
+ f"- If it exists: Read the entire file using `cat {doc_path}` and provide a structured summary of its sections and key content.\\n"
1671
+ f"- If it does NOT exist: State that clearly. Create it by copying the template at {template_path} using the reliable `cat > {doc_path} << \\'EOF\\' ... EOF` method, reading the template content first with `cat {template_path}`. Then, read the *newly created* file back using `cat {doc_path}` and summarize it.\\n"
1672
+ f"CRITICAL: Use the specified terminal commands (`ls`, `cat`, `cat > EOF`). After summarizing or creating the file THIS ONE TIME, you MUST immediately proceed to Step 2 (Project File Review). Do NOT repeat Step 1. Your output for Step 1 is just the summary. Now, continue to Step 2."
1673
)
1674
# The agent should summarize and then continue, not loop.
1675
team_leader.hist_add_user_message(UserMessage(message=doc_check_prompt, attachments=[]))
@@ -1725,23 +1757,28 @@ CODE EDITING BEST PRACTICE:
1757
self.log.update(progress=f"Planning Step 7/7: Updating planning document at {doc_path}...") # Add log here
1758
# Construct the final planning summary string first
1759
planning_summary_content = (
1728
- f"{doc_check_summary}\n\n" # Use the summary from step 1
1729
- f"## Project File Review\n{file_review}\n\n"
1730
- f"## Project Goal and Challenges\n{goal_summary}\n\n"
1731
- f"## Team Roles and Skills\n{roles_suggestion}\n\n"
1732
- f"## Role-Specific Task Assignment Guidance\n{role_task_guidance}\n\n"
1733
- f"## High-Level Task Breakdown\n{task_breakdown}\n\n"
1734
- f"## Clarifications or Questions\n{clarifications}\n"
1760
+ f"{doc_check_summary}\\n\\n" # Use the summary from step 1 # Escaped newline
1761
+ f"## Project File Review\\n{file_review}\\n\\n" # Escaped newline
1762
+ f"## Project Goal and Challenges\\n{goal_summary}\\n\\n" # Escaped newline
1763
+ f"## Team Roles and Skills\\n{roles_suggestion}\\n\\n" # Escaped newline
1764
+ f"## Role-Specific Task Assignment Guidance\\n{role_task_guidance}\\n\\n" # Escaped newline
1765
+ f"## High-Level Task Breakdown\\n{task_breakdown}\\n\\n" # Escaped newline
1766
+ f"## Clarifications or Questions\\n{clarifications}\\n" # Escaped newline
1767
)
1736
-
1768
+
1769
# Use the reliable full-overwrite method to update the document's overview section
1770
+ # Escape backticks and dollar signs within the heredoc content if they were potentially present
1771
+ escaped_planning_summary_content = planning_summary_content.replace('`', '\\`').replace('$', '\\$')
1772
+
1773
doc_update_prompt = (
1774
f"Step 7: Update Planning Document ({doc_path})\\n"
1740
- f"Task: Read the entire document at '{doc_path}'. Find the '## Project Overview' section. Replace the content *under* this header with the new planning summary provided below. If the section doesn't exist, add it. Construct the full, updated markdown content in memory. Overwrite the file at '{doc_path}' in one single write operation using the full updated content. After writing, read the file back to confirm the '## Project Overview' section contains the new summary.\\n"
1741
- f"CRITICAL: Use the full overwrite method (read all -> modify in memory -> write all). Do NOT use partial replacements.\\n"
1742
- f"\n--- New Project Overview Content ---\n{planning_summary_content}\n--- End New Content ---"
1775
+ f"Task: Read the entire document at '{doc_path}' using `cat {doc_path}`. Find the '## Project Overview' section. Replace the content *under* this header with the new planning summary provided below. If the section doesn't exist, add it at an appropriate place (e.g., after the guide). Construct the full, updated markdown content *in memory* first.\\n"
1776
+ f"Then, overwrite the file at '{doc_path}' in ONE single write operation using the terminal heredoc method: `cat > {doc_path} << \\'EOF\\'\\n[Your FULL reconstructed file content]\\nEOF`.\\n"
1777
+ f"After writing, read the file back using `cat {doc_path}` to confirm the '## Project Overview' section contains the new summary.\\n"
1778
+ f"CRITICAL: Use the specified `cat` and `cat > EOF` commands. Do NOT use partial replacements or other runtimes.\\n"
1779
+ f"\\n--- New Project Overview Content (to be inserted) ---\\n{escaped_planning_summary_content}\\n--- End New Content ---" # Use the escaped content
1780
)
1744
-
1781
+
1782
team_leader.hist_add_user_message(UserMessage(message=doc_update_prompt, attachments=[]))
1783
doc_update_confirmation = await team_leader.monologue() # This should contain confirmation from the agent
1784
planning_context["doc_update_confirmation"] = doc_update_confirmation
@@ -1753,15 +1790,15 @@ CODE EDITING BEST PRACTICE:
1790
# Compose the complete planning summary for return
1791
# This includes the initial doc check summary and the confirmation from the update step
1792
final_planning_summary = (
1756
- f"{doc_check_summary}\n\n" # Include initial doc check summary
1757
- f"--- Planning Summary ---\n"
1758
- f"Project File Review:\n{file_review}\n\n"
1759
- f"Project Goal and Challenges:\n{goal_summary}\n\n"
1760
- f"Team Roles and Skills:\n{roles_suggestion}\n\n"
1761
- f"Role-Specific Task Assignment Guidance:\n{role_task_guidance}\n\n"
1762
- f"High-Level Task Breakdown:\n{task_breakdown}\n\n"
1763
- f"Clarifications or Questions:\n{clarifications}\n\n"
1764
- f"--- Document Update Confirmation ---\n{doc_update_confirmation}\n" # Include update confirmation
1793
+ f"{doc_check_summary}\\n\\n" # Include initial doc check summary
1794
+ f"--- Planning Summary ---\\n"
1795
+ f"Project File Review:\\n{file_review}\\n\\n"
1796
+ f"Project Goal and Challenges:\\n{goal_summary}\\n\\n"
1797
+ f"Team Roles and Skills:\\n{roles_suggestion}\\n\\n"
1798
+ f"Role-Specific Task Assignment Guidance:\\n{role_task_guidance}\\n\\n"
1799
+ f"High-Level Task Breakdown:\\n{task_breakdown}\\n\\n"
1800
+ f"Clarifications or Questions:\\n{clarifications}\\n\\n"
1801
+ f"--- Document Update Confirmation ---\\n{doc_update_confirmation}\\n" # Include update confirmation
1802
)
1803
1804
# Return planning summary along with confirmed doc_path and status
@@ -1775,14 +1812,14 @@ CODE EDITING BEST PRACTICE:
1812
"""Handles the 'review' step of the integration process."""
1813
self.log.update(progress=f"{progress_prefix} - STEP 1/2: Starting document review...")
1814
review_doc_prompt = (
1778
- f"Integration Step 1: Review Planning/Results Document\\\\n" # Escaped newline
1779
- f"Read the current planning/results document at {doc_path}. Summarize its contents, especially the Project Overview and any previous Integration Review sections.\\\\n" # Escaped newline
1780
- f"Then review the current project directory and files. Validate that all deliverables are present and organized. Summarize results, check for gaps, and provide recommendations.\\\\n" # Escaped newline
1781
- f"Your response should include:\\\\n" # Escaped newline
1782
- f"- Directory/file review (list and describe key files and structure)\\\\n" # Escaped newline
1783
- f"- Checklist of deliverables (what was expected, what is present, what is missing)\\\\n" # Escaped newline
1784
- f"- Summary of results (from all completed tasks)\\\\n" # Escaped newline
1785
- f"- Recommendations for improvement or next steps\\\\n" # Escaped newline
1815
+ f"Integration Step 1: Review Planning/Results Document\\n" # Escaped newline
1816
+ f"Read the current planning/results document at {doc_path} using `cat {doc_path}`. Summarize its contents, especially the Project Overview and any previous Integration Review sections.\\n" # Escaped newline
1817
+ f"Then review the current project directory and files using `ls -R` or similar terminal commands. Validate that all expected deliverables are present and organized. Summarize results, check for gaps, and provide recommendations.\\n" # Escaped newline
1818
+ f"Your response should include:\\n" # Escaped newline
1819
+ f"- Directory/file review (list and describe key files and structure using terminal commands)\\n" # Escaped newline
1820
+ f"- Checklist of deliverables (what was expected, what is present, what is missing)\\n" # Escaped newline
1821
+ f"- Summary of results (from all completed tasks)\\n" # Escaped newline
1822
+ f"- Recommendations for improvement or next steps\\n" # Escaped newline
1823
f"Always state which directories and files you are reviewing in your output."
1824
)
1825
team_leader.hist_add_user_message(UserMessage(message=review_doc_prompt, attachments=[]))