test_agent.py — langchain Source File
Architecture documentation for test_agent.py, a python file in the langchain codebase. 20 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 7be1d026_df75_9dc0_fa12_ce9b8bac0944["test_agent.py"] a327e534_84f6_5308_58ca_5727d5eda0cf["asyncio"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> a327e534_84f6_5308_58ca_5727d5eda0cf 7025b240_fdc3_cf68_b72f_f41dac94566b["json"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 7025b240_fdc3_cf68_b72f_f41dac94566b 7aaf52d4_ee88_411e_980e_bc4beeeb30ad["operator"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 7aaf52d4_ee88_411e_980e_bc4beeeb30ad c990f2d7_9509_7cea_ca95_51ad57dbe5c6["functools"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> c990f2d7_9509_7cea_ca95_51ad57dbe5c6 436f77bc_653d_0edb_555c_c2679d5a59ac["itertools"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 436f77bc_653d_0edb_555c_c2679d5a59ac 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b["langchain_core.agents"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b e8ec017e_6c91_4b34_675f_2a96c5aa9be6["langchain_core.callbacks.manager"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> e8ec017e_6c91_4b34_675f_2a96c5aa9be6 89934eed_a823_2184_acf2_039f48eed5f9["langchain_core.language_models.llms"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 89934eed_a823_2184_acf2_039f48eed5f9 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> d758344f_537f_649e_f467_b9d7442e86df e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> e6b4f61e_7b98_6666_3641_26b069517d4a 81c04601_d095_a27d_4af1_55e771bb2b6b["langchain_core.runnables.utils"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 81c04601_d095_a27d_4af1_55e771bb2b6b 43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 43d88577_548b_2248_b01b_7987bae85dcc 2b6e6b96_8f94_4170_1803_67a415a5e13a["langchain_core.tracers"] 7be1d026_df75_9dc0_fa12_ce9b8bac0944 --> 2b6e6b96_8f94_4170_1803_67a415a5e13a style 7be1d026_df75_9dc0_fa12_ce9b8bac0944 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Unit tests for agents."""
import asyncio
import json
import operator
from functools import reduce
from itertools import cycle
from typing import Any, cast
from langchain_core.agents import (
AgentAction,
AgentFinish,
AgentStep,
)
from langchain_core.callbacks.manager import CallbackManagerForLLMRun
from langchain_core.language_models.llms import LLM
from langchain_core.messages import (
AIMessage,
AIMessageChunk,
FunctionMessage,
HumanMessage,
ToolCall,
)
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables.utils import add
from langchain_core.tools import Tool, tool
from langchain_core.tracers import RunLog, RunLogPatch
from typing_extensions import override
from langchain_classic.agents import (
AgentExecutor,
AgentType,
create_openai_functions_agent,
create_openai_tools_agent,
create_tool_calling_agent,
initialize_agent,
)
from langchain_classic.agents.output_parsers.openai_tools import OpenAIToolAgentAction
from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler
from tests.unit_tests.llms.fake_chat_model import GenericFakeChatModel
from tests.unit_tests.stubs import (
_AnyIdAIMessageChunk,
)
class FakeListLLM(LLM):
"""Fake LLM for testing that outputs elements of a list."""
responses: list[str]
i: int = -1
@override
def _call(
self,
prompt: str,
stop: list[str] | None = None,
run_manager: CallbackManagerForLLMRun | None = None,
**kwargs: Any,
) -> str:
"""Increment counter, and then return response in that index."""
// ... (1270 more lines)
Domain
Subdomains
Functions
- _get_agent()
- _make_func_invocation()
- _make_tools_invocation()
- _recursive_dump()
- test_agent_bad_action()
- test_agent_invalid_tool()
- test_agent_lookup_tool()
- test_agent_stopped_early()
- test_agent_stream()
- test_agent_tool_return_direct()
- test_agent_tool_return_direct_in_intermediate_steps()
- test_agent_with_callbacks()
- test_agent_with_new_prefix_suffix()
- test_openai_agent_tools_agent()
- test_openai_agent_with_streaming()
- test_runnable_agent()
- test_runnable_agent_with_function_calls()
- test_runnable_with_multi_action_per_step()
Classes
Dependencies
- asyncio
- functools
- itertools
- json
- langchain_classic.agents
- langchain_classic.agents.output_parsers.openai_tools
- langchain_core.agents
- langchain_core.callbacks.manager
- langchain_core.language_models.llms
- langchain_core.messages
- langchain_core.prompts
- langchain_core.runnables.utils
- langchain_core.tools
- langchain_core.tracers
- operator
- tests.unit_tests.callbacks.fake_callback_handler
- tests.unit_tests.llms.fake_chat_model
- tests.unit_tests.stubs
- typing
- typing_extensions
Source
Frequently Asked Questions
What does test_agent.py do?
test_agent.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in test_agent.py?
test_agent.py defines 18 function(s): _get_agent, _make_func_invocation, _make_tools_invocation, _recursive_dump, test_agent_bad_action, test_agent_invalid_tool, test_agent_lookup_tool, test_agent_stopped_early, test_agent_stream, test_agent_tool_return_direct, and 8 more.
What does test_agent.py depend on?
test_agent.py imports 20 module(s): asyncio, functools, itertools, json, langchain_classic.agents, langchain_classic.agents.output_parsers.openai_tools, langchain_core.agents, langchain_core.callbacks.manager, and 12 more.
Where is test_agent.py in the architecture?
test_agent.py is located at libs/langchain/tests/unit_tests/agents/test_agent.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/tests/unit_tests/agents).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free