Home / File/ test_injected_runtime_create_agent.py — langchain Source File

test_injected_runtime_create_agent.py — langchain Source File

Architecture documentation for test_injected_runtime_create_agent.py, a python file in the langchain codebase. 10 imports, 0 dependents.

File python LangChainCore Runnables 10 imports 16 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  a4d83fe9_0a39_5761_b1a5_de54f81974c9["test_injected_runtime_create_agent.py"]
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> feec1ec4_6917_867b_d228_b134d0ff8099
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  121262a1_0bd6_d637_bce3_307ab6b3ecd4["langchain_core.tools"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> 121262a1_0bd6_d637_bce3_307ab6b3ecd4
  3d8bc858_08d9_4750_c1de_fad2b835a63a["langgraph.prebuilt"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> 3d8bc858_08d9_4750_c1de_fad2b835a63a
  2b1e8314_8ce2_fe87_d59e_484fdb8ff4cb["langgraph.store.memory"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> 2b1e8314_8ce2_fe87_d59e_484fdb8ff4cb
  d9a6942a_c37a_07f8_ed13_74d0fdc117be["langchain.agents"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> d9a6942a_c37a_07f8_ed13_74d0fdc117be
  a681398d_ed44_c914_1a44_5d174223b069["langchain.agents.middleware.types"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> a681398d_ed44_c914_1a44_5d174223b069
  b036e189_bfab_a345_61aa_93be8b3e73bc["langchain.tools"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> b036e189_bfab_a345_61aa_93be8b3e73bc
  069947d2_727b_035a_0691_c12203e2f5a6["tests.unit_tests.agents.model"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> 069947d2_727b_035a_0691_c12203e2f5a6
  e07f6d54_afcc_052d_d33f_8ccdcc46f752["langgraph.runtime"]
  a4d83fe9_0a39_5761_b1a5_de54f81974c9 --> e07f6d54_afcc_052d_d33f_8ccdcc46f752
  style a4d83fe9_0a39_5761_b1a5_de54f81974c9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test ToolRuntime injection with create_agent.

This module tests the injected runtime functionality when using tools
with the create_agent factory. The ToolRuntime provides tools access to:
- state: Current graph state
- tool_call_id: ID of the current tool call
- config: RunnableConfig for the execution
- context: Runtime context from LangGraph
- store: BaseStore for persistent storage
- stream_writer: For streaming custom output

These tests verify that runtime injection works correctly across both
sync and async execution paths, with middleware, and in various agent
configurations.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Annotated, Any

from langchain_core.messages import HumanMessage, ToolMessage
from langchain_core.tools import tool
from langgraph.prebuilt import InjectedStore
from langgraph.store.memory import InMemoryStore

from langchain.agents import create_agent
from langchain.agents.middleware.types import AgentMiddleware, AgentState
from langchain.tools import InjectedState, ToolRuntime
from tests.unit_tests.agents.model import FakeToolCallingModel

if TYPE_CHECKING:
    from langgraph.runtime import Runtime


def test_tool_runtime_basic_injection() -> None:
    """Test basic ToolRuntime injection in tools with create_agent."""
    # Track what was injected
    injected_data: dict[str, Any] = {}

    @tool
    def runtime_tool(x: int, runtime: ToolRuntime) -> str:
        """Tool that accesses runtime context."""
        injected_data["state"] = runtime.state
        injected_data["tool_call_id"] = runtime.tool_call_id
        injected_data["config"] = runtime.config
        injected_data["context"] = runtime.context
        injected_data["store"] = runtime.store
        injected_data["stream_writer"] = runtime.stream_writer
        return f"Processed {x}"

    assert runtime_tool.args

    agent = create_agent(
        model=FakeToolCallingModel(
            tool_calls=[
                [{"args": {"x": 42}, "id": "call_123", "name": "runtime_tool"}],
                [],
            ]
        ),
        tools=[runtime_tool],
// ... (771 more lines)

Domain

Subdomains

Dependencies

  • langchain.agents
  • langchain.agents.middleware.types
  • langchain.tools
  • langchain_core.messages
  • langchain_core.tools
  • langgraph.prebuilt
  • langgraph.runtime
  • langgraph.store.memory
  • tests.unit_tests.agents.model
  • typing

Frequently Asked Questions

What does test_injected_runtime_create_agent.py do?
test_injected_runtime_create_agent.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_injected_runtime_create_agent.py?
test_injected_runtime_create_agent.py defines 16 function(s): langgraph, test_combined_injected_state_runtime_store, test_combined_injected_state_runtime_store_async, test_tool_runtime_async_injection, test_tool_runtime_basic_injection, test_tool_runtime_config_access, test_tool_runtime_error_handling, test_tool_runtime_name_based_injection, test_tool_runtime_no_runtime_parameter, test_tool_runtime_parallel_execution, and 6 more.
What does test_injected_runtime_create_agent.py depend on?
test_injected_runtime_create_agent.py imports 10 module(s): langchain.agents, langchain.agents.middleware.types, langchain.tools, langchain_core.messages, langchain_core.tools, langgraph.prebuilt, langgraph.runtime, langgraph.store.memory, and 2 more.
Where is test_injected_runtime_create_agent.py in the architecture?
test_injected_runtime_create_agent.py is located at libs/langchain_v1/tests/unit_tests/agents/test_injected_runtime_create_agent.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain_v1/tests/unit_tests/agents).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free