Skip to content

fix #14249: Load agent subagents in Responses & OpenAI-compat APIs - #1

Open
houbie wants to merge 2 commits into
devfrom
cursor/api-subagents-dev-67fb
Open

houbie wants to merge 2 commits into
devfrom
cursor/api-subagents-dev-67fb

Conversation

@houbie

@houbie houbie commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Subagents (agent.subagents.agent_ids) were only resolved in the chat UI
initialization path. The Responses API (/v1/responses) and the
OpenAI-compatible API (/v1/chat/completions) only ran handoff-edge discovery
and graph-team resolution, so a primary agent invoked through those endpoints
never had its subagent spawn targets loaded — the model was unaware of the
subagent and could not delegate to it.

This PR extracts explicit agent_ids resolution into a shared helper and wires
it into the Responses and OpenAI-compat entry points so those paths match the
chat UI.

Fixes LibreChat-AI#14249

Replaces LibreChat-AI#14250 (retargeted from main to dev and rebased onto current dev).

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Changes

  • packages/api/src/agents/discovery.ts — resolveSubagents() helper
    alongside the existing resolveSubagentGraphs(): nested-tree BFS,
    MAX_SUBAGENT_DEPTH / MAX_SUBAGENT_GRAPH_NODES limits, id dedupe, self-cycle
    guard, pure-subagent pruning (kept in agentToolContexts via
    onAgentInitialized for ON_TOOL_EXECUTE), and capability-disabled stripping.
  • Wire resolveSubagents into responses.js and openai.js, using the same
    REMOTE_AGENT sharing boundary and remote permission check as the primary
    agent.
  • Leave initialize.js (chat path) unchanged — it already resolves explicit
    subagents via the lazy descriptor walk on current dev.
  • Add subagentAgentConfigs to the InitializedAgent type.
  • Include loaded subagentAgentConfigs in the OpenAI-compat context walk
    (attachments, scoped context, inline memory), matching the Responses path.
  • Perf: only fetch getModelsConfig when handoff discovery or real subagent
    loading actually needs it, keeping the common single-agent request off that
    (potentially network-bound) path.
  • Hardening: call resolveSubagents unconditionally in the remote paths so that
    when the subagents capability is disabled, any persisted subagents are
    stripped and createRun can't expose self-spawn.
  • Tests: add unit tests for resolveSubagents in discovery.spec.ts; add the
    resolveSubagents mock and controller coverage to the Responses/OpenAI specs.

Test plan

  • cd packages/api && npx jest src/agents/discovery.spec.ts (42 passed, including 6 new resolveSubagents cases)
  • cd api && npx jest server/controllers/agents/__tests__/responses.unit.spec.js server/controllers/agents/__tests__/openai.spec.js (92 passed)
  • npm run build:data-provider and packages/api build succeed
  • Manual: invoke a parent agent with a configured subagent via POST /v1/responses and confirm the subagent spawn tool is exposed and callable

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
Open in Web Open in Cursor 

Subagents (agent.subagents.agent_ids) were only resolved in the chat
initialization path. The Responses API and OpenAI-compatible API only
ran handoff-edge discovery and graph-team resolution, so a primary
agent invoked through those endpoints never had its spawn targets
loaded.

Add resolveSubagents alongside resolveSubagentGraphs and wire it into
both remote controllers so explicit agent_ids are loaded with the same
REMOTE_AGENT sharing boundary as the primary.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remote chat-completion runs already walked subagentAgentConfigs for
model-bound content checks, but context attachments and memory still
only considered handoff agents and graph members.

Co-authored-by: Cursor <cursoragent@cursor.com>
@houbie houbie closed this Sep 2, 2026
@houbie
houbie deleted the cursor/api-subagents-dev-67fb branch September 2, 2026 09:59
@cursor
cursor Bot restored the cursor/api-subagents-dev-67fb branch September 3, 2026 08:29
@houbie houbie reopened this Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants