You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/oss/langchain/tools.mdx
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,6 +146,7 @@ Define complex inputs with Pydantic models or JSON schemas:
146
146
**Why this matters:** Tools are most powerful when they can access agent state, runtime context, and long-term memory. This enables tools to make context-aware decisions, personalize responses, and maintain information across conversations.
147
147
</Info>
148
148
149
+
:::python
149
150
Tools can access runtime information through the `ToolRuntime` parameter, which provides:
150
151
151
152
-**State** - Mutable data that flows through execution (messages, counters, custom fields)
@@ -163,7 +164,6 @@ Use `ToolRuntime` to access all runtime information in a single parameter. Simpl
163
164
**`ToolRuntime`**: A unified parameter that provides tools access to state, context, store, streaming, config, and tool call ID. This replaces the older pattern of using separate @[`InjectedState`], @[`InjectedStore`], @[`get_runtime`], and @[`InjectedToolCallId`] annotations.
164
165
</Info>
165
166
166
-
:::python
167
167
**Accessing state:**
168
168
169
169
Tools can access the current graph state using `ToolRuntime`:
@@ -234,9 +234,9 @@ def update_user_name(
234
234
235
235
#### Context
236
236
237
+
:::python
237
238
Access immutable configuration and contextual data like user IDs, session details, or application-specific configuration through `runtime.context`.
238
239
239
-
:::python
240
240
Tools can access runtime context through `ToolRuntime`:
241
241
242
242
```python wrap
@@ -332,9 +332,9 @@ const result = await agent.invoke(
332
332
333
333
#### Memory (Store)
334
334
335
+
:::python
335
336
Access persistent data across conversations using the store. The store is accessed via `runtime.store` and allows you to save and retrieve user-specific or application-specific data.
336
337
337
-
:::python
338
338
Tools can access and update the store through `ToolRuntime`:
339
339
340
340
```python wrap expandable
@@ -384,6 +384,8 @@ agent.invoke({
384
384
:::
385
385
386
386
:::js
387
+
Access persistent data across conversations using the store. The store is accessed via `config.store` and allows you to save and retrieve user-specific or application-specific data.
388
+
387
389
```ts wrap expandable
388
390
import*aszfrom"zod";
389
391
import { createAgent, tool } from"langchain";
@@ -460,9 +462,9 @@ console.log(result);
460
462
461
463
#### Stream Writer
462
464
465
+
:::python
463
466
Stream custom updates from tools as they execute using `runtime.stream_writer`. This is useful for providing real-time feedback to users about what a tool is doing.
464
467
465
-
:::python
466
468
```python wrap
467
469
from langchain.tools import tool, ToolRuntime
468
470
@@ -484,6 +486,8 @@ If you use `runtime.stream_writer` inside your tool, the tool must be invoked wi
484
486
:::
485
487
486
488
:::js
489
+
Stream custom updates from tools as they execute using `config.streamWriter`. This is useful for providing real-time feedback to users about what a tool is doing.
0 commit comments