An optional schema for the context. It allows to pass in a typed context object into the agent
invocation and allows to access it in hooks such as prompt and middleware.
As opposed to the agent state, defined in stateSchema, the context is not persisted between
agent invocations.
contextSchema: ContextSchemaconst agent = createAgent({
llm: model,
tools: [getWeather],
contextSchema: z.object({
capital: z.string(),
}),
prompt: (state, config) => {
return [
new SystemMessage(`You are a helpful assistant. The capital of France is ${config.context.capital}.`),
];
},
});
const result = await agent.invoke({
messages: [
new SystemMessage("You are a helpful assistant."),
new HumanMessage("What is the capital of France?"),
],
}, {
context: {
capital: "Paris",
},
});