feat: recursive graph_sub_agent tool for Jarvis graph exploration#1461
Merged
Conversation
Spawns an in-process child agent with its own copy of the Jarvis graph tools (get_ontology, graph_search, graph_get, graph_neighbors) so a parent agent can locate key nodes then fan out focused sub-agents and collate their findings. Opt-in via toolsConfig.graph_sub_agent; recursion is depth-capped (maxDepth, default 2) so children can't spawn forever, plus a per-run step cap (maxSteps, default 20).
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.
What
Adds a new
graph_sub_agenttool to the Jarvis knowledge-graph toolset (mcp/src/repo/toolsJarvis.ts). It spawns an in-process child agent with its own copy of the graph tools (get_ontology,graph_search,graph_get,graph_neighbors) that explores based on a prompt from the parent and returns a synthesized text summary.This lets a parent agent locate a few key nodes, then fan out one focused sub-agent per node/subtopic and collate their findings.
How
registerJarvisTools(allTools, options?)gains an optionaloptions.subAgentconfig. The 4 read tools register as before;graph_sub_agentregisters only whensubAgentis present and the current recursion depth is belowmaxDepth.graph_sub_agent.execute({ prompt })builds a fresh child tool set by recursively callingregisterJarvisToolswithdepth + 1, then runs aToolLoopAgent(same LLM/provider viagetModelDetails) with a dedicated system prompt, returningextractFinalAnswer(...). Mirrors the existinglog_agent_contextpattern.maxDepthdefaults to2. Because the tool only registers whiledepth < maxDepth, leaf children never receive agraph_sub_agenttool, so recursion can't run forever. Also a per-runmaxStepscap (default 20).mcp/src/repo/tools.ts: addedgraph_sub_agenttoToolName,TOOL_NAMES, andDEFAULT_DESCRIPTIONS; theregisterJarvisTools(...)call passessubAgentconfig gated ontoolsConfig.graph_sub_agent(a string value overrides the description).Config
{ "toolsConfig": { "graph_sub_agent": true } } // or override the description: { "toolsConfig": { "graph_sub_agent": "Delegate a focused graph lookup..." } }Testing
npx tsc --noEmitcleannpm run test:node(tools suite) — 21/21 pass