Home / File/ test_return_direct_graph.py — langchain Source File

test_return_direct_graph.py — langchain Source File

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

File python CoreAbstractions MessageSchema 4 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  870d1362_a433_dd06_dde4_6742345a9eee["test_return_direct_graph.py"]
  43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"]
  870d1362_a433_dd06_dde4_6742345a9eee --> 43d88577_548b_2248_b01b_7987bae85dcc
  66d6194f_d8c1_55b6_f522_311fdad57877["syrupy.assertion"]
  870d1362_a433_dd06_dde4_6742345a9eee --> 66d6194f_d8c1_55b6_f522_311fdad57877
  6f5e6c4b_1a3f_fd09_4697_631c27ef1033["langchain.agents.factory"]
  870d1362_a433_dd06_dde4_6742345a9eee --> 6f5e6c4b_1a3f_fd09_4697_631c27ef1033
  d135b586_15fc_7b4a_47fb_a8b2bcda78a5["tests.unit_tests.agents.model"]
  870d1362_a433_dd06_dde4_6742345a9eee --> d135b586_15fc_7b4a_47fb_a8b2bcda78a5
  style 870d1362_a433_dd06_dde4_6742345a9eee fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Tests for return_direct tool graph structure."""

from langchain_core.tools import tool
from syrupy.assertion import SnapshotAssertion

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


def test_agent_graph_without_return_direct_tools(snapshot: SnapshotAssertion) -> None:
    """Test that graph WITHOUT return_direct tools does NOT have edge from tools to end."""

    @tool
    def normal_tool(input_string: str) -> str:
        """A normal tool without return_direct."""
        return input_string

    agent = create_agent(
        model=FakeToolCallingModel(),
        tools=[normal_tool],
        system_prompt="You are a helpful assistant.",
    )

    # The mermaid diagram should NOT include an edge from tools to __end__
    # when no tools have return_direct=True
    mermaid_diagram = agent.get_graph().draw_mermaid()
    assert mermaid_diagram == snapshot


def test_agent_graph_with_return_direct_tool(snapshot: SnapshotAssertion) -> None:
    """Test that graph WITH return_direct tools has correct edge from tools to end."""

    @tool(return_direct=True)
    def return_direct_tool(input_string: str) -> str:
        """A tool with return_direct=True."""
        return input_string

    agent = create_agent(
        model=FakeToolCallingModel(),
        tools=[return_direct_tool],
        system_prompt="You are a helpful assistant.",
    )

    # The mermaid diagram SHOULD include an edge from tools to __end__
    # when at least one tool has return_direct=True
    mermaid_diagram = agent.get_graph().draw_mermaid()
    assert mermaid_diagram == snapshot


def test_agent_graph_with_mixed_tools(snapshot: SnapshotAssertion) -> None:
    """Test that graph with mixed tools (some return_direct, some not) has correct edges."""

    @tool(return_direct=True)
    def return_direct_tool(input_string: str) -> str:
        """A tool with return_direct=True."""
        return input_string

    @tool
    def normal_tool(input_string: str) -> str:
        """A normal tool without return_direct."""
        return input_string

    agent = create_agent(
        model=FakeToolCallingModel(),
        tools=[return_direct_tool, normal_tool],
        system_prompt="You are a helpful assistant.",
    )

    # The mermaid diagram SHOULD include an edge from tools to __end__
    # because at least one tool has return_direct=True
    mermaid_diagram = agent.get_graph().draw_mermaid()
    assert mermaid_diagram == snapshot

Subdomains

Dependencies

  • langchain.agents.factory
  • langchain_core.tools
  • syrupy.assertion
  • tests.unit_tests.agents.model

Frequently Asked Questions

What does test_return_direct_graph.py do?
test_return_direct_graph.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_return_direct_graph.py?
test_return_direct_graph.py defines 3 function(s): test_agent_graph_with_mixed_tools, test_agent_graph_with_return_direct_tool, test_agent_graph_without_return_direct_tools.
What does test_return_direct_graph.py depend on?
test_return_direct_graph.py imports 4 module(s): langchain.agents.factory, langchain_core.tools, syrupy.assertion, tests.unit_tests.agents.model.
Where is test_return_direct_graph.py in the architecture?
test_return_direct_graph.py is located at libs/langchain_v1/tests/unit_tests/agents/test_return_direct_graph.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