Skip to content

Commit 7ed72cb

Browse files
authored
chore(oss/js): fix ToolRuntime references in docs (#1338)
Fixes langchain-ai/langchainjs#9318
1 parent 146193b commit 7ed72cb

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/oss/langchain/context-engineering.mdx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ import { tool } from "@langchain/core/tools";
691691
import { z } from "zod";
692692

693693
const searchOrders = tool(
694-
async ({ userId, status, limit = 10 }) => {
694+
async ({ userId, status, limit }) => {
695695
// Implementation here
696696
},
697697
{
@@ -1612,11 +1612,10 @@ Most real-world tools need more than just the LLM's parameters. They need user I
16121612

16131613
```typescript
16141614
import * as z from "zod";
1615-
import { tool } from "@langchain/core/tools";
1616-
import { createAgent } from "langchain";
1615+
import { createAgent, tool, type ToolRuntime } from "langchain";
16171616

16181617
const checkAuthentication = tool(
1619-
async (_, { runtime }) => {
1618+
async (_, runtime: ToolRuntime) => {
16201619
// Read from State: check current auth status
16211620
const currentState = runtime.state;
16221621
const isAuthenticated = currentState.authenticated || false;
@@ -1683,15 +1682,14 @@ Most real-world tools need more than just the LLM's parameters. They need user I
16831682

16841683
```typescript
16851684
import * as z from "zod";
1686-
import { tool } from "@langchain/core/tools";
1687-
import { createAgent } from "langchain";
1685+
import { createAgent, tool, type ToolRuntime } from "langchain";
16881686

16891687
const contextSchema = z.object({
16901688
userId: z.string(),
16911689
});
16921690

16931691
const getPreference = tool(
1694-
async ({ preferenceKey }, { runtime }) => {
1692+
async ({ preferenceKey }, runtime: ToolRuntime) => {
16951693
const userId = runtime.context.userId;
16961694

16971695
// Read from Store: get existing preferences
@@ -1781,7 +1779,7 @@ Most real-world tools need more than just the LLM's parameters. They need user I
17811779
});
17821780

17831781
const fetchUserData = tool(
1784-
async ({ query }, { runtime }) => {
1782+
async ({ query }, runtime: ToolRuntime<any, typeof contextSchema>) => {
17851783
// Read from Runtime Context: get API key and DB connection
17861784
const { userId, apiKey, dbConnection } = runtime.context;
17871785

@@ -1856,7 +1854,7 @@ and update the memory of the agent to make important context available to future
18561854
import { Command } from "@langchain/langgraph";
18571855

18581856
const authenticateUser = tool(
1859-
async ({ password }, { runtime }) => {
1857+
async ({ password }) => {
18601858
// Perform authentication
18611859
if (password === "correct") {
18621860
// Write to State: mark as authenticated using Command
@@ -1929,15 +1927,10 @@ and update the memory of the agent to make important context available to future
19291927

19301928
```typescript
19311929
import * as z from "zod";
1932-
import { tool } from "@langchain/core/tools";
1933-
import { createAgent } from "langchain";
1934-
1935-
const contextSchema = z.object({
1936-
userId: z.string(),
1937-
});
1930+
import { createAgent, tool, type ToolRuntime } from "langchain";
19381931

19391932
const savePreference = tool(
1940-
async ({ preferenceKey, preferenceValue }, { runtime }) => {
1933+
async ({ preferenceKey, preferenceValue }, runtime: ToolRuntime<any, typeof contextSchema>) => {
19411934
const userId = runtime.context.userId;
19421935

19431936
// Read existing preferences

0 commit comments

Comments
 (0)