test_agent_iterator_with_callbacks() — langchain Function Reference
Architecture documentation for the test_agent_iterator_with_callbacks() function in test_agent_iterator.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d60c26f3_6884_9532_467b_6ad52ff2d641["test_agent_iterator_with_callbacks()"] 2423e003_42f4_7c6a_3fba_30db54c07a0c["test_agent_iterator.py"] d60c26f3_6884_9532_467b_6ad52ff2d641 -->|defined in| 2423e003_42f4_7c6a_3fba_30db54c07a0c style d60c26f3_6884_9532_467b_6ad52ff2d641 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/tests/unit_tests/agents/test_agent_iterator.py lines 93–156
def test_agent_iterator_with_callbacks() -> None:
"""Test react chain iterator with callbacks by setting verbose globally."""
handler1 = FakeCallbackHandler()
handler2 = FakeCallbackHandler()
bad_action_name = "BadAction"
responses = [
f"I'm turning evil\nAction: {bad_action_name}\nAction Input: misalignment",
"Oh well\nFinal Answer: curses foiled again",
]
fake_llm = FakeListLLM(cache=False, responses=responses, callbacks=[handler2])
tools = [
Tool(
name="Search",
func=lambda x: x,
description="Useful for searching",
),
Tool(
name="Lookup",
func=lambda x: x,
description="Useful for looking up things in a table",
),
]
agent = initialize_agent(
tools,
fake_llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
)
agent_iter = agent.iter(
inputs="when was langchain made",
callbacks=[handler1],
include_run_info=True,
)
outputs = list(agent_iter)
assert isinstance(outputs[-1], dict)
assert outputs[-1]["output"] == "curses foiled again"
assert isinstance(outputs[-1][RUN_KEY].run_id, UUID)
# 1 top level chain run runs, 2 LLMChain runs, 2 LLM runs, 1 tool run
assert handler1.chain_starts == handler1.chain_ends == 3
assert handler1.llm_starts == handler1.llm_ends == 2
assert handler1.tool_starts == 1
assert handler1.tool_ends == 1
# 1 extra agent action
assert handler1.starts == 7
# 1 extra agent end
assert handler1.ends == 7
print("h:", handler1) # noqa: T201
assert handler1.errors == 0
# during LLMChain
assert handler1.text == 2
assert handler2.llm_starts == 2
assert handler2.llm_ends == 2
assert (
handler2.chain_starts
== handler2.tool_starts
== handler2.tool_ends
== handler2.chain_ends
== 0
)
Domain
Subdomains
Source
Frequently Asked Questions
What does test_agent_iterator_with_callbacks() do?
test_agent_iterator_with_callbacks() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/test_agent_iterator.py.
Where is test_agent_iterator_with_callbacks() defined?
test_agent_iterator_with_callbacks() is defined in libs/langchain/tests/unit_tests/agents/test_agent_iterator.py at line 93.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free