Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/oss/javascript/migrate/langchain-v1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ import { createAgent, dynamicSystemPromptMiddleware } from "langchain";
import * as z from "zod";

const contextSchema = z.object({
userRole: z.enum(["expert", "beginner"]).default("user"),
userRole: z.enum(["expert", "beginner"]),
});

const userRolePrompt = dynamicSystemPromptMiddleware((request) => { // [!code highlight]
const userRole = request.runtime.context.userRole;
const userRolePrompt = dynamicSystemPromptMiddleware((state, runtime) => { // [!code highlight]
const userRole = runtime.context.userRole;
const basePrompt = "You are a helpful assistant.";

if (userRole === "expert") {
Expand All @@ -135,6 +135,7 @@ const agent = createAgent({

await agent.invoke({
messages: [new HumanMessage("Explain async programming")],
},{
context: {
userRole: "expert",
},
Expand All @@ -145,7 +146,7 @@ await agent.invoke({
import { createReactAgent } from "@langchain/langgraph/prebuilts";

const contextSchema = z.object({
userRole: z.enum(["expert", "beginner"]).default("user"),
userRole: z.enum(["expert", "beginner"]),
});

const agent = createReactAgent({
Expand All @@ -167,7 +168,8 @@ const agent = createReactAgent({

// Use with context
await agent.invoke({
messages: [new HumanMessage("Explain async programming")],
messages: [new HumanMessage("Explain async programming")]
}, {
context: { userRole: "expert" },
});
```
Expand Down