Skip to content

perf(copilot): reduce tool schema token cost by 34% - #12398

Merged
majdyz merged 36 commits into
devfrom
feat/copilot-token-optimization
Mar 23, 2026
Merged

perf(copilot): reduce tool schema token cost by 34%#12398
majdyz merged 36 commits into
devfrom
feat/copilot-token-optimization

Conversation

@majdyz

@majdyz majdyz commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Reduce CoPilot per-turn token overhead by systematically trimming tool descriptions, parameter schemas, and system prompt content. All 35 MCP tool schemas are passed on every SDK call — this PR reduces their size.

Strategy

  1. Tool descriptions: Trimmed verbose multi-sentence explanations to concise single-sentence summaries while preserving meaning
  2. Parameter schemas: Shortened parameter descriptions to essential info, removed some default values (handled in code)
  3. System prompt: Condensed _SHARED_TOOL_NOTES and storage supplement template in prompting.py
  4. Cross-tool references: Removed duplicate workflow hints (e.g. "call find_block before run_block" appeared in BOTH tools — kept only in the dependent tool). Critical cross-tool references retained (e.g. continue_run_block in run_block, fix_agent_graph in validate_agent, get_doc_page in search_docs, web_fetch preference in browser_navigate)

Token Impact

Metric Before After Reduction
System Prompt ~865 tokens ~497 tokens 43%
Tool Schemas ~9,744 tokens ~6,470 tokens 34%
Grand Total ~10,609 tokens ~6,967 tokens 34%

Saves ~3,642 tokens per conversation turn.

Key Decisions

  • Mostly description changes: Tool logic, parameters, and types unchanged. However, some schema-level default fields were removed (e.g. save in customize_agent) — these are machine-readable metadata, not just prose, and may affect LLM behavior.
  • Quality preserved: All descriptions still convey what the tool does and essential usage patterns
  • Cross-references trimmed carefully: Kept prerequisite hints in the dependent tool (run_block mentions find_block) but removed the reverse (find_block no longer mentions run_block). Critical cross-tool guidance retained where removal would degrade model behavior.
  • run_time description fixed: Added missing supported values (today, last 30 days, ISO datetime) per review feedback

Future Optimization

The SDK passes all 35 tools on every call. The MCP protocol's list_tools() handler supports dynamic tool registration — a follow-up PR could implement lazy tool loading (register core tools + a discovery meta-tool) to further reduce per-turn token cost.

Changes

  • Trimmed descriptions across 25 tool files
  • Condensed _SHARED_TOOL_NOTES and _build_storage_supplement in prompting.py
  • Fixed run_time schema description in agent_output.py

Checklist

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • All 273 copilot tests pass locally
    • All 35 tools load and produce valid schemas
    • Before/after token dumps compared
    • Formatting passes (poetry run format)
    • CI green

@majdyz
majdyz requested a review from a team as a code owner March 13, 2026 08:12
@majdyz
majdyz requested review from Swiftyos and kcze and removed request for a team March 13, 2026 08:12
@github-project-automation github-project-automation Bot moved this to 🆕 Needs initial review in AutoGPT development kanban Mar 13, 2026
@github-actions github-actions Bot added platform/backend AutoGPT Platform - Back end conflicts Automatically applied to PRs with merge conflicts labels Mar 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Streamlines and shortens help/description text across copilot prompting and ~30 copilot tool modules; restructures storage/supplement wording in prompting.py. No public function signatures, control flow, or runtime behavior were changed.

Changes

Cohort / File(s) Summary
System prompting & storage
autogpt_platform/backend/backend/copilot/prompting.py
Rewrote _SHARED_TOOL_NOTES and storage supplement builders; unified headings to "Shell & filesystem" and "Storage", consolidated cloud/persistent workspace wording, updated move/read/write guidance to reference write_workspace_file/read_workspace_file, and appended shared notes.
Workspace & file tools
autogpt_platform/backend/backend/copilot/tools/workspace_files.py
Replaced verbose list/read/write/delete descriptions with concise guidance and shortened parameter/response docs; semantics unchanged.
Browser & web tools
autogpt_platform/backend/backend/copilot/tools/agent_browser.py, autogpt_platform/backend/backend/copilot/tools/web_fetch.py
Condensed tool descriptions and parameter texts for navigation/actions/screenshot and web fetch; removed some JSON Schema default fields; no signature changes.
Agent lifecycle & validation
autogpt_platform/backend/backend/copilot/tools/create_agent.py, customize_agent.py, edit_agent.py, fix_agent.py, validate_agent.py, get_agent_building_guide.py
Shortened tool descriptions and parameter docs (agent_json, library_agent_ids, save, etc.) to concise single-line forms; validation/behavior unchanged.
Agent discovery & execution
autogpt_platform/backend/backend/copilot/tools/find_agent.py, find_library_agent.py, run_agent.py
Simplified discovery/run descriptions and parameter wording (queries, identifiers, scheduling fields); preserved existing interfaces.
Block & workflow tools
autogpt_platform/backend/backend/copilot/tools/find_block.py, run_block.py, continue_run_block.py
Condensed guidance for finding/executing blocks and continuing runs; emphasized schema-discovery workflow in descriptions; no functional changes.
Context, output & requests
autogpt_platform/backend/backend/copilot/tools/add_understanding.py, agent_output.py, feature_requests.py
Shortened descriptions and standardized parameter docs for context storage, agent output retrieval, and feature-request tools; signatures unchanged.
Folder management
autogpt_platform/backend/backend/copilot/tools/manage_folders.py
Unified and shortened descriptions/parameter texts for create/list/move/delete folder operations; required fields and behavior unchanged.
System execution & MCP
autogpt_platform/backend/backend/copilot/tools/bash_exec.py, autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
Brevity edits to bash execution and MCP discovery/execution phrasing; parameter descriptions shortened.
Docs & guides
autogpt_platform/backend/backend/copilot/tools/search_docs.py, get_doc_page.py, get_mcp_guide.py
Replaced multi-line help strings with concise one-line summaries and shorter parameter labels.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

Review effort 4/5, documentation

Suggested reviewers

  • Swiftyos
  • kcze
  • ntindle

Poem

🐰 Hopped through docs with snip and cheer,
Trimmed each note so intent is clear.
Shorter hops, same work to do —
Quiet leaves, big carrots too. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.90% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary change: reducing token cost of tool schemas by 34% through description trimming.
Description check ✅ Passed The PR description is directly related to the changeset, clearly explaining the objective to reduce token overhead by trimming tool descriptions and parameter schemas.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/copilot-token-optimization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@majdyz
majdyz force-pushed the feat/copilot-token-optimization branch from fdf46ec to 9a61e2a Compare March 13, 2026 08:16
@github-actions github-actions Bot removed the conflicts Automatically applied to PRs with merge conflicts label Mar 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@github-actions

github-actions Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Overlap Detection

This check compares your PR against all other open PRs targeting the same branch to detect potential merge conflicts early.

🔴 Merge Conflicts Detected

The following PRs have been tested and will have merge conflicts if merged after this PR. Consider coordinating with the authors.

  • feat(platform): add nightly copilot automation flow #12407 (Swiftyos · updated 4d ago)

    • .claude/skills/pr-address/SKILL.md (1 conflict, ~10 lines)
    • autogpt_platform/backend/backend/api/features/admin/model.py (2 conflicts, ~125 lines)
    • autogpt_platform/backend/backend/api/features/admin/user_admin_routes.py (deleted here, modified there)
    • autogpt_platform/backend/backend/api/features/admin/user_admin_routes_test.py (deleted here, modified there)
    • autogpt_platform/backend/backend/api/features/chat/routes_test.py (2 conflicts, ~75 lines)
    • autogpt_platform/backend/backend/copilot/prompting.py (3 conflicts, ~34 lines)
    • autogpt_platform/backend/backend/copilot/sdk/service.py (7 conflicts, ~563 lines)
    • autogpt_platform/backend/backend/copilot/sdk/transcript_test.py (1 conflict, ~180 lines)
    • autogpt_platform/backend/backend/copilot/service.py (1 conflict, ~5 lines)
    • autogpt_platform/backend/backend/copilot/tools/__init__.py (1 conflict, ~5 lines)
    • autogpt_platform/backend/backend/copilot/tools/find_agent.py (2 conflicts, ~13 lines)
    • autogpt_platform/backend/backend/copilot/tools/find_block.py (2 conflicts, ~22 lines)
    • autogpt_platform/backend/backend/copilot/tools/workspace_files.py (1 conflict, ~5 lines)
    • autogpt_platform/backend/backend/data/db_manager.py (1 conflict, ~6 lines)
    • autogpt_platform/backend/backend/data/invited_user.py (deleted here, modified there)
    • autogpt_platform/backend/backend/notifications/email.py (1 conflict, ~60 lines)
    • autogpt_platform/backend/backend/notifications/test_notifications.py (1 conflict, ~4 lines)
    • autogpt_platform/backend/backend/util/settings.py (1 conflict, ~23 lines)
    • autogpt_platform/backend/poetry.lock (1 conflict, ~5 lines)
    • autogpt_platform/backend/schema.prisma (2 conflicts, ~47 lines)
    • autogpt_platform/frontend/src/app/(platform)/admin/layout.tsx (1 conflict, ~15 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts (1 conflict, ~5 lines)
    • autogpt_platform/frontend/src/app/(platform)/library/components/LibrarySubSection/LibrarySubSection.tsx (2 conflicts, ~20 lines)
    • autogpt_platform/frontend/src/app/api/openapi.json (3 conflicts, ~394 lines)
  • feat(backend/api): External API v2 #12206 (Pwuts · updated 4d ago)

    • 📁 autogpt_platform/backend/backend/copilot/tools/
      • __init__.py (1 conflict, ~93 lines)

🟢 Low Risk — File Overlap Only

These PRs touch the same files but different sections (click to expand)

Summary: 2 conflict(s), 0 medium risk, 5 low risk (out of 7 PRs with file overlap)


Auto-generated on push. Ignores: openapi.json, lock files.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
autogpt_platform/backend/backend/copilot/tools/agent_output.py (1)

140-140: Make run_time examples explicitly non-exhaustive.

Line 140 currently reads like a closed set, but the parser also accepts additional values/formats (e.g., today, ISO datetime). Consider adding “e.g.” to avoid over-constraining tool usage.

Suggested wording tweak
- "description": "'latest', 'yesterday', 'last week', or 'YYYY-MM-DD'.",
+ "description": "e.g. 'latest', 'yesterday', 'last week', or 'YYYY-MM-DD'.",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@autogpt_platform/backend/backend/copilot/tools/agent_output.py` at line 140,
Update the description string for the run_time parameter (the "description"
field in the dict in agent_output.py) to make examples explicitly non-exhaustive
by inserting phrasing like "e.g." or "such as" and optionally adding examples
like "today" and "ISO datetime" so it no longer reads as a closed set; locate
the dict entry that currently contains "'latest', 'yesterday', 'last week', or
'YYYY-MM-DD'." and change it to a non-exhaustive example phrasing (e.g. "'e.g.,
latest, yesterday, last week, 'YYYY-MM-DD', 'today', or ISO datetime') to
clarify the parser accepts additional formats.
autogpt_platform/backend/backend/copilot/tools/run_block.py (1)

56-69: Make block_name optional (or consume it) to avoid required-but-unused schema overhead.

block_name is required in the schema, but _execute does not use it (Line 95 onward). This adds avoidable token cost and can force unnecessary validation failures.

♻️ Suggested schema adjustment
             "properties": {
                 "block_id": {
                     "type": "string",
                     "description": "Block ID from find_block results.",
                 },
                 "block_name": {
                     "type": "string",
                     "description": "Block name for UI display.",
                 },
                 "input_data": {
                     "type": "object",
                     "description": "Input values. Use {} first to see schema.",
                 },
             },
-            "required": ["block_id", "block_name", "input_data"],
+            "required": ["block_id", "input_data"],
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@autogpt_platform/backend/backend/copilot/tools/run_block.py` around lines 56
- 69, The schema in run_block.py marks "block_name" as required but the executor
(_execute method) never uses it, causing unnecessary validation/token overhead;
update the schema definition (the object containing
"block_id","block_name","input_data") to remove "block_name" from the "required"
array or modify _execute to consume/log/use the block_name parameter so it is
actually used (adjust references in the schema object and the _execute function
accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@autogpt_platform/backend/backend/copilot/prompting.py`:
- Around line 63-66: The prompt text overstates a shared filesystem; update the
wording around the "Shell & filesystem" section so it scopes "All file tools
share the same filesystem" to SDK file tools and bash_exec (mentioning bash_exec
and working_dir) and add an explicit distinction that workspace persistence
tools (the persistent workspace vs ephemeral working dir/local-storage model)
may not share state with ephemeral working_dir and require explicit file
transfer or persistence actions; reference SDK file tools, bash_exec,
working_dir, and "workspace persistence" in the sentence so the model knows to
treat them differently.

In `@autogpt_platform/backend/scripts/measure_copilot_tokens.py`:
- Around line 58-77: Replace the hardcoded system_prompt literal with the same
shared production prompt-construction logic used by the SDK flow (i.e., call the
shared prompt builder that constructs the base/system prompt instead of
embedding the literal), then append get_sdk_supplement(...) to that produced
base prompt and pass the combined string (full_system) to estimate_tokens;
update the code that sets system_prompt, full_system, and sys_tokens so
full_system is built from the production prompt builder + sdk_supplement and
sys_tokens = estimate_tokens(full_system).
- Around line 7-10: The usage example in the top-level docstring of
measure_copilot_tokens.py shows running the script with "python
scripts/measure_copilot_tokens.py"; update that example to use the repository's
required Poetry wrapper by changing the command to "poetry run python
scripts/measure_copilot_tokens.py [--output before.txt]" so the usage in the
module (docstring in measure_copilot_tokens.py) follows the convention required
for autogpt_platform/backend Python commands.

---

Nitpick comments:
In `@autogpt_platform/backend/backend/copilot/tools/agent_output.py`:
- Line 140: Update the description string for the run_time parameter (the
"description" field in the dict in agent_output.py) to make examples explicitly
non-exhaustive by inserting phrasing like "e.g." or "such as" and optionally
adding examples like "today" and "ISO datetime" so it no longer reads as a
closed set; locate the dict entry that currently contains "'latest',
'yesterday', 'last week', or 'YYYY-MM-DD'." and change it to a non-exhaustive
example phrasing (e.g. "'e.g., latest, yesterday, last week, 'YYYY-MM-DD',
'today', or ISO datetime') to clarify the parser accepts additional formats.

In `@autogpt_platform/backend/backend/copilot/tools/run_block.py`:
- Around line 56-69: The schema in run_block.py marks "block_name" as required
but the executor (_execute method) never uses it, causing unnecessary
validation/token overhead; update the schema definition (the object containing
"block_id","block_name","input_data") to remove "block_name" from the "required"
array or modify _execute to consume/log/use the block_name parameter so it is
actually used (adjust references in the schema object and the _execute function
accordingly).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 93c26a7d-bb55-4845-bae2-5c831f0fd047

📥 Commits

Reviewing files that changed from the base of the PR and between 0cd9c0d and fdf46ec.

📒 Files selected for processing (26)
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Seer Code Review
🧰 Additional context used
📓 Path-based instructions (4)
autogpt_platform/backend/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

autogpt_platform/backend/**/*.py: Use Python 3.11 (required; managed by Poetry via pyproject.toml) for backend development
Always run 'poetry run format' (Black + isort) before linting in backend development
Always run 'poetry run lint' (ruff) after formatting in backend development

Files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
autogpt_platform/backend/**/*.{py,txt}

📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)

Use poetry run prefix for all Python commands, including testing, linting, formatting, and migrations

Files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
autogpt_platform/backend/backend/**/*.py

📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)

Use Prisma ORM for database operations in PostgreSQL with pgvector for embeddings

Files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
autogpt_platform/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Format Python code with poetry run format

Files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
🧠 Learnings (19)
📓 Common learnings
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:10030-10037
Timestamp: 2026-03-01T07:59:02.311Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — For MCP manual token storage, backend model autogpt_platform/backend/backend/api/features/mcp/routes.py defines MCPStoreTokenRequest.token as Pydantic SecretStr with a min length constraint, which generates OpenAPI schema metadata (format: "password", writeOnly: true, minLength: 1) in autogpt_platform/frontend/src/app/api/openapi.json. Prefer SecretStr (with length constraints) for sensitive request fields so generated TS clients and docs treat them as secrets.
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — OpenAPI/codegen
Learning: Ensuring a field is required in generated TS types needs two sides: (1) no default value on the Pydantic field, and (2) the OpenAPI model's "required" array must list it. For MCPToolInfo, making input_schema required in OpenAPI and removing Field(default_factory=dict) in the backend prevents optional typing drift.
📚 Learning: 2026-03-08T23:28:21.675Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12334
File: docs/integrations/block-integrations/github/repo.md:11-40
Timestamp: 2026-03-08T23:28:21.675Z
Learning: In Significant-Gravitas/AutoGPT, new GitHub block documentation stubs in `docs/integrations/block-integrations/github/` are auto-generated by a docs script with placeholder text (`_Add technical explanation here._` / `_Add practical use case examples here._`) inside `<!-- MANUAL: how_it_works

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/prompting.py
📚 Learning: 2026-02-26T17:02:22.448Z
Learnt from: Pwuts
Repo: Significant-Gravitas/AutoGPT PR: 12211
File: .pre-commit-config.yaml:160-179
Timestamp: 2026-02-26T17:02:22.448Z
Learning: Keep the pre-commit hook pattern broad for autogpt_platform/backend to ensure OpenAPI schema changes are captured. Do not narrow to backend/api/ alone, since the generated schema depends on Pydantic models across multiple directories (backend/data/, backend/blocks/, backend/copilot/, backend/integrations/, backend/util/). Narrowing could miss schema changes and cause frontend type desynchronization.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
📚 Learning: 2026-03-04T08:04:35.881Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12273
File: autogpt_platform/backend/backend/copilot/tools/workspace_files.py:216-220
Timestamp: 2026-03-04T08:04:35.881Z
Learning: In the AutoGPT Copilot backend, ensure that SVG images are not treated as vision image types by excluding 'image/svg+xml' from INLINEABLE_MIME_TYPES and MULTIMODAL_TYPES in tool_adapter.py; the Claude API supports PNG, JPEG, GIF, and WebP for vision. SVGs (XML text) should be handled via the text path instead, not the vision path.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
📚 Learning: 2026-03-04T12:19:39.243Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12279
File: autogpt_platform/backend/backend/copilot/tools/base.py:184-188
Timestamp: 2026-03-04T12:19:39.243Z
Learning: In autogpt_platform/backend/backend/copilot/tools/, ensure that anonymous users always pass user_id=None to tool execution methods. The anon_ prefix (e.g., anon_123) is used only for PostHog/analytics distinct_id and must not be used as an actual user_id. Use a simple truthiness check on user_id (e.g., if user_id: ... else: ... or a dedicated is_authenticated flag) to distinguish anonymous from authenticated users, and review all tool execution call sites within this directory to prevent accidentally forwarding an anon_ user_id to tools.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
📚 Learning: 2026-03-05T15:42:08.207Z
Learnt from: ntindle
Repo: Significant-Gravitas/AutoGPT PR: 12297
File: .claude/skills/backend-check/SKILL.md:14-16
Timestamp: 2026-03-05T15:42:08.207Z
Learning: In Python files under autogpt_platform/backend (recursively), rely on poetry run format to perform formatting (Black + isort) and linting (ruff). Do not run poetry run lint as a separate step after poetry run format, since format already includes linting checks.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
📚 Learning: 2026-02-27T10:45:55.700Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx:23-24
Timestamp: 2026-02-27T10:45:55.700Z
Learning: As of PR `#12213`, MCP tool response types (MCPToolsDiscoveredResponse, MCPToolOutputResponse) are defined in openapi.json and frontend code in autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx uses the generated types from `@/app/api/__generated__/`. Other tools like RunBlock still use inline TypeScript interfaces (e.g., BlockDetailsResponse) for SSE stream payloads that are not included in openapi.json schemas. The pattern is tool-specific: use generated types when available in openapi.json, use inline types only when the payload schema is truly SSE-stream-only and not exposed via OpenAPI.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
📚 Learning: 2026-02-27T15:59:00.370Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — Backend/frontend OpenAPI codegen
Learning: For MCP schema models, required OpenAPI fields must have no defaults in Pydantic. Specifically, MCPToolInfo.input_schema must be required (no Field(default_factory=dict)) so openapi.json emits it in "required", ensuring generated TS types treat input_schema as non-optional.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
📚 Learning: 2026-02-27T15:59:00.370Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — OpenAPI/codegen
Learning: Ensuring a field is required in generated TS types needs two sides: (1) no default value on the Pydantic field, and (2) the OpenAPI model's "required" array must list it. For MCPToolInfo, making input_schema required in OpenAPI and removing Field(default_factory=dict) in the backend prevents optional typing drift.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
📚 Learning: 2026-03-04T23:58:18.476Z
Learnt from: Pwuts
Repo: Significant-Gravitas/AutoGPT PR: 12284
File: autogpt_platform/frontend/src/app/api/openapi.json:11897-11900
Timestamp: 2026-03-04T23:58:18.476Z
Learning: Repo: Significant-Gravitas/AutoGPT — PR `#12284`
Backend/frontend OpenAPI codegen convention: In backend/api/features/store/model.py, the StoreSubmission and StoreSubmissionAdminView models define submitted_at: datetime | None, changes_summary: str | None, and instructions: str | None with no default. This is intentional to produce “required but nullable” fields in OpenAPI (properties appear in required[] and use anyOf [type, null]). This matches Prisma’s submittedAt DateTime? and changesSummary String?. Do not flag this as a required/nullable mismatch.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
📚 Learning: 2026-03-01T07:59:02.311Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:10030-10037
Timestamp: 2026-03-01T07:59:02.311Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — For MCP manual token storage, backend model autogpt_platform/backend/backend/api/features/mcp/routes.py defines MCPStoreTokenRequest.token as Pydantic SecretStr with a min length constraint, which generates OpenAPI schema metadata (format: "password", writeOnly: true, minLength: 1) in autogpt_platform/frontend/src/app/api/openapi.json. Prefer SecretStr (with length constraints) for sensitive request fields so generated TS clients and docs treat them as secrets.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-03-04T23:57:59.510Z
Learnt from: Pwuts
Repo: Significant-Gravitas/AutoGPT PR: 12284
File: autogpt_platform/frontend/src/app/api/openapi.json:5593-5593
Timestamp: 2026-03-04T23:57:59.510Z
Learning: In Significant-Gravitas/AutoGPT backend (FastAPI), openapi.json is autogenerated: descriptions come from route docstrings and schemas from response_model/type annotations. To prevent drift when models are renamed (e.g., AdminView variants), avoid embedding specific schema class names in route docstrings; instead describe behavior, or keep names synced via backend edits—never hand-edit frontend/src/app/api/openapi.json.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
📚 Learning: 2026-03-10T08:38:30.834Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12356
File: autogpt_platform/backend/backend/copilot/tools/run_block.py:349-370
Timestamp: 2026-03-10T08:38:30.834Z
Learning: In the AutoGPT CoPilot HITL (Human-In-The-Loop) flow (`autogpt_platform/backend/backend/copilot/tools/run_block.py`), the review card presented to users sets `editable: false`, meaning reviewers cannot modify the input payload. Therefore, credentials resolved before `is_block_exec_need_review()` remain valid and do not need to be recomputed after the review step — the original `input_data` is unchanged through the review lifecycle.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
📚 Learning: 2026-01-22T11:37:20.219Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2026-01-22T11:37:20.219Z
Learning: Applies to docs/**/*.md : Keep documentation descriptions concise and action-oriented, focusing on practical, real-world scenarios

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
📚 Learning: 2026-02-04T16:49:42.490Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-04T16:49:42.490Z
Learning: Applies to autogpt_platform/backend/backend/blocks/**/*.py : Implement 'run' method with proper error handling in backend blocks

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_block.py
📚 Learning: 2026-02-04T16:50:20.508Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: autogpt_platform/backend/CLAUDE.md:0-0
Timestamp: 2026-02-04T16:50:20.508Z
Learning: Applies to autogpt_platform/backend/backend/blocks/*.py : When adding new blocks, analyze block interfaces to ensure inputs and outputs tie well together for productive graph-based editor connections

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_block.py
📚 Learning: 2026-02-04T16:50:20.508Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: autogpt_platform/backend/CLAUDE.md:0-0
Timestamp: 2026-02-04T16:50:20.508Z
Learning: Applies to autogpt_platform/backend/backend/blocks/*.py : When creating new blocks, inherit from the `Block` base class and define input/output schemas using `BlockSchema`

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_block.py
📚 Learning: 2026-03-10T08:38:29.078Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12356
File: autogpt_platform/backend/backend/copilot/tools/run_block.py:297-300
Timestamp: 2026-03-10T08:38:29.078Z
Learning: In autogpt_platform/backend/backend/copilot/tools/run_block.py, the auto-approval key for sensitive block HITL review is session-scoped: it uses graph_exec_id (copilot-session-{session_id}) combined with node_id (copilot-node-{block_id}). If the user enables the auto-approve toggle for a CoPilot session, approving a block type in that session automatically approves all future invocations of that same block type within the same session. If the user does not toggle auto-approve (default), each individual invocation requires its own approval. This behavior should be clearly documented in code and comments, and tested to ensure the toggle reliably toggles between session-scoped auto-approval and per-invocation approval.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_block.py
📚 Learning: 2026-03-10T08:38:30.834Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12356
File: autogpt_platform/backend/backend/copilot/tools/run_block.py:349-370
Timestamp: 2026-03-10T08:38:30.834Z
Learning: In the AutoGPT CoPilot HITL flow, the review card presents with editable: false, so the input payload cannot be modified. Therefore credentials resolved before is_block_exec_need_review() remain valid and do not need to be recomputed after the review step. Ensure run_block.py uses the original input_data for credential validation and that any credential caching relies on the pre-review input. If there is any logic that would recompute credentials post-review, guard it against input_data mutations and rely on the UI to enforce immutability. This guideline is specific to autogpt_platform/backend/backend/copilot/tools/run_block.py.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_block.py
🔇 Additional comments (30)
autogpt_platform/backend/backend/copilot/tools/continue_run_block.py (2)

31-33: LGTM!

The shortened description is clear and retains all essential information: what the tool does, when to use it, and what parameter is required.


36-46: LGTM!

The parameter description is concise while clearly indicating the source of the review_id value. The schema structure remains correct with proper type and required field specification.

autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py (1)

41-41: Concise description preserves guidance and intent.

This wording stays clear while reducing token overhead and still instructs the expected tool-call order.

autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py (2)

60-61: Description still communicates the staged MCP flow clearly.

Good reduction in verbosity without losing the discover-then-execute contract.


71-71: Parameter descriptions are lean but still unambiguous.

These concise strings preserve caller expectations and fit the token-optimization objective.

Also applies to: 75-75, 79-79

autogpt_platform/backend/backend/copilot/tools/manage_folders.py (5)

90-120: LGTM — concise descriptions retain essential information.

The shortened descriptions for CreateFolderTool effectively communicate the tool's purpose and parameter semantics. The #RRGGBB format hint for color is a good inclusion for guiding proper parameter values.


169-195: LGTM — helpful LLM guidance preserved.

The description appropriately instructs when to enable include_agents, which is valuable for correct tool invocation. The default value hint (default: false) helps the LLM make informed decisions without redundant schema metadata.


341-364: LGTM — null-for-root semantics clearly documented.

The descriptions concisely convey the move operation and the null convention for root-level placement. Consistency between tool and parameter descriptions aids LLM comprehension.


411-430: LGTM — critical behavioral note preserved.

The description correctly communicates that agents are preserved (moved to root, not deleted) when a folder is deleted. This is essential information for LLM tool selection and user trust.


474-498: LGTM — consistent conventions and clear semantics.

The descriptions follow the established null-for-root pattern and clearly distinguish "library agent IDs" from other identifier types. Good consistency with other folder tools in this file.

autogpt_platform/backend/backend/copilot/tools/agent_output.py (1)

111-136: Concise metadata reduction is clean and aligned with the PR goal.

These description trims keep intent clear while reducing schema prompt overhead, and there’s no functional risk in this segment.

Also applies to: 144-145

autogpt_platform/backend/backend/copilot/tools/agent_browser.py (1)

411-428: LGTM! Descriptions are shortened appropriately while preserving essential information.

The description changes across all three browser tools (browser_navigate, browser_act, browser_screenshot) are well-executed:

  1. Default values mentioned in descriptions accurately match the code implementations (e.g., networkidle on line 455, down on line 617, True on line 777, screenshot.png on line 782).

  2. Critical behavioral distinctions are preserved (e.g., "fill clears field first; type appends" in browser_act).

  3. Workflow guidance remains actionable (e.g., "Call read_workspace_file with the returned file_id to display it").

The token reduction aligns with the PR objective without sacrificing LLM usability.

Also applies to: 547-588, 735-751

autogpt_platform/backend/backend/copilot/tools/search_docs.py (1)

41-50: Concise tool metadata update looks good.

Line 41 and Line 50 keep the guidance clear and action-oriented while reducing schema verbosity, with no behavior impact.

autogpt_platform/backend/backend/copilot/tools/add_understanding.py (1)

25-29: Description rewrite is clear and preserves intent.

The shorter wording still captures when to call the tool and how incremental merging works.

autogpt_platform/backend/backend/copilot/tools/get_doc_page.py (1)

28-38: Good concise wording for tool and path parameter.

Line 28 and Line 38 remain explicit about expected input and keep the search_docs → get_doc_page flow understandable.

autogpt_platform/backend/backend/copilot/tools/web_fetch.py (1)

62-75: Metadata simplification is accurate and consistent with behavior.

Line 75’s default note matches current execution logic, and the shortened text is still sufficiently precise.

autogpt_platform/backend/backend/copilot/tools/find_agent.py (1)

21-30: Looks good—clear, compact metadata.

The updated description and parameter text are concise without reducing usability.

autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py (1)

45-45: Concise description update is solid.

Line 45 keeps the “call before generating agent JSON” instruction explicit while reducing token cost.

autogpt_platform/backend/backend/copilot/tools/bash_exec.py (1)

44-45: Good concise rewrite with critical constraints retained.

The shortened text still clearly conveys shared filesystem behavior and timeout bounds.

Also applies to: 55-59

autogpt_platform/backend/backend/copilot/tools/find_library_agent.py (1)

22-23: Clean metadata reduction with no functional risk.

The wording is concise and still tells callers that query is optional.

Also applies to: 33-33

autogpt_platform/backend/backend/copilot/tools/run_agent.py (1)

107-111: LGTM: concise metadata update is clear and behavior-preserving.

The shortened tool/parameter descriptions stay consistent with the existing validation and execution behavior.

Also applies to: 120-149

autogpt_platform/backend/backend/copilot/tools/find_block.py (1)

55-57: LGTM: description simplification is still operationally clear.

The updated wording keeps the intended find→run flow understandable while reducing schema verbosity.

Also applies to: 66-70

autogpt_platform/backend/backend/copilot/tools/edit_agent.py (1)

25-25: LGTM: concise schema text remains aligned with current runtime defaults.

No behavior drift introduced by these description-only changes.

Also applies to: 38-52

autogpt_platform/backend/backend/copilot/tools/create_agent.py (1)

26-28: LGTM: metadata is shorter and still accurately describes usage.

The updated parameter wording remains consistent with current validation/default behavior.

Also applies to: 41-55

autogpt_platform/backend/backend/copilot/tools/customize_agent.py (1)

26-27: LGTM: concise phrasing with no behavioral side effects.

This remains aligned with the existing customize/validate/save flow.

Also applies to: 40-54

autogpt_platform/backend/backend/copilot/tools/workspace_files.py (1)

330-347: LGTM: workspace tool docs are tighter but still precise.

The condensed descriptions keep key usage constraints intact (scope, source options, pagination, and overwrite semantics).

Also applies to: 430-467, 621-658, 784-801

autogpt_platform/backend/backend/copilot/tools/feature_requests.py (1)

137-137: LGTM: concise descriptions still communicate required workflow and constraints.

No functional or schema-shape regressions introduced by these edits.

Also applies to: 233-236, 245-254

autogpt_platform/backend/scripts/measure_copilot_tokens.py (1)

98-103: Tool availability filtering matches runtime behavior.

Good call filtering with tool.is_available before measuring schema size; this keeps measurement aligned with actual tool exposure.

autogpt_platform/backend/backend/copilot/tools/fix_agent.py (1)

25-27: Description simplification looks good.

This keeps tool metadata concise without changing execution behavior.

autogpt_platform/backend/backend/copilot/tools/validate_agent.py (1)

25-27: Concise API text update is clean and consistent.

The shortened tool and parameter descriptions preserve intent and align with the token-reduction objective.

Also applies to: 40-40

Comment thread autogpt_platform/backend/backend/copilot/prompting.py
Comment thread autogpt_platform/backend/scripts/measure_copilot_tokens.py Outdated
Comment thread autogpt_platform/backend/scripts/measure_copilot_tokens.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
autogpt_platform/backend/scripts/measure_copilot_tokens.py (2)

58-77: ⚠️ Potential issue | 🟠 Major

Build full_system from the production prompt-construction path, not an inline literal.

Line 58 hardcodes the base system prompt, so token reports can drift from real runtime prompt assembly and invalidate before/after comparisons as prompt text evolves.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@autogpt_platform/backend/scripts/measure_copilot_tokens.py` around lines 58 -
77, The system prompt is hardcoded into system_prompt causing token measurements
to diverge from production; instead, reconstruct the system prompt using the
same production prompt-construction path used at runtime (call the shared prompt
builder rather than the inline literal), e.g., replace the inline system_prompt
with the production function/utility that builds the base system prompt, then
append sdk_supplement (via get_sdk_supplement) and call estimate_tokens on the
resulting full_system so the variables system_prompt, get_sdk_supplement,
full_system, and estimate_tokens reflect real runtime assembly.

7-10: ⚠️ Potential issue | 🟡 Minor

Use Poetry in the usage example.

Line 9 still documents python scripts/measure_copilot_tokens.py; in this backend path it should use poetry run python ... to match repo command conventions.

Suggested docstring fix
 Usage:
     cd autogpt_platform/backend
-    python scripts/measure_copilot_tokens.py [--output before.txt]
+    poetry run python scripts/measure_copilot_tokens.py [--output before.txt]

As per coding guidelines autogpt_platform/backend/**/*.{py,txt}: “Use poetry run prefix for all Python commands, including testing, linting, formatting, and migrations.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@autogpt_platform/backend/scripts/measure_copilot_tokens.py` around lines 7 -
10, Update the module docstring usage example in measure_copilot_tokens.py so it
follows repo conventions by prefixing Python invocations with "poetry run";
specifically replace the line that currently reads "python
scripts/measure_copilot_tokens.py [--output before.txt]" in the top-level usage
string with "poetry run python scripts/measure_copilot_tokens.py [--output
before.txt]" to comply with the autogpt_platform/backend command style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@autogpt_platform/backend/backend/copilot/tools/agent_output.py`:
- Around line 138-141: Update the "run_time" schema description to list all
supported parser inputs so it's not misleading: include 'latest', 'today',
'yesterday', 'last week', 'last 7 days', 'last month', 'last 30 days', and allow
ISO date ('YYYY-MM-DD') and ISO datetime formats; modify the description string
for the "run_time" key in agent_output.py so it enumerates these accepted values
and clarifies ISO date/time support.

---

Duplicate comments:
In `@autogpt_platform/backend/scripts/measure_copilot_tokens.py`:
- Around line 58-77: The system prompt is hardcoded into system_prompt causing
token measurements to diverge from production; instead, reconstruct the system
prompt using the same production prompt-construction path used at runtime (call
the shared prompt builder rather than the inline literal), e.g., replace the
inline system_prompt with the production function/utility that builds the base
system prompt, then append sdk_supplement (via get_sdk_supplement) and call
estimate_tokens on the resulting full_system so the variables system_prompt,
get_sdk_supplement, full_system, and estimate_tokens reflect real runtime
assembly.
- Around line 7-10: Update the module docstring usage example in
measure_copilot_tokens.py so it follows repo conventions by prefixing Python
invocations with "poetry run"; specifically replace the line that currently
reads "python scripts/measure_copilot_tokens.py [--output before.txt]" in the
top-level usage string with "poetry run python scripts/measure_copilot_tokens.py
[--output before.txt]" to comply with the autogpt_platform/backend command
style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1cfcc183-f377-4721-96f5-94a34f83347a

📥 Commits

Reviewing files that changed from the base of the PR and between fdf46ec and 9a61e2a.

📒 Files selected for processing (26)
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
✅ Files skipped from review due to trivial changes (2)
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
🚧 Files skipped from review as they are similar to previous changes (15)
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: types
  • GitHub Check: test (3.12)
  • GitHub Check: test (3.11)
  • GitHub Check: test (3.13)
  • GitHub Check: Check PR Status
🧰 Additional context used
📓 Path-based instructions (4)
autogpt_platform/backend/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

autogpt_platform/backend/**/*.py: Use Python 3.11 (required; managed by Poetry via pyproject.toml) for backend development
Always run 'poetry run format' (Black + isort) before linting in backend development
Always run 'poetry run lint' (ruff) after formatting in backend development

Files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
autogpt_platform/backend/**/*.{py,txt}

📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)

Use poetry run prefix for all Python commands, including testing, linting, formatting, and migrations

Files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
autogpt_platform/backend/backend/**/*.py

📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)

Use Prisma ORM for database operations in PostgreSQL with pgvector for embeddings

Files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
autogpt_platform/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Format Python code with poetry run format

Files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
🧠 Learnings (22)
📓 Common learnings
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:10030-10037
Timestamp: 2026-03-01T07:59:02.311Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — For MCP manual token storage, backend model autogpt_platform/backend/backend/api/features/mcp/routes.py defines MCPStoreTokenRequest.token as Pydantic SecretStr with a min length constraint, which generates OpenAPI schema metadata (format: "password", writeOnly: true, minLength: 1) in autogpt_platform/frontend/src/app/api/openapi.json. Prefer SecretStr (with length constraints) for sensitive request fields so generated TS clients and docs treat them as secrets.
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — OpenAPI/codegen
Learning: Ensuring a field is required in generated TS types needs two sides: (1) no default value on the Pydantic field, and (2) the OpenAPI model's "required" array must list it. For MCPToolInfo, making input_schema required in OpenAPI and removing Field(default_factory=dict) in the backend prevents optional typing drift.
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx:23-24
Timestamp: 2026-02-27T10:45:55.700Z
Learning: As of PR `#12213`, MCP tool response types (MCPToolsDiscoveredResponse, MCPToolOutputResponse) are defined in openapi.json and frontend code in autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx uses the generated types from `@/app/api/__generated__/`. Other tools like RunBlock still use inline TypeScript interfaces (e.g., BlockDetailsResponse) for SSE stream payloads that are not included in openapi.json schemas. The pattern is tool-specific: use generated types when available in openapi.json, use inline types only when the payload schema is truly SSE-stream-only and not exposed via OpenAPI.
📚 Learning: 2026-03-04T23:57:59.510Z
Learnt from: Pwuts
Repo: Significant-Gravitas/AutoGPT PR: 12284
File: autogpt_platform/frontend/src/app/api/openapi.json:5593-5593
Timestamp: 2026-03-04T23:57:59.510Z
Learning: In Significant-Gravitas/AutoGPT backend (FastAPI), openapi.json is autogenerated: descriptions come from route docstrings and schemas from response_model/type annotations. To prevent drift when models are renamed (e.g., AdminView variants), avoid embedding specific schema class names in route docstrings; instead describe behavior, or keep names synced via backend edits—never hand-edit frontend/src/app/api/openapi.json.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
📚 Learning: 2026-02-27T10:45:55.700Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx:23-24
Timestamp: 2026-02-27T10:45:55.700Z
Learning: As of PR `#12213`, MCP tool response types (MCPToolsDiscoveredResponse, MCPToolOutputResponse) are defined in openapi.json and frontend code in autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx uses the generated types from `@/app/api/__generated__/`. Other tools like RunBlock still use inline TypeScript interfaces (e.g., BlockDetailsResponse) for SSE stream payloads that are not included in openapi.json schemas. The pattern is tool-specific: use generated types when available in openapi.json, use inline types only when the payload schema is truly SSE-stream-only and not exposed via OpenAPI.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
📚 Learning: 2026-02-26T17:02:22.448Z
Learnt from: Pwuts
Repo: Significant-Gravitas/AutoGPT PR: 12211
File: .pre-commit-config.yaml:160-179
Timestamp: 2026-02-26T17:02:22.448Z
Learning: Keep the pre-commit hook pattern broad for autogpt_platform/backend to ensure OpenAPI schema changes are captured. Do not narrow to backend/api/ alone, since the generated schema depends on Pydantic models across multiple directories (backend/data/, backend/blocks/, backend/copilot/, backend/integrations/, backend/util/). Narrowing could miss schema changes and cause frontend type desynchronization.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-03-04T08:04:35.881Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12273
File: autogpt_platform/backend/backend/copilot/tools/workspace_files.py:216-220
Timestamp: 2026-03-04T08:04:35.881Z
Learning: In the AutoGPT Copilot backend, ensure that SVG images are not treated as vision image types by excluding 'image/svg+xml' from INLINEABLE_MIME_TYPES and MULTIMODAL_TYPES in tool_adapter.py; the Claude API supports PNG, JPEG, GIF, and WebP for vision. SVGs (XML text) should be handled via the text path instead, not the vision path.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
📚 Learning: 2026-03-04T12:19:39.243Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12279
File: autogpt_platform/backend/backend/copilot/tools/base.py:184-188
Timestamp: 2026-03-04T12:19:39.243Z
Learning: In autogpt_platform/backend/backend/copilot/tools/, ensure that anonymous users always pass user_id=None to tool execution methods. The anon_ prefix (e.g., anon_123) is used only for PostHog/analytics distinct_id and must not be used as an actual user_id. Use a simple truthiness check on user_id (e.g., if user_id: ... else: ... or a dedicated is_authenticated flag) to distinguish anonymous from authenticated users, and review all tool execution call sites within this directory to prevent accidentally forwarding an anon_ user_id to tools.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
📚 Learning: 2026-03-05T15:42:08.207Z
Learnt from: ntindle
Repo: Significant-Gravitas/AutoGPT PR: 12297
File: .claude/skills/backend-check/SKILL.md:14-16
Timestamp: 2026-03-05T15:42:08.207Z
Learning: In Python files under autogpt_platform/backend (recursively), rely on poetry run format to perform formatting (Black + isort) and linting (ruff). Do not run poetry run lint as a separate step after poetry run format, since format already includes linting checks.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-03-10T08:38:30.834Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12356
File: autogpt_platform/backend/backend/copilot/tools/run_block.py:349-370
Timestamp: 2026-03-10T08:38:30.834Z
Learning: In the AutoGPT CoPilot HITL (Human-In-The-Loop) flow (`autogpt_platform/backend/backend/copilot/tools/run_block.py`), the review card presented to users sets `editable: false`, meaning reviewers cannot modify the input payload. Therefore, credentials resolved before `is_block_exec_need_review()` remain valid and do not need to be recomputed after the review step — the original `input_data` is unchanged through the review lifecycle.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
📚 Learning: 2026-02-27T15:59:00.370Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — Backend/frontend OpenAPI codegen
Learning: For MCP schema models, required OpenAPI fields must have no defaults in Pydantic. Specifically, MCPToolInfo.input_schema must be required (no Field(default_factory=dict)) so openapi.json emits it in "required", ensuring generated TS types treat input_schema as non-optional.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
📚 Learning: 2026-02-27T15:59:00.370Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — OpenAPI/codegen
Learning: Ensuring a field is required in generated TS types needs two sides: (1) no default value on the Pydantic field, and (2) the OpenAPI model's "required" array must list it. For MCPToolInfo, making input_schema required in OpenAPI and removing Field(default_factory=dict) in the backend prevents optional typing drift.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
📚 Learning: 2026-03-01T07:59:02.311Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:10030-10037
Timestamp: 2026-03-01T07:59:02.311Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — For MCP manual token storage, backend model autogpt_platform/backend/backend/api/features/mcp/routes.py defines MCPStoreTokenRequest.token as Pydantic SecretStr with a min length constraint, which generates OpenAPI schema metadata (format: "password", writeOnly: true, minLength: 1) in autogpt_platform/frontend/src/app/api/openapi.json. Prefer SecretStr (with length constraints) for sensitive request fields so generated TS clients and docs treat them as secrets.

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:50:20.508Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: autogpt_platform/backend/CLAUDE.md:0-0
Timestamp: 2026-02-04T16:50:20.508Z
Learning: Applies to autogpt_platform/backend/**/*.{py,txt} : Use `poetry run` prefix for all Python commands, including testing, linting, formatting, and migrations

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:50:51.495Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-04T16:50:51.495Z
Learning: Applies to autogpt_platform/**/*.py : Format Python code with `poetry run format`

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:49:42.490Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-04T16:49:42.490Z
Learning: Run 'poetry run test' before committing backend changes to ensure all tests pass

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:49:42.490Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-04T16:49:42.490Z
Learning: Applies to autogpt_platform/backend/**/*.py : Always run 'poetry run format' (Black + isort) before linting in backend development

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:49:42.490Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-04T16:49:42.490Z
Learning: Always run 'poetry install' before backend development

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:49:42.490Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-04T16:49:42.490Z
Learning: Applies to autogpt_platform/backend/**/*.py : Use Python 3.11 (required; managed by Poetry via pyproject.toml) for backend development

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:50:20.508Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: autogpt_platform/backend/CLAUDE.md:0-0
Timestamp: 2026-02-04T16:50:20.508Z
Learning: Applies to autogpt_platform/backend/**/*_test.py : Always review snapshot changes with `git diff` before committing when updating snapshots with `poetry run pytest --snapshot-update`

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:50:51.495Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-04T16:50:51.495Z
Learning: Applies to autogpt_platform/backend/**/*test*.py : Run `poetry run test` for backend testing (runs pytest with docker based postgres + prisma)

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-02-04T16:49:42.490Z
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-04T16:49:42.490Z
Learning: Applies to autogpt_platform/backend/schema.prisma : Run database migrations with 'poetry run prisma migrate dev' and 'poetry run prisma generate' after schema changes in backend

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-03-10T08:39:13.707Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12356
File: autogpt_platform/backend/backend/copilot/constants.py:9-12
Timestamp: 2026-03-10T08:39:13.707Z
Learning: In Significant-Gravitas/AutoGPT PR `#12356`, the `COPILOT_SYNTHETIC_ID_PREFIX = "copilot-"` check in `create_auto_approval_record` (human_review.py) is intentional and safe. The `graph_exec_id` passed to this function comes from server-side `PendingHumanReview` DB records (not from user input); the API only accepts `node_exec_id` from users. Synthetic `copilot-*` IDs are only ever created server-side in `run_block.py`. The prefix skip avoids a DB lookup for a `AgentGraphExecution` record that legitimately does not exist for CoPilot sessions, while `user_id` scoping is enforced at the auth layer and on the resulting auto-approval record.

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
📚 Learning: 2026-03-09T10:50:43.907Z
Learnt from: Bentlybro
Repo: Significant-Gravitas/AutoGPT PR: 0
File: :0-0
Timestamp: 2026-03-09T10:50:43.907Z
Learning: Repo: Significant-Gravitas/AutoGPT — File: autogpt_platform/backend/backend/blocks/llm.py
For xAI Grok models accessed via OpenRouter, the API returns `null` for `max_completion_tokens`. The convention in this codebase is to use the model's context window size as the `max_output_tokens` value in ModelMetadata. For example, Grok 3 uses 131072 (128k) and Grok 4 uses 262144 (256k). Do not flag these as incorrect max output token values.

Applied to files:

  • autogpt_platform/backend/scripts/measure_copilot_tokens.py
🔇 Additional comments (15)
autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py (2)

60-61: Description update is concise and behavior-accurate.

The new wording keeps the discovery → execution contract explicit while reducing token footprint.


71-79: Parameter descriptions are clear and aligned with runtime validation.

These edits preserve intent and improve schema compactness without changing semantics.

autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py (1)

44-45: LGTM!

The shortened description effectively conveys purpose and usage guidance ("Call before generating agent JSON") while reducing token overhead. Detailed documentation is preserved in the class docstring for developer reference.

autogpt_platform/backend/backend/copilot/tools/add_understanding.py (1)

23-29: LGTM! Concise description maintains clarity.

The shortened description accurately captures the tool's purpose (storing business context), invocation trigger (when user shares business info), and merge semantics (incremental updates with partial fields). This aligns well with the actual implementation behavior documented in the _execute docstring.

autogpt_platform/backend/backend/copilot/tools/web_fetch.py (1)

61-75: LGTM!

The shortened descriptions are accurate and maintain essential information:

  • Tool description correctly captures the primary behavior (fetching pages and extracting text from HTML by default).
  • The extract_text description appropriately documents the default value, which aligns with the code at line 92 where kwargs.get("extract_text", True) handles the default.

Good token savings while preserving clarity.

autogpt_platform/backend/backend/copilot/tools/continue_run_block.py (2)

31-33: LGTM!

The shortened description is clear and actionable—it explains both the purpose (resume after human review approval) and the required action (pass the review_id).


40-43: LGTM!

The parameter description is succinct and provides the essential information—where to obtain the review_id value.

autogpt_platform/backend/backend/copilot/tools/edit_agent.py (3)

23-25: LGTM!

Shortened description remains clear and captures the essential functionality (validate, auto-fix, save).


36-42: LGTM!

Concise parameter descriptions retain necessary context while reducing token overhead.


44-52: Descriptions and code-level default look correct.

The save description helpfully includes "(default: true)" to communicate expected behavior since the schema default attribute was removed. Line 83 preserves the code-level default via kwargs.get("save", True), so functionality is unchanged.

One edge case to be aware of: if the LLM explicitly sends save: null, kwargs.get would return None, which the downstream if not save: check (in pipeline.py:149) treats as falsy—resulting in preview mode instead of save mode. However, this is unlikely given the clear description guidance, and aligns with the PR's stated design that "defaults are handled in code."

autogpt_platform/backend/backend/copilot/tools/workspace_files.py (4)

329-351: LGTM!

The shortened descriptions remain clear and accurately reflect the tool's behavior. The "Current session only by default" note correctly documents the include_all_sessions parameter's default value.


428-467: LGTM!

The condensed description effectively communicates the tool's dual response modes (inline vs metadata+URL), the save_to_path functionality, and pagination support. Parameter descriptions retain the essential information needed for correct usage.


619-661: LGTM!

The description clearly communicates the three mutually exclusive content sources and the dynamic max file size constraint. The shortened parameter descriptions maintain clarity—especially the mutual exclusivity note on the content parameter.


783-801: LGTM!

The description is appropriately minimal for a straightforward delete operation. The "file_id or path" guidance matches the runtime validation logic.

autogpt_platform/backend/backend/copilot/tools/agent_output.py (1)

111-137: Good metadata compression without behavior changes

The shortened tool/parameter descriptions in these lines stay clear and consistent with current behavior, while supporting the token-cost reduction goal.

Also applies to: 142-145

Comment thread autogpt_platform/backend/backend/copilot/tools/agent_output.py
@majdyz
majdyz force-pushed the feat/copilot-token-optimization branch from 9a61e2a to 5142e36 Compare March 13, 2026 08:27
Trim verbose tool descriptions and parameter schemas across all 35
CoPilot tools. Remove redundant cross-tool workflow references.
Condense system prompt shared notes and storage supplement.
No functional changes — only description text trimmed.

Before: ~10,609 tokens (865 system + 9,744 tools)
After:  ~6,967 tokens (497 system + 6,470 tools)
Saving: ~3,642 tokens per conversation turn (34% reduction)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
autogpt_platform/backend/backend/copilot/tools/workspace_files.py (1)

619-661: Consider caching Config value to avoid repeated instantiation.

The f-string interpolation {Config().max_file_size_mb} creates a new Config instance on every property access. While description properties are typically accessed infrequently, this could be optimized by referencing a module-level constant or caching the value.

This is a minor nit given the low access frequency.

♻️ Optional: cache the config value
+_MAX_FILE_SIZE_MB = Config().max_file_size_mb
+
 class WriteWorkspaceFileTool(BaseTool):
     """Tool for writing files to workspace."""
 
     `@property`
     def description(self) -> str:
         return (
             "Write a file to persistent workspace (survives across sessions). "
             "Provide exactly one of: content (text), content_base64 (binary), "
-            f"or source_path (copy from working dir). Max {Config().max_file_size_mb}MB."
+            f"or source_path (copy from working dir). Max {_MAX_FILE_SIZE_MB}MB."
         )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@autogpt_platform/backend/backend/copilot/tools/workspace_files.py` around
lines 619 - 661, The description() method currently calls
Config().max_file_size_mb each time (via f-string {Config().max_file_size_mb}),
which instantiates Config repeatedly; replace that with a cached value (e.g.,
compute MAX_FILE_SIZE_MB = Config().max_file_size_mb at module import or a
class-level cached attribute) and reference that constant inside description()
so the Config instance is only created once and the string uses the cached
MAX_FILE_SIZE_MB instead of Config().max_file_size_mb.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@autogpt_platform/backend/backend/copilot/tools/workspace_files.py`:
- Around line 619-661: The description() method currently calls
Config().max_file_size_mb each time (via f-string {Config().max_file_size_mb}),
which instantiates Config repeatedly; replace that with a cached value (e.g.,
compute MAX_FILE_SIZE_MB = Config().max_file_size_mb at module import or a
class-level cached attribute) and reference that constant inside description()
so the Config instance is only created once and the string uses the cached
MAX_FILE_SIZE_MB instead of Config().max_file_size_mb.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 97e5570e-ad57-447b-a313-76c5b7481a11

📥 Commits

Reviewing files that changed from the base of the PR and between 9a61e2a and 3c75482.

📒 Files selected for processing (25)
  • autogpt_platform/backend/backend/copilot/prompting.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
✅ Files skipped from review due to trivial changes (2)
  • autogpt_platform/backend/backend/copilot/tools/fix_agent.py
  • autogpt_platform/backend/backend/copilot/prompting.py
🚧 Files skipped from review as they are similar to previous changes (15)
  • autogpt_platform/backend/backend/copilot/tools/run_block.py
  • autogpt_platform/backend/backend/copilot/tools/continue_run_block.py
  • autogpt_platform/backend/backend/copilot/tools/customize_agent.py
  • autogpt_platform/backend/backend/copilot/tools/find_agent.py
  • autogpt_platform/backend/backend/copilot/tools/add_understanding.py
  • autogpt_platform/backend/backend/copilot/tools/feature_requests.py
  • autogpt_platform/backend/backend/copilot/tools/validate_agent.py
  • autogpt_platform/backend/backend/copilot/tools/find_library_agent.py
  • autogpt_platform/backend/backend/copilot/tools/edit_agent.py
  • autogpt_platform/backend/backend/copilot/tools/search_docs.py
  • autogpt_platform/backend/backend/copilot/tools/manage_folders.py
  • autogpt_platform/backend/backend/copilot/tools/run_agent.py
  • autogpt_platform/backend/backend/copilot/tools/agent_output.py
  • autogpt_platform/backend/backend/copilot/tools/get_doc_page.py
  • autogpt_platform/backend/backend/copilot/tools/agent_browser.py
📜 Review details
🧰 Additional context used
📓 Path-based instructions (4)
autogpt_platform/backend/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

autogpt_platform/backend/**/*.py: Use Python 3.11 (required; managed by Poetry via pyproject.toml) for backend development
Always run 'poetry run format' (Black + isort) before linting in backend development
Always run 'poetry run lint' (ruff) after formatting in backend development

Files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
autogpt_platform/backend/**/*.{py,txt}

📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)

Use poetry run prefix for all Python commands, including testing, linting, formatting, and migrations

Files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
autogpt_platform/backend/backend/**/*.py

📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)

Use Prisma ORM for database operations in PostgreSQL with pgvector for embeddings

Files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
autogpt_platform/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Format Python code with poetry run format

Files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
🧠 Learnings (9)
📓 Common learnings
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:10030-10037
Timestamp: 2026-03-01T07:59:02.311Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — For MCP manual token storage, backend model autogpt_platform/backend/backend/api/features/mcp/routes.py defines MCPStoreTokenRequest.token as Pydantic SecretStr with a min length constraint, which generates OpenAPI schema metadata (format: "password", writeOnly: true, minLength: 1) in autogpt_platform/frontend/src/app/api/openapi.json. Prefer SecretStr (with length constraints) for sensitive request fields so generated TS clients and docs treat them as secrets.
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — OpenAPI/codegen
Learning: Ensuring a field is required in generated TS types needs two sides: (1) no default value on the Pydantic field, and (2) the OpenAPI model's "required" array must list it. For MCPToolInfo, making input_schema required in OpenAPI and removing Field(default_factory=dict) in the backend prevents optional typing drift.
Learnt from: CR
Repo: Significant-Gravitas/AutoGPT PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-04T16:50:51.495Z
Learning: Ensure PR descriptions are complete
📚 Learning: 2026-03-04T23:57:59.510Z
Learnt from: Pwuts
Repo: Significant-Gravitas/AutoGPT PR: 12284
File: autogpt_platform/frontend/src/app/api/openapi.json:5593-5593
Timestamp: 2026-03-04T23:57:59.510Z
Learning: In Significant-Gravitas/AutoGPT backend (FastAPI), openapi.json is autogenerated: descriptions come from route docstrings and schemas from response_model/type annotations. To prevent drift when models are renamed (e.g., AdminView variants), avoid embedding specific schema class names in route docstrings; instead describe behavior, or keep names synced via backend edits—never hand-edit frontend/src/app/api/openapi.json.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
📚 Learning: 2026-02-26T17:02:22.448Z
Learnt from: Pwuts
Repo: Significant-Gravitas/AutoGPT PR: 12211
File: .pre-commit-config.yaml:160-179
Timestamp: 2026-02-26T17:02:22.448Z
Learning: Keep the pre-commit hook pattern broad for autogpt_platform/backend to ensure OpenAPI schema changes are captured. Do not narrow to backend/api/ alone, since the generated schema depends on Pydantic models across multiple directories (backend/data/, backend/blocks/, backend/copilot/, backend/integrations/, backend/util/). Narrowing could miss schema changes and cause frontend type desynchronization.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
📚 Learning: 2026-03-04T08:04:35.881Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12273
File: autogpt_platform/backend/backend/copilot/tools/workspace_files.py:216-220
Timestamp: 2026-03-04T08:04:35.881Z
Learning: In the AutoGPT Copilot backend, ensure that SVG images are not treated as vision image types by excluding 'image/svg+xml' from INLINEABLE_MIME_TYPES and MULTIMODAL_TYPES in tool_adapter.py; the Claude API supports PNG, JPEG, GIF, and WebP for vision. SVGs (XML text) should be handled via the text path instead, not the vision path.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
📚 Learning: 2026-03-04T12:19:39.243Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12279
File: autogpt_platform/backend/backend/copilot/tools/base.py:184-188
Timestamp: 2026-03-04T12:19:39.243Z
Learning: In autogpt_platform/backend/backend/copilot/tools/, ensure that anonymous users always pass user_id=None to tool execution methods. The anon_ prefix (e.g., anon_123) is used only for PostHog/analytics distinct_id and must not be used as an actual user_id. Use a simple truthiness check on user_id (e.g., if user_id: ... else: ... or a dedicated is_authenticated flag) to distinguish anonymous from authenticated users, and review all tool execution call sites within this directory to prevent accidentally forwarding an anon_ user_id to tools.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
📚 Learning: 2026-03-05T15:42:08.207Z
Learnt from: ntindle
Repo: Significant-Gravitas/AutoGPT PR: 12297
File: .claude/skills/backend-check/SKILL.md:14-16
Timestamp: 2026-03-05T15:42:08.207Z
Learning: In Python files under autogpt_platform/backend (recursively), rely on poetry run format to perform formatting (Black + isort) and linting (ruff). Do not run poetry run lint as a separate step after poetry run format, since format already includes linting checks.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/create_agent.py
  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/web_fetch.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
  • autogpt_platform/backend/backend/copilot/tools/find_block.py
  • autogpt_platform/backend/backend/copilot/tools/workspace_files.py
  • autogpt_platform/backend/backend/copilot/tools/bash_exec.py
  • autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py
📚 Learning: 2026-02-27T10:45:55.700Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx:23-24
Timestamp: 2026-02-27T10:45:55.700Z
Learning: As of PR `#12213`, MCP tool response types (MCPToolsDiscoveredResponse, MCPToolOutputResponse) are defined in openapi.json and frontend code in autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/helpers.tsx uses the generated types from `@/app/api/__generated__/`. Other tools like RunBlock still use inline TypeScript interfaces (e.g., BlockDetailsResponse) for SSE stream payloads that are not included in openapi.json schemas. The pattern is tool-specific: use generated types when available in openapi.json, use inline types only when the payload schema is truly SSE-stream-only and not exposed via OpenAPI.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
📚 Learning: 2026-02-27T15:59:00.370Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — OpenAPI/codegen
Learning: Ensuring a field is required in generated TS types needs two sides: (1) no default value on the Pydantic field, and (2) the OpenAPI model's "required" array must list it. For MCPToolInfo, making input_schema required in OpenAPI and removing Field(default_factory=dict) in the backend prevents optional typing drift.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
📚 Learning: 2026-02-27T15:59:00.370Z
Learnt from: majdyz
Repo: Significant-Gravitas/AutoGPT PR: 12213
File: autogpt_platform/frontend/src/app/api/openapi.json:9983-9995
Timestamp: 2026-02-27T15:59:00.370Z
Learning: Repo: Significant-Gravitas/AutoGPT PR: 12213 — Backend/frontend OpenAPI codegen
Learning: For MCP schema models, required OpenAPI fields must have no defaults in Pydantic. Specifically, MCPToolInfo.input_schema must be required (no Field(default_factory=dict)) so openapi.json emits it in "required", ensuring generated TS types treat input_schema as non-optional.

Applied to files:

  • autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py
  • autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py
🔇 Additional comments (11)
autogpt_platform/backend/backend/copilot/tools/get_mcp_guide.py (1)

40-41: Description change looks good and still clear.

This concise phrasing preserves intent while supporting the token-reduction objective, with no behavioral impact.

autogpt_platform/backend/backend/copilot/tools/web_fetch.py (1)

62-75: Description/schema text reductions look correct and behavior-safe.

These concise descriptions still match runtime behavior (notably, default extract_text=True at Line 92), so this change aligns with the token-optimization goal without functional drift.

autogpt_platform/backend/backend/copilot/tools/find_block.py (1)

54-67: Metadata compression looks good and preserves intent.

The shorter tool/parameter descriptions stay clear and actionable while keeping behavior unchanged.

autogpt_platform/backend/backend/copilot/tools/get_agent_building_guide.py (1)

43-45: LGTM!

The shortened description is clear and actionable—it tells the LLM what the tool does and when to call it. This aligns well with the PR's token optimization goal while preserving essential guidance.

autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py (2)

58-62: Description update is concise and still behavior-accurate.

The new wording matches the actual two-stage execution path and supports the token-reduction goal without losing key usage guidance.


69-80: Parameter description simplification looks good.

These descriptions are shorter but still precise, and they stay aligned with the JSON schema (required: ["server_url"]) and runtime argument handling.

autogpt_platform/backend/backend/copilot/tools/create_agent.py (1)

24-55: LGTM! Descriptions are concise yet accurate.

The shortened descriptions effectively capture the essential information for each parameter:

  • Tool description accurately reflects the validate → fix → save pipeline.
  • agent_json correctly identifies the expected structure.
  • save default value matches the code (True at line 76).
  • folder_id describes the semantic default behavior.

This achieves the PR's token reduction goal while maintaining clarity for the LLM consumer.

autogpt_platform/backend/backend/copilot/tools/bash_exec.py (1)

42-63: LGTM — concise descriptions preserve essential information.

The shortened descriptions effectively communicate:

  • Tool purpose and filesystem sharing behavior
  • Timeout defaults (30s) and limits (120s)
  • Parameter semantics

This aligns well with the PR's token-reduction objective while maintaining clarity for LLM tool selection.

autogpt_platform/backend/backend/copilot/tools/workspace_files.py (3)

329-351: LGTM!

The shortened description retains the essential semantics: filtering by path_prefix, current-session-only default behavior, and the parameter defaults (limit 50/max 100, include_all_sessions false). Good token reduction without sacrificing clarity.


428-467: LGTM!

The condensed description effectively communicates the key behaviors:

  • File identification via file_id or path
  • Inline content for small text/images vs. metadata+URL for large/binary
  • save_to_path for copying to working directory
  • Pagination support via offset/length

Parameter descriptions are appropriately terse while remaining unambiguous.


783-801: LGTM!

The delete tool description is appropriately minimal. The "required": [] is correct since the code validates that at least one of file_id or path is provided at runtime (lines 821-824), implementing an "any-of" pattern that JSON Schema's required array cannot express directly.

Comment thread autogpt_platform/backend/backend/copilot/tools/workspace_files.py
Comment thread autogpt_platform/backend/backend/copilot/tools/agent_browser.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/tools/agent_browser.py
Comment thread autogpt_platform/backend/backend/copilot/prompting.py
Comment thread autogpt_platform/backend/backend/copilot/tools/run_block.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/tools/agent_browser.py
…vioral guidance

Address review comments:
- Restore minimum/maximum JSON Schema constraints on limit parameter
- Restore default fields in JSON Schema for wait_for, annotate, filename, direction
- Restore read_workspace_file instruction after browser_screenshot
- Restore @@agptfile: syntax examples in system prompt
- Restore stronger 'do NOT guess' warning for block IDs
- Restore browser actions list in browser_act description
…gressively

- Restore "CRITICAL" emphasis on storage system docs
- Restore "SDK Bash tool is NOT available" explicit warning
- Restore two-step workflow hint in find_block (call with empty input first)
- Add .xls not-supported caveat to structured data note
- Restore full validation check list in validate_agent description
- Restore full fix category list in fix_agent description
Comment thread autogpt_platform/backend/backend/copilot/tools/tool_schema_test.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/tools/tool_schema_test.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/tools/run_block.py
Comment thread autogpt_platform/backend/backend/copilot/tools/agent_output.py
Comment thread .gitignore Outdated
majdyz added 4 commits March 23, 2026 13:55
- Replace tiktoken with character-based budget (tokenizer-agnostic)
- Move module-level schema collection into fixture + function
- Remove unrelated .application.logs from .gitignore
Avoid repeated Config instantiation in workspace_files.py description
and validation, per review nitpick.
- Strengthen PII warnings in feature_requests.py (No PII → No names, emails, or company info)
- Add explicit submit step to browser auth recipe
- Restore cross-session path hint in read/write/delete workspace file descriptions
@majdyz

majdyz commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Addressed all findings from autogpt-pr-reviewer in commit 6c15e6c:

  • 🟠 .application.logs — Already removed in 9252eea (was only in .gitignore, file never existed in repo)
  • ✅ 🟡 feature_requests.py — Strengthened PII warnings: "No PII" → "No names, emails, or company info"
  • ✅ 🟡 find_agent.py — Slug lookup was already in description (or look up by slug ('username/agent-name'))
  • ✅ 🟡 agent_browser.py — Added explicit "submit" to auth recipe
  • ✅ 🟡 prompting.py — No-range @@agptfile example already preserved in the examples block (line 30)
  • ✅ 🟡 workspace_files.py — Restored cross-session path hint to read/write/delete descriptions

@github-project-automation github-project-automation Bot moved this from 🚧 Needs work to 👍🏼 Mergeable in AutoGPT development kanban Mar 23, 2026
@majdyz
majdyz added this pull request to the merge queue Mar 23, 2026
Merged via the queue into dev with commit 7176cec Mar 23, 2026
25 checks passed
@majdyz
majdyz deleted the feat/copilot-token-optimization branch March 23, 2026 08:42
@github-project-automation github-project-automation Bot moved this from 👍🏼 Mergeable to ✅ Done in AutoGPT development kanban Mar 23, 2026
Bentlybro pushed a commit that referenced this pull request Apr 4, 2026
## Summary

Reduce CoPilot per-turn token overhead by systematically trimming tool
descriptions, parameter schemas, and system prompt content. All 35 MCP
tool schemas are passed on every SDK call — this PR reduces their size.

### Strategy

1. **Tool descriptions**: Trimmed verbose multi-sentence explanations to
concise single-sentence summaries while preserving meaning
2. **Parameter schemas**: Shortened parameter descriptions to essential
info, removed some `default` values (handled in code)
3. **System prompt**: Condensed `_SHARED_TOOL_NOTES` and storage
supplement template in `prompting.py`
4. **Cross-tool references**: Removed duplicate workflow hints (e.g.
"call find_block before run_block" appeared in BOTH tools — kept only in
the dependent tool). Critical cross-tool references retained (e.g.
`continue_run_block` in `run_block`, `fix_agent_graph` in
`validate_agent`, `get_doc_page` in `search_docs`, `web_fetch`
preference in `browser_navigate`)

### Token Impact

| Metric | Before | After | Reduction |
|--------|--------|-------|-----------|
| System Prompt | ~865 tokens | ~497 tokens | 43% |
| Tool Schemas | ~9,744 tokens | ~6,470 tokens | 34% |
| **Grand Total** | **~10,609 tokens** | **~6,967 tokens** | **34%** |

Saves **~3,642 tokens per conversation turn**.

### Key Decisions

- **Mostly description changes**: Tool logic, parameters, and types
unchanged. However, some schema-level `default` fields were removed
(e.g. `save` in `customize_agent`) — these are machine-readable
metadata, not just prose, and may affect LLM behavior.
- **Quality preserved**: All descriptions still convey what the tool
does and essential usage patterns
- **Cross-references trimmed carefully**: Kept prerequisite hints in the
dependent tool (run_block mentions find_block) but removed the reverse
(find_block no longer mentions run_block). Critical cross-tool guidance
retained where removal would degrade model behavior.
- **`run_time` description fixed**: Added missing supported values
(today, last 30 days, ISO datetime) per review feedback

### Future Optimization

The SDK passes all 35 tools on every call. The MCP protocol's
`list_tools()` handler supports dynamic tool registration — a follow-up
PR could implement lazy tool loading (register core tools + a discovery
meta-tool) to further reduce per-turn token cost.

### Changes

- Trimmed descriptions across 25 tool files
- Condensed `_SHARED_TOOL_NOTES` and `_build_storage_supplement` in
`prompting.py`
- Fixed `run_time` schema description in `agent_output.py`

### Checklist

#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
  - [x] All 273 copilot tests pass locally
  - [x] All 35 tools load and produce valid schemas
  - [x] Before/after token dumps compared
  - [x] Formatting passes (`poetry run format`)
  - [x] CI green
majdyz added a commit that referenced this pull request Apr 21, 2026
…covery (#12862)

Closes #12861 · [OPEN-3096](https://linear.app/autogpt/issue/OPEN-3096)

## Why

Four related copilot UX / stability issues surfaced on dev once action
tools started rendering inline in the chat (see #12813):

### 1. Duplicate bash_exec row

`GenericTool` rendered two rows saying the same thing for every
completed tool call — a muted subtitle line ("Command exited with code
1" / "Ran: sleep 20") **and** a `ToolAccordion` with the command echoed
in its description. Previously hidden inside the "Show reasoning" /
"Show steps" collapse, now visibly duplicated.

### 2. `bash_exec` capped at 120s via advisory text

The tool schema said `"Max seconds (default 30, max 120)"`; the model
obeyed, so long-running scripts got clipped at 120s with a vague `Timed
out after 120s` even though the E2B sandbox has no such limit. Confirmed
via Langfuse traces — the model picks `120` for long scripts because
that's what the schema told it the max was. E2B path never had a
server-side clamp.

Originally added in #12103 (default 30) and tightened to "max 120"
advisory in #12398 (token-reduction pass).

### 3. 30s default was too aggressive

`pip install`, small data-processing scripts, etc. routinely cross 30s
and got killed before the model thought to retry with a bigger timeout.

### 4. Stop + edit + resend → "The assistant encountered an error"
([OPEN-3096](https://linear.app/autogpt/issue/OPEN-3096))

Two independent bugs both land on the same banner — fixing only one
leaves the other visible on the next action.

**4a. Stream lock never released on Stop** *(the error in the ticket
screenshot)*. The executor's `async for chunk in
stream_and_publish(...)` broke out on `cancel.is_set()` without calling
`aclose()` on the wrapper. `async for` does NOT auto-close iterators on
`break`, so `stream_chat_completion_sdk` stayed suspended at its current
`await` — still holding the per-session Redis lock (TTL 120s) until GC
eventually closed it. The next `POST /stream` hit `lock.try_acquire()`
at
[sdk/service.py](autogpt_platform/backend/backend/copilot/sdk/service.py)
and yielded `StreamError("Another stream is already active for this
session. Please wait or stop it.")`. The `except GeneratorExit →
lock.release()` handler written exactly for this case never fired
because nothing sent GeneratorExit.

**4b. Orphan `tool_use` after stop-mid-tool.** Even with the lock
released, the stop path persists the session ending on an assistant row
whose `tool_calls` have no matching `role="tool"` row. On the next turn,
`_session_messages_to_transcript` hands Claude CLI `--resume` a JSONL
with a `tool_use` and no paired `tool_result`, and the SDK raises a
vague error — same banner. The ticket's "Open questions" explicitly
flags this.

## What

**Frontend — `GenericTool.tsx`** split responsibilities between the two
rows so they don't duplicate:
- **Subtitle row** (always visible, muted): *what ran* — `Ran: sleep
120`. Never the exit code.
- **Accordion description**: *how it ended* — `completed` / `status code
127 · bash: missing-bin: command not found` / `Timed out after 120s` /
(fallback to command preview for legacy rows missing `exit_code` /
`timed_out`). Pulled from the first non-empty line of `stdout` /
`stderr` when available.
- **Expanded accordion**: full command + stdout + stderr code blocks
(unchanged).

**Backend — `bash_exec.py`**:
- Drop the "max 120" advisory from the schema description.
- Bump default `timeout: 30 → 120`.
- Clean up the result message — `"Command executed with status code 0"`
(no "on E2B", no parens).

**Backend — `executor/processor.py` + `stream_registry.py` (OPEN-3096
#4a)**: wrap the consumer `async for` in `try/finally: await
stream.aclose()`. Close now propagates through `stream_and_publish` into
`stream_chat_completion_sdk`, whose existing `except GeneratorExit →
lock.release()` releases the Redis lock immediately on cancel. Stream
types tightened to `AsyncGenerator[StreamBaseResponse, None]` so the
defensive `getattr(stream, "aclose", None)` goes away.

**Backend — `session_cleanup.py` (OPEN-3096 #4b)**: new
`prune_orphan_tool_calls()` helper walks the trailing session tail and
drops any trailing assistant row whose `tool_calls` have unresolved ids
(plus everything after it) and any trailing `STOPPED_BY_USER_MARKER`
system-stop row. Single backward pass — tolerates the marker being
present or absent. Called from the existing turn-start cleanup in both
`sdk/service.py` and `baseline/service.py`; takes an optional
`log_prefix` so both paths emit the same INFO log when something was
popped. In-memory only — the DB save path is append-only via
`start_sequence`.

## Test plan

- [x] `pnpm exec vitest run src/app/(platform)/copilot/tools/GenericTool
src/app/(platform)/copilot/components/ChatMessagesContainer` — 105 pass
(6 new for GenericTool subtitle/description variants + legacy-fallback
case).
- [x] `pnpm format` / `pnpm lint` / `pnpm types` — clean.
- [x] `poetry run pytest
backend/copilot/sdk/session_persistence_test.py` — 17 pass (6 + 3 new
covering the orphan-tool-call prune and its optional-log-prefix branch).
- [x] `poetry run pytest backend/copilot/stream_registry_test.py
backend/copilot/executor/processor_test.py` — 19 pass (2 for aclose
propagation on the `stream_and_publish` wrapper, 2 for `_execute_async`
aclose propagation on both exit paths, 1 for publish_chunk RedisError
warning ladder).
- [x] `poetry run ruff check` / `poetry run pyright` on touched files —
clean.
- [x] Manual: fire a `bash_exec` — one labelled row, accordion
description reads sensibly (`completed` / `status code 1 · …` / `Timed
out after 120s`).
- [x] Manual: script that needs >120s — no longer clipped.
- [x] Manual: Stop mid-tool + edit + resend — Autopilot resumes without
"Another stream is already active" and without the vague SDK error.

## Scope note

Does not touch `splitReasoningAndResponse` — re-collapsing action tools
back into "Show steps" is #12813's responsibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/backend AutoGPT Platform - Back end size/xl

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants