Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Subagents (
agent.subagents.agent_ids) were only resolved in the chat UIinitialization path. The Responses API (
/v1/responses) and theOpenAI-compatible API (
/v1/chat/completions) only ran handoff-edge discoveryand 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_idsresolution into a shared helper and wiresit 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
maintodevand rebased onto currentdev).Change Type
Changes
packages/api/src/agents/discovery.ts—resolveSubagents()helperalongside the existing
resolveSubagentGraphs(): nested-tree BFS,MAX_SUBAGENT_DEPTH/MAX_SUBAGENT_GRAPH_NODESlimits, id dedupe, self-cycleguard, pure-subagent pruning (kept in
agentToolContextsviaonAgentInitializedforON_TOOL_EXECUTE), and capability-disabled stripping.resolveSubagentsintoresponses.jsandopenai.js, using the sameREMOTE_AGENTsharing boundary and remote permission check as the primaryagent.
initialize.js(chat path) unchanged — it already resolves explicitsubagents via the lazy descriptor walk on current
dev.subagentAgentConfigsto theInitializedAgenttype.subagentAgentConfigsin the OpenAI-compat context walk(attachments, scoped context, inline memory), matching the Responses path.
getModelsConfigwhen handoff discovery or real subagentloading actually needs it, keeping the common single-agent request off that
(potentially network-bound) path.
resolveSubagentsunconditionally in the remote paths so thatwhen the
subagentscapability is disabled, any persistedsubagentsarestripped and
createRuncan't expose self-spawn.resolveSubagentsindiscovery.spec.ts; add theresolveSubagentsmock and controller coverage to the Responses/OpenAI specs.Test plan
cd packages/api && npx jest src/agents/discovery.spec.ts(42 passed, including 6 newresolveSubagentscases)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-providerandpackages/apibuild succeedPOST /v1/responsesand confirm the subagent spawn tool is exposed and callableChecklist