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
50 changes: 50 additions & 0 deletions src/oss/langchain/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,56 @@ The following parameter names are reserved and cannot be used as tool arguments.
To access runtime information, use the @[`ToolRuntime`] parameter instead of naming your own arguments `config` or `runtime`.
:::

### Migration: Older Injection Patterns → `ToolRuntime`

Many earlier LangChain examples used multiple injection helpers such as
`InjectedState`, `InjectedStore`, `get_runtime()`, or `InjectedToolCallId`.
These patterns have now been unified under the `ToolRuntime` API.

`ToolRuntime` provides a single interface for accessing:

- Execution state
- Context data
- Long-term memory (store)
- Streaming callbacks
- Execution config
- Tool call metadatakv

This simplifies tool development and makes tools easier to test.

#### Before (deprecated)

```python
from langchain.tools import tool, InjectedState

@tool
def summarize(state: InjectedState) -> str:
"""Summarize the conversation."""
messages = state["messages"]
return f"Conversation length: {len(messages)} messages."
```

#### After (recommended)

```python
from langchain.tools import tool, ToolRuntime

@tool
def summarize(runtime: ToolRuntime) -> str:
"""Summarize the conversation."""
messages = runtime.state["messages"]
return f"Conversation length: {len(messages)} messages."
```

#### Why migrate?

- Unifies several older injection patterns
- Makes tool behavior more explicit and predictable
- Improves testability
- Aligns with LangGraph state and context patterns
- Avoids hidden implicit global state


## Accessing Context

<Info>
Expand Down