馃 feat: Resolve Explicit Subagents Lazily - #14714
Conversation
There was a problem hiding this comment.
Pull request overview
Implements lazy resolution for explicit subagents by advertising lightweight, VIEW-checked descriptors up-front and deferring expensive child initialization (tools/MCP/files/skills/model validation) until the SDK selects a specific subagent, with a fail-closed recheck on selection (VIEW + versioned config fingerprint).
Changes:
- Added lazy subagent descriptor plumbing in the runtime subagent config builder and capability traversals (code env / stateful sessions / reasoning replay).
- Introduced deterministic, secret-scrubbed config fingerprinting for lazy descriptor identity and selection-time drift detection.
- Refactored agent initialization to advertise inert descriptors, initialize selected subagents on-demand, and expanded test coverage for limits/cancellation/config drift.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/api/src/agents/run.ts | Builds subagent configs with support for inert lazy descriptors and resolves selected children on-demand. |
| api/server/services/Endpoints/agents/initialize.js | Advertises lazy subagent descriptors, enforces selection-time VIEW + fingerprint checks, and initializes selected subagents lazily. |
| api/server/services/Endpoints/agents/initialize.spec.js | Updates/expands regression coverage for lazy descriptor behavior, limits, cancellation, and config drift. |
| packages/api/src/agents/lazySubagents.ts | Adds deterministic fingerprinting for lazy descriptor identity with secret-key exclusion and stable canonicalization. |
| packages/api/src/agents/lazySubagents.spec.ts | Tests fingerprint stability, drift detection, secret exclusion, and version inclusion. |
| packages/api/src/agents/tests/run-summarization.test.ts | Ensures descriptors are advertised without eager inputs and resolves lazily with correct budgeting behavior. |
| packages/api/src/agents/statefulCodeSessions.spec.ts | Verifies stateful-session prewarm detection includes inert lazy descriptors. |
| packages/api/src/agents/run.spec.ts | Verifies reasoning replay detection includes inert lazy descriptors. |
| packages/api/src/agents/usage.spec.ts | Ensures usage pricing resolver observes per-agent pricing entries added after resolver creation. |
| packages/api/src/agents/index.ts | Exports the new lazy subagent fingerprint helpers. |
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (subagentIds.length > 0 && depth >= MAX_SUBAGENT_DEPTH) { | ||
| throw new Error( | ||
| `Subagent graph exceeds the maximum depth of ${MAX_SUBAGENT_DEPTH} at agent ${agent.id}.`, | ||
| ); | ||
| } |
c0a3986 to
1e30e8d
Compare
1e30e8d to
280eed3
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: 鈩癸笍 About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 馃憤. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
I changed explicit single-agent subagents to advertise lightweight, authorization-checked descriptors and defer their expensive runtime initialization until the SDK selects them. This implements AI-1714 against the lazy resolver contract in
@librechat/agents3.4.3.Change Type
Testing
node --check api/server/services/Endpoints/agents/initialize.js.git diff --check.gpt-4.1-miniand Anthropicclaude-haiku-4-5: both selected resolvers ran exactly once, unused sibling resolvers stayed cold, expected output returned, and positive child usage was emitted.Test Configuration:
@librechat/agents3.4.3Checklist