From bebbf5d9a068496675bd802f0ac172a4ae3daf76 Mon Sep 17 00:00:00 2001 From: Hunter Lovell Date: Fri, 7 Nov 2025 16:39:39 -0800 Subject: [PATCH] chore(oss/js): update runtime doc Fixes https://github.com/langchain-ai/langchainjs/issues/9364 --- src/oss/langchain/runtime.mdx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/oss/langchain/runtime.mdx b/src/oss/langchain/runtime.mdx index 4e38c7c13b..1a6c375c53 100644 --- a/src/oss/langchain/runtime.mdx +++ b/src/oss/langchain/runtime.mdx @@ -128,14 +128,14 @@ Use the `runtime` parameter to access the @[`Runtime`] object inside a tool. ```ts import * as z from "zod"; import { tool } from "langchain"; -import { type Runtime } from "@langchain/langgraph"; // [!code highlight] +import { type ToolRuntime } from "@langchain/core/tools"; // [!code highlight] const contextSchema = z.object({ userName: z.string(), }); const fetchUserEmailPreferences = tool( - async (_, runtime: Runtime>) => { // [!code highlight] + async (_, runtime: ToolRuntime) => { // [!code highlight] const userName = runtime.context?.userName; // [!code highlight] if (!userName) { throw new Error("userName is required"); @@ -216,7 +216,7 @@ Use the `runtime` parameter to access the @[`Runtime`] object inside middleware. ```ts import * as z from "zod"; -import { createAgent, createMiddleware, type AgentState, SystemMessage } from "langchain"; +import { createAgent, createMiddleware, SystemMessage } from "langchain"; import { type Runtime } from "@langchain/langgraph"; // [!code highlight] const contextSchema = z.object({ @@ -226,7 +226,8 @@ const contextSchema = z.object({ // Dynamic prompt middleware const dynamicPromptMiddleware = createMiddleware({ name: "DynamicPrompt", - beforeModel: (state: AgentState, runtime: Runtime>) => { // [!code highlight] + contextSchema + beforeModel: (state, runtime: Runtime>) => { // [!code highlight] const userName = runtime.context?.userName; // [!code highlight] if (!userName) { throw new Error("userName is required"); @@ -242,11 +243,12 @@ const dynamicPromptMiddleware = createMiddleware({ // Logging middleware const loggingMiddleware = createMiddleware({ name: "Logging", - beforeModel: (state: AgentState, runtime: Runtime>) => { // [!code highlight] + contextSchema, + beforeModel: (state, runtime) => { // [!code highlight] console.log(`Processing request for user: ${runtime.context?.userName}`); // [!code highlight] return; }, - afterModel: (state: AgentState, runtime: Runtime>) => { // [!code highlight] + afterModel: (state, runtime) => { // [!code highlight] console.log(`Completed request for user: ${runtime.context?.userName}`); // [!code highlight] return; }