# InjectedState

> **Class** in `langgraph.prebuilt`

📖 [View in docs](https://reference.langchain.com/python/langgraph.prebuilt/tool_node/InjectedState)

Annotation for injecting graph state into tool arguments.

This annotation enables tools to access graph state without exposing state
management details to the language model. Tools annotated with `InjectedState`
receive state data automatically during execution while remaining invisible
to the model's tool-calling interface.

## Signature

```python
InjectedState(
    self,
    field: str | None = None,
)
```

## Description

**Example:**

```python
from typing import List
from typing_extensions import Annotated, TypedDict

from langchain_core.messages import BaseMessage, AIMessage
from langchain.tools import InjectedState, ToolNode, tool

class AgentState(TypedDict):
    messages: List[BaseMessage]
    foo: str

@tool
def state_tool(x: int, state: Annotated[dict, InjectedState]) -> str:
    '''Do something with state.'''
    if len(state["messages"]) > 2:
        return state["foo"] + str(x)
    else:
        return "not enough messages"

@tool
def foo_tool(x: int, foo: Annotated[str, InjectedState("foo")]) -> str:
    '''Do something else with state.'''
    return foo + str(x + 1)

node = ToolNode([state_tool, foo_tool])

tool_call1 = {"name": "state_tool", "args": {"x": 1}, "id": "1", "type": "tool_call"}
tool_call2 = {"name": "foo_tool", "args": {"x": 1}, "id": "2", "type": "tool_call"}
state = {
    "messages": [AIMessage("", tool_calls=[tool_call1, tool_call2])],
    "foo": "bar",
}
node.invoke(state)
```

```python
[
    ToolMessage(content="not enough messages", name="state_tool", tool_call_id="1"),
    ToolMessage(content="bar2", name="foo_tool", tool_call_id="2"),
]
```

!!! note
- `InjectedState` arguments are automatically excluded from tool schemas
    presented to language models
- `ToolNode` handles the injection process during execution
- Tools can mix regular arguments (controlled by the model) with injected
    arguments (controlled by the system)
- State injection occurs after the model generates tool calls but before
    tool execution

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `field` | `str \| None` | No | Optional key to extract from the state dictionary. If `None`, the entire state is injected. If specified, only that field's value is injected. This allows tools to request specific state components rather than processing the full state structure. (default: `None`) |

## Extends

- `InjectedToolArg`

## Constructors

```python
__init__(
    self,
    field: str | None = None,
) -> None
```

| Name | Type |
|------|------|
| `field` | `str \| None` |


## Properties

- `field`

---

[View source on GitHub](https://github.com/langchain-ai/langgraph/blob/398d6cc59d4cf81ab23c09f037e9f521c3fedcd6/libs/prebuilt/langgraph/prebuilt/tool_node.py#L1753)