Skip to content

Commit ae70fa4

Browse files
fix(deepagents): pass on subagent name (#218)
* fix(deepagents): pass on subagent name * Add changeset for deepagents patch * update deps * format
1 parent 4b2892b commit ae70fa4

File tree

6 files changed

+537
-416
lines changed

6 files changed

+537
-416
lines changed

.changeset/quiet-doors-yawn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"deepagents": patch
3+
---
4+
5+
fix(deepagents): pass on subagent name

libs/deepagents/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@
3838
},
3939
"homepage": "https://github.com/langchain-ai/deepagentsjs#readme",
4040
"dependencies": {
41-
"@langchain/core": "^1.1.21",
41+
"@langchain/core": "^1.1.22",
4242
"@langchain/langgraph": "^1.1.4",
4343
"fast-glob": "^3.3.3",
44-
"langchain": "^1.2.20",
44+
"langchain": "^1.2.21",
4545
"micromatch": "^4.0.8",
4646
"yaml": "^2.8.2",
4747
"zod": "^4.3.6"
4848
},
4949
"devDependencies": {
5050
"@langchain/langgraph-checkpoint": "^1.0.0",
51-
"@langchain/openai": "^1.2.3",
51+
"@langchain/openai": "^1.2.7",
5252
"@langchain/tavily": "^1.2.0",
5353
"@tsconfig/recommended": "^1.0.13",
5454
"@types/micromatch": "^4.0.10",
55-
"@types/node": "^25.1.0",
55+
"@types/node": "^25.2.3",
5656
"@types/uuid": "^11.0.0",
5757
"@vitest/coverage-v8": "^4.0.18",
5858
"@vitest/ui": "^4.0.18",
59-
"dotenv": "^17.2.3",
60-
"tsdown": "^0.20.1",
59+
"dotenv": "^17.2.4",
60+
"tsdown": "^0.20.3",
6161
"tsx": "^4.21.0",
6262
"typescript": "^5.9.3",
6363
"uuid": "^13.0.0",

libs/deepagents/src/middleware/subagents.int.test.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { describe, it, expect } from "vitest";
2-
import { createAgent, createMiddleware, ReactAgent } from "langchain";
2+
import { createAgent, createMiddleware, ReactAgent, tool } from "langchain";
33
import { AIMessage, BaseMessage, HumanMessage } from "@langchain/core/messages";
44
import { MemorySaver } from "@langchain/langgraph";
5+
import { z } from "zod/v4";
56
import {
67
createSubAgentMiddleware,
78
createFilesystemMiddleware,
@@ -842,4 +843,64 @@ Use the write_file tool to save your code.`,
842843
expect(usedConsoleLog).toBe(false);
843844
},
844845
);
846+
847+
it.concurrent(
848+
"should propagate lc_agent_name metadata to tools inside subagents",
849+
{ timeout: 90 * 1000 }, // 90s
850+
async () => {
851+
/**
852+
* This test verifies that when a subagent is created with a name,
853+
* its tools can access the agent name via config.metadata.lc_agent_name.
854+
* This is critical for identifying which agent invoked a shared tool.
855+
*/
856+
let capturedAgentName: string | undefined;
857+
858+
const identifyingTool = tool(
859+
(input, config) => {
860+
capturedAgentName = config.metadata?.lc_agent_name;
861+
return `Weather in ${input.location} is sunny. Agent: ${capturedAgentName}`;
862+
},
863+
{
864+
name: "get_weather_with_identity",
865+
description: "Get the weather and identify the calling agent",
866+
schema: z.object({ location: z.string() }),
867+
},
868+
);
869+
870+
const agent = createAgent({
871+
model: SAMPLE_MODEL,
872+
systemPrompt:
873+
"Use the weather-agent subagent to get the weather. Always delegate to the subagent.",
874+
middleware: [
875+
createSubAgentMiddleware({
876+
defaultModel: SAMPLE_MODEL,
877+
defaultTools: [],
878+
subagents: [
879+
{
880+
name: "weather-agent",
881+
description:
882+
"A weather specialist agent. Use this for any weather queries.",
883+
systemPrompt:
884+
"You are a weather specialist. Use the get_weather_with_identity tool to answer weather questions.",
885+
tools: [identifyingTool],
886+
},
887+
],
888+
}),
889+
],
890+
});
891+
892+
const response = await agent.invoke({
893+
messages: [new HumanMessage("What is the weather in Tokyo?")],
894+
});
895+
896+
// Verify the task tool was called with the weather-agent subagent
897+
const toolCalls = extractAllToolCalls(response);
898+
const taskCall = toolCalls.find((tc) => tc.name === "task");
899+
expect(taskCall).toBeDefined();
900+
expect(taskCall!.args.subagent_type).toBe("weather-agent");
901+
902+
// Verify the tool captured the correct agent name
903+
expect(capturedAgentName).toBe("weather-agent");
904+
},
905+
);
845906
});

libs/deepagents/src/middleware/subagents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ function getSubagents(options: {
435435
systemPrompt: DEFAULT_SUBAGENT_PROMPT,
436436
tools: defaultTools as any,
437437
middleware: generalPurposeMiddleware,
438+
name: "general-purpose",
438439
});
439440

440441
agents["general-purpose"] = generalPurposeSubagent;
@@ -465,6 +466,7 @@ function getSubagents(options: {
465466
systemPrompt: agentParams.systemPrompt,
466467
tools: agentParams.tools ?? defaultTools,
467468
middleware,
469+
name: agentParams.name,
468470
});
469471
}
470472
}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
"eslint-config-prettier": "^10.1.8",
4949
"eslint-plugin-import": "^2.32.0",
5050
"eslint-plugin-no-instanceof": "^1.0.1",
51-
"eslint-plugin-prettier": "^5.5.4",
52-
"globals": "^17.0.0",
53-
"jiti": "^2.4.2",
54-
"prettier": "^3.7.4",
51+
"eslint-plugin-prettier": "^5.5.5",
52+
"globals": "^17.3.0",
53+
"jiti": "^2.6.1",
54+
"prettier": "^3.8.1",
5555
"tsx": "^4.21.0",
5656
"typescript": "^5.9.3",
57-
"typescript-eslint": "^8.52.0"
57+
"typescript-eslint": "^8.55.0"
5858
},
59-
"packageManager": "pnpm@10.27.0"
59+
"packageManager": "pnpm@10.29.2"
6060
}

0 commit comments

Comments
 (0)