mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
🕸️ feat: Run Saved Agent Teams as Subagents (#14944)
* feat: Add graph subagent integration * style: Sort response usage test imports * fix: Preserve lazy graph runtime context * fix: Use isolated graph input helper * test: Align graph integration fixtures * fix: Preserve lazy graph runtime capabilities * fix: Bound lazy graph metadata preload * fix: Harden lazy graph resolution lifecycle * fix: Coalesce lazy graph member resolution * fix: Snapshot initialized graph members only * fix: Preserve lazy agent runtime context * fix: Preserve batched lazy context preparation * fix: Preserve graph member capability bounds * fix: reconcile graph subagents with execution profiles * style: align graph subagent types with formatter
This commit is contained in:
parent
7ee9e4e363
commit
7d62be2ad3
36 changed files with 3903 additions and 636 deletions
|
|
@ -7,8 +7,8 @@ import { resolveCodeExecutionContext, type CodeExecutionContext } from './execut
|
|||
* Minimal shape for an agent that may contribute primed code files to its
|
||||
* execution-profile partition. Both `InitializedAgent` and `RunAgent` satisfy it,
|
||||
* and the recursive walk in {@link buildInitialToolSessions} traverses
|
||||
* `subagentAgentConfigs` so nested subagents (which aren't in the top-level
|
||||
* `agentConfigs` map after pure-subagent pruning) still contribute.
|
||||
* legacy child configs and graph-member configs so agents pruned from the
|
||||
* top-level `agentConfigs` map still contribute.
|
||||
*/
|
||||
export interface CodeFilesAgent {
|
||||
id?: string;
|
||||
|
|
@ -20,6 +20,7 @@ export interface CodeFilesAgent {
|
|||
statefulCodeEnvironment?: StatefulCodeEnvironment;
|
||||
subagentAgentConfigs?: CodeFilesAgent[];
|
||||
lazySubagentConfigs?: CodeFilesAgent[];
|
||||
subagentGraphConfigs?: Array<{ memberConfigs: CodeFilesAgent[] }>;
|
||||
}
|
||||
|
||||
export interface CodeExecutionProfileRoute {
|
||||
|
|
@ -27,6 +28,24 @@ export interface CodeExecutionProfileRoute {
|
|||
codeSessionKeys: string[];
|
||||
}
|
||||
|
||||
function enqueueCodeFilesChildren(
|
||||
agent: CodeFilesAgent,
|
||||
queue: CodeFilesAgent[],
|
||||
visited: Set<CodeFilesAgent>,
|
||||
): void {
|
||||
for (const child of [
|
||||
...(agent.subagentAgentConfigs ?? []),
|
||||
...(agent.lazySubagentConfigs ?? []),
|
||||
]) {
|
||||
if (child && !visited.has(child)) queue.push(child);
|
||||
}
|
||||
for (const graph of agent.subagentGraphConfigs ?? []) {
|
||||
for (const member of graph.memberConfigs) {
|
||||
if (member && !visited.has(member)) queue.push(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Collects the distinct Code API deployments used by a run and every
|
||||
* trusted session partition that must receive that deployment's immutable
|
||||
* skill-file seed. */
|
||||
|
|
@ -66,12 +85,7 @@ export function collectCodeExecutionProfileRoutes(
|
|||
route.codeSessionKeys.add(agent.codeSessionKey ?? context.codeSessionKey);
|
||||
routes.set(context.executionProfile, route);
|
||||
}
|
||||
for (const child of [
|
||||
...(agent.subagentAgentConfigs ?? []),
|
||||
...(agent.lazySubagentConfigs ?? []),
|
||||
]) {
|
||||
if (child && !visited.has(child)) queue.push(child);
|
||||
}
|
||||
enqueueCodeFilesChildren(agent, queue, visited);
|
||||
}
|
||||
return Array.from(routes.values(), (route) => ({
|
||||
codeExecutionContext: route.codeExecutionContext,
|
||||
|
|
@ -195,8 +209,8 @@ export function buildAgentInitialToolSessions(
|
|||
* profile partition; this helper never copies a pointer across partitions.
|
||||
*
|
||||
* **Walk order:** primary first, then `agentConfigs` (handoff/addedConvo)
|
||||
* in iteration order, then recurse into each config's
|
||||
* `subagentAgentConfigs` breadth-first. Order matters because when no
|
||||
* in iteration order, then recurse through legacy children and graph members
|
||||
* breadth-first. Order matters because when no
|
||||
* skill sessions exist, the FIRST agent's first file supplies the
|
||||
* representative `session_id` written to `Graph.sessions[EXECUTE_CODE]`.
|
||||
* `ToolNode` ultimately uses per-file `session_id`s for injection so
|
||||
|
|
@ -214,7 +228,7 @@ export function buildAgentInitialToolSessions(
|
|||
* from the skill side is preserved).
|
||||
* @param agents - The complete set of code-execution-capable agents in
|
||||
* the run. Caller passes `[primaryConfig, ...agentConfigs.values()]`;
|
||||
* this function recurses into each one's `subagentAgentConfigs`.
|
||||
* this function recurses into every reachable subagent configuration.
|
||||
*/
|
||||
export function buildInitialToolSessions(params: {
|
||||
skillSessions?: ToolSessionMap;
|
||||
|
|
@ -244,11 +258,7 @@ export function buildInitialToolSessions(params: {
|
|||
if (agent.primedCodeFiles && agent.primedCodeFiles.length > 0) {
|
||||
sessions = seedCodeFilesIntoSessions(agent.primedCodeFiles, sessions, sessionKey);
|
||||
}
|
||||
if (agent.subagentAgentConfigs && agent.subagentAgentConfigs.length > 0) {
|
||||
for (const child of agent.subagentAgentConfigs) {
|
||||
if (child && !visited.has(child)) queue.push(child);
|
||||
}
|
||||
}
|
||||
enqueueCodeFilesChildren(agent, queue, visited);
|
||||
}
|
||||
return sessions;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue