-
Notifications
You must be signed in to change notification settings - Fork 363
Description
Checked other resources
- I added a very descriptive title to this issue.
- I searched the LangGraph.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangGraph.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).
Example Code
import { createAgent, createMiddleware, SystemMessage } from 'langchain';
import { z } from 'zod';
const contextSchema = z.object({
systemPromptRef: z.string(),
});
const agent = createAgent({
name: 'testAgent',
model: model,
middleware: [dynamicPromptMiddleware],
contextSchema: contextSchema,
});
const dynamicPromptMiddleware = createMiddleware({
name: 'DynamicPrompt',
beforeAgent: async (state, runtime) => {
const systemMsg = runtime.context.systemPrompt ?? 'default test';
return {
messages: [new SystemMessage(systemMsg), ...state.messages],
};
},
contextSchema: contextSchema,
});
export const testAgent = agent.graph;Error Message and Stack Trace (if applicable)
No response
Description
The context passed through the LangSmith UI is not properly passed to the context object.
The parameter shows up in the LangSmith UI when I try to create a new assistant, but is not available on the context object when entering my custom middleware (the context object is empty).
I saw a related issue logged for LangchainJS: langchain-ai/langchainjs#9222
The fix proposed here seems to solve my issue.
System Info
Node version: v22.16.0
Operating system: darwin arm64
Package manager: npm
Package manager version: 11.2.1
@langchain/core -> @1.0.3, , @"1.0.3", @"^1.0.1", @"^0.3.59, @"^1.0.0", @"^1.0.3"
langsmith -> @0.3.79, , @"^0.3.79", @"^0.3.64", @"^0.3.33", @"~0.3.74"
zod -> @3.25.76, , @"3.25.76"
@langchain/langgraph-cli -> @1.0.3, , @"1.0.3"
@langchain/langgraph-api -> @1.0.3, , @"1.0.3"
@langchain/langgraph-checkpoint -> @1.0.0, , @"^1.0.0", @"~0.0.16
@langchain/langgraph-sdk -> @1.0.0, , @"^1.0.0", @"~1.0.0", @"~0.0.16
@langchain/langgraph-ui -> @1.0.3, , @"1.0.3"
@langchain/langgraph -> @1.0.1, , @"1.0.1", @"^0.2.57, @"^0.2.72, @"^1.0.0"
@langchain/langgraph-supervisor -> @1.0.0, , @"1.0.0"
@langchain/mcp-adapters -> @1.0.0, , @"^1.0.0"
@langchain/openai -> @1.0.0, , @"1.0.0"
langchain -> @1.0.3, , @"^1.0.3"