test_agent_stream() — langchain Function Reference
Architecture documentation for the test_agent_stream() function in test_agent_async.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 53aed176_7fe7_59d7_f62b_b19f49eacee1["test_agent_stream()"] 663245d2_2254_328f_5cf8_4bbd36fb32cc["test_agent_async.py"] 53aed176_7fe7_59d7_f62b_b19f49eacee1 -->|defined in| 663245d2_2254_328f_5cf8_4bbd36fb32cc style 53aed176_7fe7_59d7_f62b_b19f49eacee1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/tests/unit_tests/agents/test_agent_async.py lines 157–284
async def test_agent_stream() -> None:
"""Test react chain with callbacks by setting verbose globally."""
tool = "Search"
responses = [
f"FooBarBaz\nAction: {tool}\nAction Input: misalignment",
f"FooBarBaz\nAction: {tool}\nAction Input: something else",
"Oh well\nFinal Answer: curses foiled again",
]
# Only fake LLM gets callbacks for handler2
fake_llm = FakeListLLM(responses=responses)
tools = [
Tool(
name="Search",
func=lambda x: f"Results for: {x}",
description="Useful for searching",
),
]
agent = initialize_agent(
tools,
fake_llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
output = [a async for a in agent.astream("when was langchain made")]
assert output == [
{
"actions": [
AgentAction(
tool="Search",
tool_input="misalignment",
log="FooBarBaz\nAction: Search\nAction Input: misalignment",
),
],
"messages": [
AIMessage(
content="FooBarBaz\nAction: Search\nAction Input: misalignment",
),
],
},
{
"steps": [
AgentStep(
action=AgentAction(
tool="Search",
tool_input="misalignment",
log="FooBarBaz\nAction: Search\nAction Input: misalignment",
),
observation="Results for: misalignment",
),
],
"messages": [HumanMessage(content="Results for: misalignment")],
},
{
"actions": [
AgentAction(
tool="Search",
tool_input="something else",
log="FooBarBaz\nAction: Search\nAction Input: something else",
),
],
"messages": [
AIMessage(
content="FooBarBaz\nAction: Search\nAction Input: something else",
),
],
},
{
"steps": [
AgentStep(
action=AgentAction(
tool="Search",
tool_input="something else",
log="FooBarBaz\nAction: Search\nAction Input: something else",
),
observation="Results for: something else",
),
],
"messages": [HumanMessage(content="Results for: something else")],
},
{
"output": "curses foiled again",
Domain
Subdomains
Source
Frequently Asked Questions
What does test_agent_stream() do?
test_agent_stream() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/test_agent_async.py.
Where is test_agent_stream() defined?
test_agent_stream() is defined in libs/langchain/tests/unit_tests/agents/test_agent_async.py at line 157.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free