New in the OpenRouter TypeScript SDK: typed tool context/state. Define a contextSchema on tools. Pass context from callModel keyed by tool name. Mutate it mid-execution with `setContext()`. Changes persist across turns and are Zod-validated. Here's a research agent that builds up sources as it goes:
OpenRouter TypeScript SDK Brings Typed Tool Context to AI Agents
· Updated
OpenRouter's SDK adds typed context and state for AI agents. Define a
contextSchema on your tools, pass context from callModel keyed by tool name, then mutate it mid-execution using setContext() — changes persist across turns and are Zod-validated. A research agent accumulates sources as it iterates, keeping memory between calls.The feature ties state directly to individual tools rather than managing it externally. Context is keyed per tool name and type-checked at runtime, so each tool in an agentic workflow carries its own validated state across turns without additional wiring.
Add contextSchema to your tool definitions and let setContext() handle persistence. The SDK supports TypeScript and Python, with Go and Java also available.
OpenRouter
@OpenRouter
2retweets
View on X



