feat(langgraph): Add tool support to LangGraph templates#130
feat(langgraph): Add tool support to LangGraph templates#130andreiborza wants to merge 6 commits intomainfrom
Conversation
This PR adds tool calls to LangGraph templates. It creates tools using `@langchain/core/tools` with zod schemas.
|
Looks good! This reminded me that |
|
Yep, the alternative is https://docs.langchain.com/oss/javascript/releases/langchain-v1#createagent, we'll need to instrument that too at some point. |
🔴 AI SDK Integration Test ResultsStatus: 2 regressions detected Summary
🔴 RegressionsThese tests were passing on main but are now failing: browser/openai :: Multi-Turn LLM Test (blocking)Error: Browser test timed out (60s) node/google-genai :: Conversation ID LLM Test (blocking)Error: 2 check(s) failed: ✅ FixedThese tests were failing on main but are now passing:
Test MatrixAgent Tests
Embedding Tests
LLM Tests
MCP Tests
Legend: ✅ Pass | ❌ Fail | ✅🔧 Fixed | ❌📉 Regressed | ✅🆕 New (pass) | ❌🆕 New (fail) | 🗑️ Removed | str=streaming blk=blocking a=async s=sync io=stdio sse=sse hi=highlevel lo=lowlevel Generated by AI SDK Integration Tests |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
d84fd14 to
390aa97
Compare
src/test-cases/checks.ts
Outdated
| let actualArgs: Record<string, unknown>; | ||
| const argsRaw = | ||
| foundCall.arguments || | ||
| foundCall.args || |
There was a problem hiding this comment.
Not sure if we should do that. This comes from the gen_ai.output.messages (or the old tool_call one) which includes the tool calls as ToolCallRequestPart, which has "arguments", not "args".
Here's the relevant schema:
"ToolCallRequestPart": {
"additionalProperties": true,
"description": "Represents a tool call requested by the model.",
"properties": {
"type": {
"const": "tool_call",
"description": "The type of the content captured in this part.",
"title": "Type",
"type": "string"
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Unique identifier for the tool call.",
"title": "Id"
},
"name": {
"description": "Name of the tool.",
"title": "Name",
"type": "string"
},
"arguments": {
"default": null,
"description": "Arguments for the tool call.",
"title": "Arguments"
}
},I would opt to fix that in the integration, tbh.
There was a problem hiding this comment.
Hm, ok. But doesn't foundCall.function also go against this schema? As far as I can tell that is also there for OpenAI's format.
Not saying we should add yet another exception, I can remap it in the SDK but remapping logic becomes brittle quick.
Let me know what you think @constantinius.
There was a problem hiding this comment.
I went ahead and reverted in 8976eee and will normalize on the SDK side for the time being.
| name: "{{ toolDef.name }}", | ||
| description: "{{ toolDef.description }}", | ||
| schema: z.object({ | ||
| {% if toolDef.parameters and toolDef.parameters.properties %} | ||
| {% for paramName, paramDef in toolDef.parameters.properties %} | ||
| {{ paramName }}: {{ zodType(paramDef.type) }}{% if paramDef.description %}.describe("{{ paramDef.description }}"){% endif %}, |
There was a problem hiding this comment.
Bug: Tool definition properties like name and description are rendered into a JavaScript template without escaping, which can lead to syntax errors if they contain special characters.
Severity: HIGH
Suggested Fix
Apply an appropriate escaping mechanism to the toolDef.name, toolDef.description, and toolDef.error variables within the Nunjucks template. Using a filter that JSON-encodes the string, similar to the | dump filter used for toolDef.result, would ensure the output is a valid JavaScript string literal.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/runner/templates/agents/node/langgraph/template.njk#L44-L49
Potential issue: The Nunjucks template at
`src/runner/templates/agents/node/langgraph/template.njk` directly interpolates tool
definition properties like `toolDef.name`, `toolDef.description`, and `toolDef.error`
into JavaScript string literals. Since Nunjucks is configured with `autoescape: false`
and no specific JavaScript escaping filter is applied, any special characters (e.g.,
double quotes, backslashes, newlines) within these properties will break the syntax of
the generated JavaScript. This will cause the generated test script to fail with a
`SyntaxError` at runtime when a tool's metadata contains such characters.

This PR adds tool calls to LangGraph templates. It creates tools using
@langchain/core/toolswith zod schemas.