Skip to content

feat: add library agent fetching with two-phase search for sub-agent support - #11889

Merged
majdyz merged 48 commits into
devfrom
feat/sub-agent-support
Jan 31, 2026
Merged

feat: add library agent fetching with two-phase search for sub-agent support#11889
majdyz merged 48 commits into
devfrom
feat/sub-agent-support

Conversation

@majdyz

@majdyz majdyz commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Context

When users ask the chat to create agents, they may want to compose workflows that reuse their existing agents as sub-agents. For this to work, the Agent Generator service needs to know what agents the user has available.

Challenge: Users can have large libraries with many agents. Fetching all of them would be slow and provide too much context to the LLM.

Solution

This PR implements search-based library agent fetching with a two-phase search strategy:

  1. Phase 1 (Initial Search): When the user describes their goal, we search for relevant library agents using the goal as the search query
  2. Phase 2 (Step-Based Enrichment): After the goal is decomposed into steps, we extract keywords from those steps and search for additional relevant agents

This ensures we find agents that are relevant to both the high-level goal AND the specific steps identified.

Example Flow

User goal: "Create an agent that fetches weather and sends a summary email"

Phase 1: Search for "weather email summary" → finds "Weather Fetcher" agent
Phase 2: After decomposition identifies steps like "send email notification"
         → searches "send email notification" → finds "Gmail Sender" agent

Changes

Library Agent Fetching:

  • get_library_agents_for_generation() - Search-based fetching from user's library
  • search_marketplace_agents_for_generation() - Search public marketplace
  • get_all_relevant_agents_for_generation() - Combines both with deduplication

Two-Phase Search:

  • extract_search_terms_from_steps() - Extracts keywords from decomposed steps
  • enrich_library_agents_from_steps() - Searches for additional agents based on steps
  • Integrated into create_agent.py as "Step 1.5" after goal decomposition

Type Safety:

  • Added TypedDict definitions: LibraryAgentSummary, MarketplaceAgentSummary, DecompositionStep, DecompositionResult

Design Decisions

  • Search-based, not fetch-all: Scalable for large libraries
  • Library agents prioritized: They have full schemas; marketplace agents have basic info only
  • Deduplication by name and graph_id: Prevents duplicates across searches
  • Graceful degradation: Failures don't block agent generation
  • Limited to 3 search terms: Avoids excessive API calls during enrichment

Related PR

Test plan

  • test_library_agents.py - 19 tests covering all new functions
  • test_service.py - 4 tests for library_agents passthrough
  • Integration test: Create agent with library sub-agent composition

- Add get_library_agents_for_generation() with search_term support
- Add search_marketplace_agents_for_generation() for marketplace search
- Add get_all_relevant_agents_for_generation() combining both sources
- Update service.py to pass library_agents in all requests
- Update create_agent.py to fetch and pass relevant library agents
- Update edit_agent.py to fetch and pass relevant library agents
- Add tests for library agent fetching and passthrough
@majdyz
majdyz requested a review from a team as a code owner January 29, 2026 23:18
@majdyz
majdyz requested review from 0ubbe and ntindle and removed request for a team January 29, 2026 23:18
@github-project-automation github-project-automation Bot moved this to 🆕 Needs initial review in AutoGPT development kanban Jan 29, 2026
@github-actions github-actions Bot added platform/backend AutoGPT Platform - Back end size/xl labels Jan 29, 2026
@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@majdyz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b3fd038 and 6e737c8.

📒 Files selected for processing (1)
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py

Walkthrough

Expands agent-generator public API and core types; threads optional library_agents through decomposition/generation/patch flows and external payloads; adds UUID direct lookups, enrichment/dedup logic, and JSON validation; augments LibraryAgent with execution metrics; improves search filtering and error sanitization; adds session-scoped clarification persistence in frontend; updates tests.

Changes

Cohort / File(s) Summary
Public API / Exports
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
Expanded public exports (typed summaries, decomposition types, enrichment/search helpers, UUID utilities, lookup/generation helpers, check_external_service_health) and reordered/restored items (e.g., save_agent_to_library).
Core Implementation
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
Added TypedDicts/unions (ExecutionSummary/LibraryAgentSummary/MarketplaceAgentSummary/DecompositionStep/DecompositionResult/AgentSummary), _to_dict_list, UUID extraction, library & marketplace lookup APIs, search-term extraction, enrichment helpers, threaded library_agents through decompose/generate/patch, AgentJsonValidationError, json->graph validation, ID reassignment/versioning, user_id population for executor nodes, and adjusted save/get/generate signatures.
Service Layer
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/service.py
External decompose/generate/patch endpoints accept optional library_agents and include them in POST payloads when provided; payload shapes and error formatting adjusted.
Tool Flows (create/edit)
autogpt_platform/backend/backend/api/features/chat/tools/create_agent.py, .../edit_agent.py
Fetch relevant agents via get_all_relevant_agents_for_generation, pass library_agents into decomposition/generation/patch, call enrich_library_agents_from_steps after decomposition; retrieval/enrichment failures are non-fatal; library links updated to /library/agents/{id}.
Search / Lookup & DB
autogpt_platform/backend/backend/api/features/chat/tools/agent_search.py, autogpt_platform/backend/backend/api/features/library/db.py
Added UUID detection/direct library-agent lookup in search; list_library_agents adds include_executions flag; logging around direct lookups and adjusted search flow.
Models / OpenAPI / Snapshots
autogpt_platform/backend/backend/api/features/library/model.py, frontend/src/app/api/openapi.json, backend/snapshots/lib_agts_search
Added RecentExecution and augmented LibraryAgent with execution_count, success_rate, avg_correctness_score, recent_executions; from_db computes metrics; OpenAPI and snapshots updated.
Error Handling
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/errors.py
Unified get_user_message_for_error, added error_details param, sanitization/truncation of technical details, and centralized base_message generation.
Chat Service Flow
autogpt_platform/backend/backend/api/features/chat/service.py
After long-running tool completion or failure, triggers _generate_llm_continuation to produce a follow-up explanation; continuation failures are logged and non-fatal.
Frontend: Clarification & Minor UI
frontend/src/components/.../ClarificationQuestionsWidget/ClarificationQuestionsWidget.tsx, .../ChatMessage/ChatMessage.tsx, .../ToolResponseMessage/helpers.ts
Clarification widget adds session-scoped localStorage persistence and sessionId/isAnswered props; ChatMessage forwards sessionId; tool-response error/message selection now prefers response.message.
Tests — Core, Service & Library Agents
autogpt_platform/backend/test/.../test_core_integration.py, .../test_service.py, .../test_library_agents.py
Updated external-call mocks to include library_agents=None; added/updated tests for library/marketplace fetching, enrichment, UUID extraction/direct lookup, dedupe logic, and payload propagation of library_agents.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Tool as Create/Edit Tool
    participant Retrieval as AgentRetrieval
    participant Core as AgentGeneratorCore
    participant Service as AgentGeneratorService
    participant External as ExternalAgentAPI

    Client->>Tool: create/edit request (description, context)
    Tool->>Retrieval: get_all_relevant_agents_for_generation(user_id, search_query)
    Retrieval->>Retrieval: library DB lookup (UUID/direct or per-word search), marketplace search, dedupe
    Retrieval-->>Tool: return library_agents
    Tool->>Core: decompose_goal(description, context, library_agents)
    Core->>Service: decompose/generate/patch request (payload includes library_agents)
    Service->>External: POST payload (includes library_agents)
    External-->>Service: response (instructions/agent JSON)
    Service-->>Core: return result
    Core-->>Tool: final agent JSON/patch
    Tool->>Client: return created/updated agent
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested Labels

Review effort 4/5

Suggested Reviewers

  • Swiftyos
  • Bentlybro
  • 0ubbe

Poem

🐇 I hop through graphs and library stacks,
I sniff UUIDs on winding tracks,
I stitch up agents, dedupe with care,
I pass their steps into the generator's air,
I twitch my whiskers — built with flair.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding library agent fetching with a two-phase search strategy for sub-agent support, which is the core objective of this changeset.
Description check ✅ Passed The description comprehensively explains the context, solution, implementation details, and design decisions related to the changeset, providing clear examples and rationale.
Docstring Coverage ✅ Passed Docstring coverage is 90.24% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/sub-agent-support

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.

Comment thread autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.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: 2

🤖 Fix all issues with AI agents
In
`@autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py`:
- Around line 39-78: get_library_agents_for_generation currently calls
library_db.list_library_agents without error handling; wrap that call in a
try/except similar to search_marketplace_agents_for_generation to catch
exceptions (e.g., DatabaseError/Exception), log the error (using the
module/logger used elsewhere) with context, and return an empty list on failure
so agent generation can degrade gracefully; update
get_library_agents_for_generation to perform the try/except around
library_db.list_library_agents and ensure the function still filters
exclude_graph_id and returns the formatted agent dicts when successful.

In `@autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py`:
- Around line 135-139: The call to get_all_relevant_agents_for_generation is
excluding by exclude_graph_id using agent_id, which may be a library-agent id
and fail to filter the current agent; change the exclude_graph_id argument to
use the graph id from current_agent when present (e.g., current_agent.graph_id)
and fall back to agent_id otherwise so the current agent is reliably excluded;
update the call site where library_agents is fetched to pass that graph id
instead of agent_id.
🧹 Nitpick comments (5)
autogpt_platform/backend/test/agent_generator/test_service.py (1)

475-567: Remove redundant inline “Verify …” comments.

The assertions already document intent; the inline comments add noise without extra clarity. As per coding guidelines, "Avoid comments at all times unless the code is very complex".

autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py (1)

131-146: Drop inline comments in the new sub-agent fetch block.

The block is straightforward and the comments repeat intent. As per coding guidelines, "Avoid comments at all times unless the code is very complex".

autogpt_platform/backend/test/agent_generator/test_core_integration.py (1)

60-61: Remove inline “defaults to None” comments.

The assertions already convey this, so the comments are redundant. As per coding guidelines, "Avoid comments at all times unless the code is very complex".

Also applies to: 78-80, 114-115, 180-181

autogpt_platform/backend/test/agent_generator/test_library_agents.py (1)

20-52: Inline comments are unnecessary in these tests.

The assertions and mocks are self-explanatory; consider removing the inline notes. As per coding guidelines, "Avoid comments at all times unless the code is very complex".

Also applies to: 137-152

autogpt_platform/backend/backend/api/features/chat/tools/create_agent.py (1)

107-121: Remove inline comments in the library-agent fetch block.

The logic is clear without them. As per coding guidelines, "Avoid comments at all times unless the code is very complex".

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b2eb483 and 552d069.

📒 Files selected for processing (8)
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/service.py
  • autogpt_platform/backend/backend/api/features/chat/tools/create_agent.py
  • autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py
  • autogpt_platform/backend/test/agent_generator/test_core_integration.py
  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
  • autogpt_platform/backend/test/agent_generator/test_service.py
🧰 Additional context used
📓 Path-based instructions (2)
autogpt_platform/backend/**/*.py

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

autogpt_platform/backend/**/*.py: Always run backend setup commands in order: poetry install, poetry run prisma migrate dev, poetry run prisma generate before backend development
Always run poetry run format (Black + isort) before poetry run lint (ruff) for backend code
Use Python 3.10-3.13 with Python 3.11 required for development (managed by Poetry via pyproject.toml)

autogpt_platform/backend/**/*.py: Use FastAPI with async support for API endpoints in the backend
Use Prisma ORM for database operations with PostgreSQL
Use RabbitMQ for async task processing in the backend
Use JWT-based authentication with Supabase integration
Use poetry run format (Black + isort) to format code and poetry run lint (ruff) for linting in the backend
Use ClamAV integration for file upload security

autogpt_platform/backend/**/*.py: Format Python code with poetry run format
Run poetry run test (runs pytest with a docker based postgres + prisma) before committing backend changes

Files:

  • autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py
  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/service.py
  • autogpt_platform/backend/test/agent_generator/test_service.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
  • autogpt_platform/backend/test/agent_generator/test_core_integration.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
  • autogpt_platform/backend/backend/api/features/chat/tools/create_agent.py
autogpt_platform/**/*.{ts,tsx,js,py}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid comments at all times unless the code is very complex

Files:

  • autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py
  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/service.py
  • autogpt_platform/backend/test/agent_generator/test_service.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
  • autogpt_platform/backend/test/agent_generator/test_core_integration.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
  • autogpt_platform/backend/backend/api/features/chat/tools/create_agent.py
🧬 Code graph analysis (3)
autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py (1)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (2)
  • get_all_relevant_agents_for_generation (123-171)
  • generate_agent_patch (402-430)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (2)
autogpt_platform/backend/backend/api/features/library/db.py (1)
  • list_library_agents (36-149)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/service.py (3)
  • decompose_goal_external (119-210)
  • generate_agent_external (213-259)
  • generate_agent_patch_external (262-328)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py (1)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (5)
  • get_all_relevant_agents_for_generation (123-171)
  • get_library_agents_for_generation (39-78)
  • json_to_graph (233-272)
  • save_agent_to_library (296-343)
  • search_marketplace_agents_for_generation (81-120)
⏰ 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). (6)
  • GitHub Check: Seer Code Review
  • GitHub Check: setup
  • GitHub Check: test (3.11)
  • GitHub Check: test (3.13)
  • GitHub Check: test (3.12)
  • GitHub Check: Check PR Status
🔇 Additional comments (11)
autogpt_platform/backend/backend/api/features/chat/tools/edit_agent.py (2)

8-13: Import update looks good.

Keeping the tool on the package’s public API surface is the right direction.


155-157: library_agents propagation looks correct.

Passing the retrieved list into the patch generator aligns with the new contract.

autogpt_platform/backend/backend/api/features/chat/tools/create_agent.py (2)

8-13: Public API import added cleanly.

No issues with the new import.


125-127: Good propagation of library_agents into decomposition and generation.

This aligns the tool flow with the expanded Agent Generator contract.

Also applies to: 214-214

autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py (1)

3-14: Exports updated consistently.

The new utility functions are correctly re-exported at the package root.

Also applies to: 19-29

autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/service.py (1)

119-149: Payload enrichment for library_agents is solid.

The optional field is forwarded consistently across all external calls.

Also applies to: 213-231, 262-285

autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (5)

81-120: LGTM!

Good error handling with graceful degradation - catching exceptions and returning an empty list prevents marketplace failures from blocking agent generation. The warning log provides visibility for debugging.


123-171: LGTM!

The combination logic correctly prioritizes library agents (with full schemas) and deduplicates marketplace results by name. The condition at line 160 appropriately requires a search query for marketplace search since store_db.get_store_agents needs a search term.


174-197: LGTM!

Clean parameter addition with proper type hints and documentation. The library_agents parameter is correctly propagated to the external service.


200-230: LGTM!

The library_agents parameter is correctly added and forwarded to the external service. The existing post-processing logic for ensuring required fields remains intact.


402-429: LGTM!

Consistent parameter addition matching the pattern used in decompose_goal and generate_agent. Properly forwarded to the external service.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py Outdated
- Add try/except error handling to get_library_agents_for_generation
  for graceful degradation (consistent with marketplace search)
- Add null checks when deduplicating agents by name to prevent
  AttributeError if agent name is None
- Use actual graph ID from current_agent in edit_agent.py to properly
  exclude the agent being edited (agent_id might be a library agent ID)
ntindle
ntindle previously approved these changes Jan 30, 2026
@github-project-automation github-project-automation Bot moved this from 🆕 Needs initial review to 👍🏼 Mergeable in AutoGPT development kanban Jan 30, 2026
- Add TypedDict types for agent summaries (LibraryAgentSummary, MarketplaceAgentSummary, DecompositionResult)
- Add extract_search_terms_from_steps() to extract keywords from decomposed instructions
- Add enrich_library_agents_from_steps() for two-phase search after decomposition
- Integrate enrichment into create_agent.py flow
- Add comprehensive tests for new functionality
@majdyz majdyz changed the title feat: add search-based library agent fetching for sub-agent support feat: add library agent fetching with two-phase search for sub-agent support Jan 30, 2026
get_agent_as_json claimed to accept both graph IDs and library agent IDs
but only tried direct graph lookup. When a library agent ID was passed,
the function would return None (agent_not_found error).

Now the function:
1. First tries direct graph lookup with the provided ID
2. If not found, resolves the ID as a library agent ID to get the graph_id
3. Then fetches the graph using the resolved graph_id
- Move store_db, get_graph, get_graph_all_versions imports to top-level
- Catch specific NotFoundError instead of generic Exception
- Cleaner code organization following standard Python conventions
When users mention agents by UUID in their goal description, we now:
1. Extract UUID v4 patterns from the search_query text
2. Fetch those agents directly by graph_id
3. Include them in the library_agents list for the LLM

This ensures explicitly referenced agents are always available to the
Agent Generator, even if text search wouldn't find them.

Added:
- extract_uuids_from_text(): extracts UUID v4 patterns from text
- get_library_agent_by_graph_id(): fetches a single agent by graph_id
- Integration in get_all_relevant_agents_for_generation()

@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

🤖 Fix all issues with AI agents
In
`@autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py`:
- Around line 564-588: In get_agent_as_json, remove the three inline comments
above the get_graph call, the fallback library_db.get_library_agent call, and
the NotFoundError except block so the function follows the style guideline
(leave the code logic unchanged: calls to get_graph, the
library_db.get_library_agent fallback, and the except NotFoundError: pass should
remain, only delete the commented lines).
🧹 Nitpick comments (1)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (1)

29-76: Consider removing the new section header comments.
TypedDicts are clear, but the separator comments aren’t needed here (and similar inline comments added below could be trimmed too) unless this area is considered complex.

As per coding guidelines: autogpt_platform/**/*.{ts,tsx,js,py}: Avoid comments at all times unless the code is very complex.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9c3822f and 9a8838c.

📒 Files selected for processing (1)
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
🧰 Additional context used
📓 Path-based instructions (2)
autogpt_platform/backend/**/*.py

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

autogpt_platform/backend/**/*.py: Always run backend setup commands in order: poetry install, poetry run prisma migrate dev, poetry run prisma generate before backend development
Always run poetry run format (Black + isort) before poetry run lint (ruff) for backend code
Use Python 3.10-3.13 with Python 3.11 required for development (managed by Poetry via pyproject.toml)

autogpt_platform/backend/**/*.py: Use FastAPI with async support for API endpoints in the backend
Use Prisma ORM for database operations with PostgreSQL
Use RabbitMQ for async task processing in the backend
Use JWT-based authentication with Supabase integration
Use poetry run format (Black + isort) to format code and poetry run lint (ruff) for linting in the backend
Use ClamAV integration for file upload security

autogpt_platform/backend/**/*.py: Format Python code with poetry run format
Run poetry run test (runs pytest with a docker based postgres + prisma) before committing backend changes

Files:

  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
autogpt_platform/**/*.{ts,tsx,js,py}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid comments at all times unless the code is very complex

Files:

  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
⏰ 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). (6)
  • GitHub Check: types
  • GitHub Check: Seer Code Review
  • GitHub Check: test (3.13)
  • GitHub Check: test (3.12)
  • GitHub Check: test (3.11)
  • GitHub Check: Check PR Status
🔇 Additional comments (10)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (10)

5-17: Imports look consistent with the new functionality.


79-85: Helper normalization looks good.


107-155: Library search mapping and graceful fallback look solid.


157-194: Marketplace search mapping looks good.


197-247: Library-first merge and name dedupe look good.


250-293: Step-term extraction/dedup logic is clear.


296-383: Two-phase enrichment and dedupe look solid.


386-414: Passing normalized library agents to the external service looks good.


417-450: External call + required-field backfill look good.


630-659: Patch call with normalized library agents looks good.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@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

🤖 Fix all issues with AI agents
In
`@autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py`:
- Around line 319-362: The function extract_search_terms_from_steps may call
len() and .lower() on non-string step field values; update the loop over
step_keys in extract_search_terms_from_steps to first check isinstance(value,
str) before using len(value) or value.lower(), only append string values longer
than 3, and remove the inline comment markers per the no-comments guideline;
ensure the deduplication still uses term.lower() (after the isinstance guard)
and that step_keys, steps, and search_terms variable names remain unchanged to
locate the change easily.
🧹 Nitpick comments (3)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (2)

30-33: Remove decorative section headers.
These banners aren’t needed and conflict with the no-comments guideline (also consider removing similar inline comments added in this module).
As per coding guidelines, autogpt_platform/**/*.{ts,tsx,js,py}: Avoid comments at all times unless the code is very complex.

🧹 Suggested change
-# =============================================================================
-# Type Definitions
-# =============================================================================

115-126: Preserve UUID order while deduplicating.
A set loses the user-specified ordering; an ordered dedup keeps results deterministic. Also drop the inline comment per the no-comments guideline.
As per coding guidelines, autogpt_platform/**/*.{ts,tsx,js,py}: Avoid comments at all times unless the code is very complex.

♻️ Suggested change
 def extract_uuids_from_text(text: str) -> list[str]:
@@
-    matches = _UUID_PATTERN.findall(text)
-    # Deduplicate and normalize to lowercase
-    return list({m.lower() for m in matches})
+    matches = _UUID_PATTERN.findall(text)
+    seen: set[str] = set()
+    ordered: list[str] = []
+    for m in matches:
+        m_lower = m.lower()
+        if m_lower not in seen:
+            seen.add(m_lower)
+            ordered.append(m_lower)
+    return ordered
autogpt_platform/backend/test/agent_generator/test_library_agents.py (1)

1-6: Remove non-essential comments/docstrings in this test module.
The module docstring (and similar inline comments/docstrings in the tests) aren’t required here and conflict with the no-comments guideline.
As per coding guidelines, autogpt_platform/**/*.{ts,tsx,js,py}: Avoid comments at all times unless the code is very complex.

🧹 Suggested change
-"""
-Tests for library agent fetching functionality in agent generator.
-
-This test suite verifies the search-based library agent fetching,
-including the combination of library and marketplace agents.
-"""
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9a8838c and aa175e0.

📒 Files selected for processing (3)
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
🧰 Additional context used
📓 Path-based instructions (2)
autogpt_platform/backend/**/*.py

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

autogpt_platform/backend/**/*.py: Always run backend setup commands in order: poetry install, poetry run prisma migrate dev, poetry run prisma generate before backend development
Always run poetry run format (Black + isort) before poetry run lint (ruff) for backend code
Use Python 3.10-3.13 with Python 3.11 required for development (managed by Poetry via pyproject.toml)

autogpt_platform/backend/**/*.py: Use FastAPI with async support for API endpoints in the backend
Use Prisma ORM for database operations with PostgreSQL
Use RabbitMQ for async task processing in the backend
Use JWT-based authentication with Supabase integration
Use poetry run format (Black + isort) to format code and poetry run lint (ruff) for linting in the backend
Use ClamAV integration for file upload security

autogpt_platform/backend/**/*.py: Format Python code with poetry run format
Run poetry run test (runs pytest with a docker based postgres + prisma) before committing backend changes

Files:

  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
autogpt_platform/**/*.{ts,tsx,js,py}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid comments at all times unless the code is very complex

Files:

  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
🧬 Code graph analysis (1)
autogpt_platform/backend/test/agent_generator/test_library_agents.py (1)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (7)
  • get_library_agents_for_generation (158-205)
  • search_marketplace_agents_for_generation (208-245)
  • get_all_relevant_agents_for_generation (248-316)
  • extract_search_terms_from_steps (319-362)
  • enrich_library_agents_from_steps (365-452)
  • extract_uuids_from_text (115-126)
  • get_library_agent_by_graph_id (129-155)
⏰ 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: Check PR Status
  • GitHub Check: test (3.11)
  • GitHub Check: test (3.13)
  • GitHub Check: test (3.12)
🔇 Additional comments (41)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (9)

3-18: Imports look consistent.


35-78: Typed summary definitions look good.


80-86: Helper conversion is straightforward.


129-155: Graceful fallback is solid.


158-205: Library search mapping looks good.


208-245: Marketplace search shaping looks good.


248-316: Dedup and prioritization logic looks good.


365-452: Enrichment and dedup flow looks solid.


455-483: library_agents propagation looks consistent end-to-end.

Also applies to: 486-519, 699-728

autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py (2)

3-23: Re-exports align with the new API surface.


28-51: __all__ is updated consistently.

autogpt_platform/backend/test/agent_generator/test_library_agents.py (30)

18-56: LGTM.


58-94: LGTM.


96-118: LGTM.


124-156: LGTM.


158-171: LGTM.


177-223: LGTM.


225-278: LGTM.


280-313: LGTM.


315-348: LGTM.


353-372: LGTM.


374-382: LGTM.


384-399: LGTM.


400-415: LGTM.


417-425: LGTM.


431-480: LGTM.


482-526: LGTM.


528-573: LGTM.


575-600: LGTM.


603-637: LGTM.


643-648: LGTM.


650-660: LGTM.


662-669: LGTM.


671-675: LGTM.


677-680: LGTM.


682-687: LGTM.


693-715: LGTM.


717-728: LGTM.


730-740: LGTM.


746-783: LGTM.


785-786: LGTM.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

When users paste library URLs (e.g., /library/agents/{id}), the ID is
the LibraryAgent primary key, not the graph_id. The previous code only
looked up by graph_id, causing "agent not found" errors.

Now get_library_agent_by_id() tries both lookup strategies:
1. First by graph_id (AgentGraph primary key)
2. Then by library agent ID (LibraryAgent primary key)

This fixes the issue where users couldn't reference agents by pasting
their library URLs in chat.
Comment thread autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py Outdated
When users paste a library URL or agent UUID, the find_library_agent
tool now does direct ID lookup first (both by graph_id and library
agent ID) before falling back to text search.

This fixes the issue where searching by UUID would fail because
it was only doing text matching on agent names/descriptions.

@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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (3)

487-515: ⚠️ Potential issue | 🟡 Minor

Remove the inline comments in decompose_goal.

They’re not needed and violate the no-comments guideline.

💡 Suggested change
-    # Convert typed dicts to plain dicts for external service
     result = await decompose_goal_external(
         description, context, _to_dict_list(library_agents)
     )
-    # Cast the result to DecompositionResult (external service returns dict)
     return result  # type: ignore[return-value]

As per coding guidelines, autogpt_platform/**/*.{ts,tsx,js,py}: Avoid comments at all times unless the code is very complex.


518-551: ⚠️ Potential issue | 🟡 Minor

Remove the inline comment in generate_agent.

The code is already clear.

💡 Suggested change
-    # Convert typed dicts to plain dicts for external service
     result = await generate_agent_external(
         dict(instructions), _to_dict_list(library_agents)
     )

As per coding guidelines, autogpt_platform/**/*.{ts,tsx,js,py}: Avoid comments at all times unless the code is very complex.


731-760: ⚠️ Potential issue | 🟡 Minor

Remove the inline comment in generate_agent_patch.

It violates the no-comments guideline.

💡 Suggested change
-    # Convert typed dicts to plain dicts for external service
     return await generate_agent_patch_external(
         update_request, current_agent, _to_dict_list(library_agents)
     )

As per coding guidelines, autogpt_platform/**/*.{ts,tsx,js,py}: Avoid comments at all times unless the code is very complex.

🤖 Fix all issues with AI agents
In
`@autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py`:
- Around line 108-126: Remove the inline comments around the UUID extraction
(delete the comment line above _UUID_PATTERN and the inline comment "#
Deduplicate and normalize to lowercase") while leaving the regex _UUID_PATTERN
and the function extract_uuids_from_text (and its docstring) intact so
functionality and returned unique lowercase UUID list are unchanged.
- Around line 190-238: Remove the inline explanatory comment inside
get_library_agents_for_generation that reads "Exclude the agent being
generated/edited to prevent circular references" since the code is
self-explanatory; locate the loop over response.agents and delete that single
comment above the if check referencing exclude_graph_id and agent.graph_id,
leaving the if-check (if exclude_graph_id is not None and agent.graph_id ==
exclude_graph_id: continue) intact.
- Around line 280-348: Remove the inline/noise comments inside
get_all_relevant_agents_for_generation while keeping the function docstring and
all logic intact: delete the comment lines that explain UUID extraction and
fetching (around mentioned_uuids/get_library_agent_by_graph_id and
seen_graph_ids), the comment before calling get_library_agents_for_generation
(library_agents), and the comments before marketplace search and deduplication
(include_marketplace, marketplace_agents, library_names), ensuring variables
like mentioned_uuids, seen_graph_ids, library_agents, marketplace_agents, and
library_names remain unchanged and the control flow and awaits are preserved.
- Around line 30-33: Remove the inline section header comment block (the lines
with "#
============================================================================="
and "Type Definitions") from the top of the module in agent_generator/core.py;
simply delete those comment lines so no inline separators remain and leave only
the actual type definitions or code that follows (do not replace with any other
comments).
- Around line 129-183: The inline "Try 1: Look up by graph_id" and "Try 2: Look
up by library agent ID (primary key)" comments inside get_library_agent_by_id
should be removed to comply with the no-comments guideline; edit the function
body to delete those two comment lines (the rest of the docstring and
logging/debug statements should remain unchanged) so the lookup logic (calls to
library_db.get_library_agent_by_graph_id and library_db.get_library_agent, and
the exception handling for NotFoundError) is preserved but without the inline
"Try 1/2" annotations.
- Around line 397-484: The function enrich_library_agents_from_steps contains
multiple inline comments (e.g., those around extraction of search_terms,
existing_ids/existing_names, the loop limiting terms, deduplication logic, and
logging) which violate the no-comments guideline; remove all such inline/comment
lines inside the function body while preserving the existing docstring and exact
runtime behavior and variable usage (search_terms, existing_agents,
existing_ids, existing_names, all_agents,
get_all_relevant_agents_for_generation, and logger), ensuring only the
implementation remains and tests/logic are unchanged.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between aa175e0 and f00678f.

📒 Files selected for processing (3)
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • autogpt_platform/backend/test/agent_generator/test_library_agents.py
🧰 Additional context used
📓 Path-based instructions (2)
autogpt_platform/backend/**/*.py

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

autogpt_platform/backend/**/*.py: Always run backend setup commands in order: poetry install, poetry run prisma migrate dev, poetry run prisma generate before backend development
Always run poetry run format (Black + isort) before poetry run lint (ruff) for backend code
Use Python 3.10-3.13 with Python 3.11 required for development (managed by Poetry via pyproject.toml)

autogpt_platform/backend/**/*.py: Use FastAPI with async support for API endpoints in the backend
Use Prisma ORM for database operations with PostgreSQL
Use RabbitMQ for async task processing in the backend
Use JWT-based authentication with Supabase integration
Use poetry run format (Black + isort) to format code and poetry run lint (ruff) for linting in the backend
Use ClamAV integration for file upload security

autogpt_platform/backend/**/*.py: Format Python code with poetry run format
Run poetry run test (runs pytest with a docker based postgres + prisma) before committing backend changes

Files:

  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
autogpt_platform/**/*.{ts,tsx,js,py}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid comments at all times unless the code is very complex

Files:

  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py
  • autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py
⏰ 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). (6)
  • GitHub Check: types
  • GitHub Check: Seer Code Review
  • GitHub Check: test (3.13)
  • GitHub Check: test (3.12)
  • GitHub Check: test (3.11)
  • GitHub Check: Check PR Status
🔇 Additional comments (5)
autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py (4)

35-77: Typed summaries look good.

The TypedDict definitions and AgentSummary union are clear and consistent.


80-86: Helper conversion looks good.

_to_dict_list cleanly normalizes typed dicts for external calls.


186-187: Alias for backward compatibility is fine.

No issues here.


240-277: Marketplace search helper looks good.

Error handling and mapping are clean.

autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/__init__.py (1)

3-53: Exports look good.

Public API surface is consistent with the new helper/types.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py Outdated
Comment thread autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py Outdated
Added logging to help diagnose library search issues:
- Log the query and user_id when tool is called
- Log the number of results returned from database
@majdyz
majdyz requested a review from ntindle January 30, 2026 23:14
Comment thread autogpt_platform/backend/backend/api/features/chat/tools/agent_generator/core.py Outdated
Otto-AGPT
Otto-AGPT previously approved these changes Jan 30, 2026

@Otto-AGPT Otto-AGPT 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.

LGTM! 🚀

Solid implementation of sub-agent support with two-phase search. The quality metrics from recent executions are a nice touch for helping the LLM make informed decisions.

Changes addressed from review:

  • Logging levels adjusted
  • Test locations organized
  • Exception handling improved

CI passing. Nice work!

@Otto-AGPT Otto-AGPT 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.

Re-approved after latest commits ✅

Good fixes:

  • _populate_agent_executor_user_ids null handling
  • Reverted to simpler search (cleaner)
  • Short query fallback

LGTM!

AGENT_EXECUTOR_BLOCK_ID = "e189baac-8c20-45a1-94a7-55177ea42565"


class ExecutionSummary(TypedDict):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why typed dixt? The entire rest of the system uses pydantic

result = await decompose_goal_external(
description, context, _to_dict_list(library_agents)
)
return result # type: ignore[return-value]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think he just needs explanation why it is ignored

llm_parse_message="The AI had trouble generating the agent. Please try again or simplify your goal.",
validation_message="The generated agent failed validation. Please try rephrasing your goal.",
validation_message=(
"I wasn't able to create a valid agent for this request. "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

R we logging these failures to product somewhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Langfuse / Langsmith

@Otto-AGPT

Copy link
Copy Markdown
Contributor

Addressing open review comments from @ntindle:

Re: TypedDict vs Pydantic
TypedDicts are used here because these structures are passed directly to the external Agent Generator service as JSON. TypedDict provides type hints without runtime overhead and serializes cleanly to dict for the HTTP API. Pydantic would add .model_dump() calls everywhere.

Re: ??
Could you clarify what you're asking about here? Is it the # type: ignore[return-value] comment?

Re: Logging failures to product
Currently these failures are logged via logger.warning() which goes to standard logging (Sentry captures warnings). Not sending to a separate product analytics pipeline. Should we add PostHog/analytics tracking for these?

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 platform/frontend AutoGPT Platform - Front end size/xl

Projects

Status: ✅ Done
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants