Home / File/ test_agent_name.py — langchain Source File

test_agent_name.py — langchain Source File

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

File python CoreAbstractions MessageSchema 4 imports 12 functions

Entity Profile

Dependency Diagram

graph LR
  3b01fc8e_2056_a3a7_49a0_cfccb7e7212b["test_agent_name.py"]
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  3b01fc8e_2056_a3a7_49a0_cfccb7e7212b --> d758344f_537f_649e_f467_b9d7442e86df
  43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"]
  3b01fc8e_2056_a3a7_49a0_cfccb7e7212b --> 43d88577_548b_2248_b01b_7987bae85dcc
  839143dd_e377_b604_96de_3624dbdffeb5["langchain.agents"]
  3b01fc8e_2056_a3a7_49a0_cfccb7e7212b --> 839143dd_e377_b604_96de_3624dbdffeb5
  d135b586_15fc_7b4a_47fb_a8b2bcda78a5["tests.unit_tests.agents.model"]
  3b01fc8e_2056_a3a7_49a0_cfccb7e7212b --> d135b586_15fc_7b4a_47fb_a8b2bcda78a5
  style 3b01fc8e_2056_a3a7_49a0_cfccb7e7212b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test agent name parameter in create_agent.

This module tests that the name parameter correctly sets .name on AIMessage outputs.
"""

from __future__ import annotations

from langchain_core.messages import (
    AIMessage,
    HumanMessage,
    ToolCall,
)
from langchain_core.tools import tool

from langchain.agents import create_agent
from tests.unit_tests.agents.model import FakeToolCallingModel


@tool
def simple_tool(x: int) -> str:
    """Simple tool for basic tests."""
    return f"Result: {x}"


def test_agent_name_set_on_ai_message() -> None:
    """Test that agent name is set on AIMessage when name is provided."""
    tool_calls: list[list[ToolCall]] = [[]]
    agent = create_agent(
        model=FakeToolCallingModel(tool_calls=tool_calls),
        name="test_agent",
    )

    result = agent.invoke({"messages": [HumanMessage("Hello")]})

    ai_messages = [m for m in result["messages"] if isinstance(m, AIMessage)]
    assert len(ai_messages) == 1
    assert ai_messages[0].name == "test_agent"


def test_agent_name_not_set_when_none() -> None:
    """Test that AIMessage.name is not set when name is not provided."""
    tool_calls: list[list[ToolCall]] = [[]]
    agent = create_agent(
        model=FakeToolCallingModel(tool_calls=tool_calls),
    )

    result = agent.invoke({"messages": [HumanMessage("Hello")]})

    ai_messages = [m for m in result["messages"] if isinstance(m, AIMessage)]
    assert len(ai_messages) == 1
    assert ai_messages[0].name is None


def test_agent_name_on_multiple_iterations() -> None:
    """Test that agent name is set on all AIMessages in multi-turn conversation."""
    agent = create_agent(
        model=FakeToolCallingModel(
            tool_calls=[[{"args": {"x": 1}, "id": "call_1", "name": "simple_tool"}], []]
        ),
        tools=[simple_tool],
// ... (160 more lines)

Subdomains

Dependencies

  • langchain.agents
  • langchain_core.messages
  • langchain_core.tools
  • tests.unit_tests.agents.model

Frequently Asked Questions

What does test_agent_name.py do?
test_agent_name.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_agent_name.py?
test_agent_name.py defines 12 function(s): simple_tool, test_agent_name_async, test_agent_name_async_multiple_iterations, test_agent_name_not_set_when_none, test_agent_name_on_multiple_iterations, test_agent_name_set_on_ai_message, test_lc_agent_name_in_astream_metadata, test_lc_agent_name_in_astream_metadata_multiple_iterations, test_lc_agent_name_in_stream_metadata, test_lc_agent_name_in_stream_metadata_multiple_iterations, and 2 more.
What does test_agent_name.py depend on?
test_agent_name.py imports 4 module(s): langchain.agents, langchain_core.messages, langchain_core.tools, tests.unit_tests.agents.model.
Where is test_agent_name.py in the architecture?
test_agent_name.py is located at libs/langchain_v1/tests/unit_tests/agents/test_agent_name.py (domain: CoreAbstractions, subdomain: MessageSchema, 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