Home / File/ test_create_agent_tool_validation.py — langchain Source File

test_create_agent_tool_validation.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 10 imports 4 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  b0f528fd_b475_ca4c_5996_78af323abd67["test_create_agent_tool_validation.py"]
  d76a28c2_c3ab_00a8_5208_77807a49449d["sys"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> d76a28c2_c3ab_00a8_5208_77807a49449d
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> d758344f_537f_649e_f467_b9d7442e86df
  5f479767_1840_a044_ff97_91f66eefd6ec["langgraph.prebuilt"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> 5f479767_1840_a044_ff97_91f66eefd6ec
  8b8be3aa_f5da_ad38_c12d_3cc292ffab59["langgraph.store.base"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> 8b8be3aa_f5da_ad38_c12d_3cc292ffab59
  0ce19084_69d6_888b_8608_f4049087d337["langgraph.store.memory"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> 0ce19084_69d6_888b_8608_f4049087d337
  839143dd_e377_b604_96de_3624dbdffeb5["langchain.agents"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> 839143dd_e377_b604_96de_3624dbdffeb5
  e85266a5_b172_4ddd_2fa6_e91b38ae8c0e["langchain.tools"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> e85266a5_b172_4ddd_2fa6_e91b38ae8c0e
  d135b586_15fc_7b4a_47fb_a8b2bcda78a5["tests.unit_tests.agents.model"]
  b0f528fd_b475_ca4c_5996_78af323abd67 --> d135b586_15fc_7b4a_47fb_a8b2bcda78a5
  style b0f528fd_b475_ca4c_5996_78af323abd67 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import sys
from typing import Annotated, Any

import pytest
from langchain_core.messages import HumanMessage
from langgraph.prebuilt import InjectedStore, ToolRuntime
from langgraph.store.base import BaseStore
from langgraph.store.memory import InMemoryStore

from langchain.agents import AgentState, create_agent
from langchain.tools import InjectedState
from langchain.tools import tool as dec_tool
from tests.unit_tests.agents.model import FakeToolCallingModel


@pytest.mark.skipif(
    sys.version_info >= (3, 14), reason="Pydantic model rebuild issue in Python 3.14"
)
def test_tool_invocation_error_excludes_injected_state() -> None:
    """Test that tool invocation errors only include LLM-controllable arguments.

    When a tool has InjectedState parameters and the LLM makes an incorrect
    invocation (e.g., missing required arguments), the error message should only
    contain the arguments from the tool call that the LLM controls. This ensures
    the LLM receives relevant context to correct its mistakes, without being
    distracted by system-injected parameters it has no control over.
    This test uses create_agent to ensure the behavior works in a full agent context.
    """

    # Define a custom state schema with injected data
    class TestState(AgentState[Any]):
        secret_data: str  # Example of state data not controlled by LLM

    @dec_tool
    def tool_with_injected_state(
        some_val: int,
        state: Annotated[TestState, InjectedState],
    ) -> str:
        """Tool that uses injected state."""
        return f"some_val: {some_val}"

    # Create a fake model that makes an incorrect tool call (missing 'some_val')
    # Then returns no tool calls on the second iteration to end the loop
    model = FakeToolCallingModel(
        tool_calls=[
            [
                {
                    "name": "tool_with_injected_state",
                    "args": {"wrong_arg": "value"},  # Missing required 'some_val'
                    "id": "call_1",
                }
            ],
            [],  # No tool calls on second iteration to end the loop
        ]
    )

    # Create an agent with the tool and custom state schema
    agent = create_agent(
        model=model,
        tools=[tool_with_injected_state],
// ... (319 more lines)

Subdomains

Dependencies

  • langchain.agents
  • langchain.tools
  • langchain_core.messages
  • langgraph.prebuilt
  • langgraph.store.base
  • langgraph.store.memory
  • pytest
  • sys
  • tests.unit_tests.agents.model
  • typing

Frequently Asked Questions

What does test_create_agent_tool_validation.py do?
test_create_agent_tool_validation.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_create_agent_tool_validation.py?
test_create_agent_tool_validation.py defines 4 function(s): test_create_agent_error_content_with_multiple_params, test_create_agent_error_only_model_controllable_params, test_tool_invocation_error_excludes_injected_state, test_tool_invocation_error_excludes_injected_state_async.
What does test_create_agent_tool_validation.py depend on?
test_create_agent_tool_validation.py imports 10 module(s): langchain.agents, langchain.tools, langchain_core.messages, langgraph.prebuilt, langgraph.store.base, langgraph.store.memory, pytest, sys, and 2 more.
Where is test_create_agent_tool_validation.py in the architecture?
test_create_agent_tool_validation.py is located at libs/langchain_v1/tests/unit_tests/agents/test_create_agent_tool_validation.py (domain: CoreAbstractions, subdomain: RunnableInterface, 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