test_tool_runtime_state_access() — langchain Function Reference
Architecture documentation for the test_tool_runtime_state_access() function in test_injected_runtime_create_agent.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 32979957_2edb_74e2_580f_a6fc0d9a04e7["test_tool_runtime_state_access()"] a4d83fe9_0a39_5761_b1a5_de54f81974c9["test_injected_runtime_create_agent.py"] 32979957_2edb_74e2_580f_a6fc0d9a04e7 -->|defined in| a4d83fe9_0a39_5761_b1a5_de54f81974c9 style 32979957_2edb_74e2_580f_a6fc0d9a04e7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py lines 123–150
def test_tool_runtime_state_access() -> None:
"""Test that tools can access and use state via ToolRuntime."""
@tool
def state_aware_tool(query: str, runtime: ToolRuntime) -> str:
"""Tool that uses state to provide context-aware responses."""
messages = runtime.state.get("messages", [])
msg_count = len(messages)
return f"Query: {query}, Message count: {msg_count}"
agent = create_agent(
model=FakeToolCallingModel(
tool_calls=[
[{"args": {"query": "test"}, "id": "state_call", "name": "state_aware_tool"}],
[],
]
),
tools=[state_aware_tool],
system_prompt="You are a helpful assistant.",
)
result = agent.invoke({"messages": [HumanMessage("Hello"), HumanMessage("World")]})
# Check that tool accessed state correctly
tool_message = result["messages"][3]
assert isinstance(tool_message, ToolMessage)
# Should have original 2 HumanMessages + 1 AIMessage before tool execution
assert "Message count: 3" in tool_message.content
Domain
Subdomains
Source
Frequently Asked Questions
What does test_tool_runtime_state_access() do?
test_tool_runtime_state_access() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py.
Where is test_tool_runtime_state_access() defined?
test_tool_runtime_state_access() is defined in libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py at line 123.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free