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 TypeScript SDK now supports typed tool context. Define a contextSchema on your tools and mutate context across agentic turns — changes persist and are Zod-validated. A research agent can accumulate sources across iterations.
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.
Every HeadsUpAI update is written based on its original source and reviewed before it's published. Read our editorial standards →




