Home / Function/ test_create_agent_invoke() — langchain Function Reference

test_create_agent_invoke() — langchain Function Reference

Architecture documentation for the test_create_agent_invoke() function in test_framework.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6e11109d_74e3_2b16_91b1_82e90d0e2d6c["test_create_agent_invoke()"]
  8310d669_2524_e019_e333_8473b50a4990["test_framework.py"]
  6e11109d_74e3_2b16_91b1_82e90d0e2d6c -->|defined in| 8310d669_2524_e019_e333_8473b50a4990
  83f90d06_bd5d_f90c_8a51_2e1292bd1cfc["after_model()"]
  6e11109d_74e3_2b16_91b1_82e90d0e2d6c -->|calls| 83f90d06_bd5d_f90c_8a51_2e1292bd1cfc
  style 6e11109d_74e3_2b16_91b1_82e90d0e2d6c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py lines 39–137

def test_create_agent_invoke(
    snapshot: SnapshotAssertion,
    sync_checkpointer: BaseCheckpointSaver[str],
) -> None:
    calls = []

    class NoopSeven(AgentMiddleware):
        def before_model(self, state: AgentState[Any], runtime: Runtime) -> None:
            calls.append("NoopSeven.before_model")

        def wrap_model_call(
            self,
            request: ModelRequest,
            handler: Callable[[ModelRequest], ModelResponse],
        ) -> ModelCallResult:
            calls.append("NoopSeven.wrap_model_call")
            return handler(request)

        def after_model(self, state: AgentState[Any], runtime: Runtime) -> None:
            calls.append("NoopSeven.after_model")

    class NoopEight(AgentMiddleware):
        def before_model(self, state: AgentState[Any], runtime: Runtime) -> None:
            calls.append("NoopEight.before_model")

        def wrap_model_call(
            self,
            request: ModelRequest,
            handler: Callable[[ModelRequest], ModelResponse],
        ) -> ModelCallResult:
            calls.append("NoopEight.wrap_model_call")
            return handler(request)

        def after_model(self, state: AgentState[Any], runtime: Runtime) -> None:
            calls.append("NoopEight.after_model")

    @tool
    def my_tool(value: str) -> str:
        """A great tool."""
        calls.append("my_tool")
        return value.upper()

    agent_one = create_agent(
        model=FakeToolCallingModel(
            tool_calls=[
                [
                    {"args": {"value": "yo"}, "id": "1", "name": "my_tool"},
                ],
                [],
            ]
        ),
        tools=[my_tool],
        system_prompt="You are a helpful assistant.",
        middleware=[NoopSeven(), NoopEight()],
        checkpointer=sync_checkpointer,
    )

    thread1 = {"configurable": {"thread_id": "1"}}
    assert agent_one.invoke({"messages": ["hello"]}, thread1) == {
        "messages": [
            _AnyIdHumanMessage(content="hello"),
            AIMessage(
                content="You are a helpful assistant.-hello",
                additional_kwargs={},
                response_metadata={},
                id="0",
                tool_calls=[
                    {
                        "name": "my_tool",
                        "args": {"value": "yo"},
                        "id": "1",
                        "type": "tool_call",
                    }
                ],
            ),
            _AnyIdToolMessage(content="YO", name="my_tool", tool_call_id="1"),
            AIMessage(
                content="You are a helpful assistant.-hello-You are a helpful assistant.-hello-YO",
                additional_kwargs={},
                response_metadata={},
                id="1",

Domain

Subdomains

Frequently Asked Questions

What does test_create_agent_invoke() do?
test_create_agent_invoke() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py.
Where is test_create_agent_invoke() defined?
test_create_agent_invoke() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py at line 39.
What does test_create_agent_invoke() call?
test_create_agent_invoke() calls 1 function(s): after_model.

Analyze Your Own Codebase

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

Try Supermodel Free