test_runnable_with_multi_action_per_step() — langchain Function Reference
Architecture documentation for the test_runnable_with_multi_action_per_step() function in test_agent.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 0c481a8b_27b4_f631_e56d_01312b0cce07["test_runnable_with_multi_action_per_step()"] 47a7b285_8e60_f78f_282d_429958c446fa["test_agent.py"] 0c481a8b_27b4_f631_e56d_01312b0cce07 -->|defined in| 47a7b285_8e60_f78f_282d_429958c446fa style 0c481a8b_27b4_f631_e56d_01312b0cce07 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/tests/unit_tests/agents/test_agent.py lines 642–787
async def test_runnable_with_multi_action_per_step() -> None:
"""Test an agent that can make multiple function calls at once."""
# Will alternate between responding with hello and goodbye
infinite_cycle = cycle(
[
AIMessage(content="looking for pet..."),
AIMessage(content="Found Pet"),
],
)
model = GenericFakeChatModel(messages=infinite_cycle)
template = ChatPromptTemplate.from_messages(
[
("system", "You are Cat Agent 007"),
("human", "{question}"),
],
)
parser_responses = cycle(
[
[
AgentAction(
tool="find_pet",
tool_input={
"pet": "cat",
},
log="find_pet()",
),
AgentAction(
tool="pet_pet", # A function that allows you to pet the given pet.
tool_input={
"pet": "cat",
},
log="pet_pet()",
),
],
AgentFinish(
return_values={"foo": "meow"},
log="hard-coded-message",
),
],
)
def fake_parse(_: dict) -> AgentFinish | AgentAction:
"""A parser."""
return cast("AgentFinish | AgentAction", next(parser_responses))
@tool
def find_pet(pet: str) -> str:
"""Find the given pet."""
if pet != "cat":
msg = "Only cats allowed"
raise ValueError(msg)
return "Spying from under the bed."
@tool
def pet_pet(pet: str) -> str:
"""Pet the given pet."""
if pet != "cat":
msg = "Only cats should be petted."
raise ValueError(msg)
return "purrrr"
agent = template | model | fake_parse
executor = AgentExecutor(agent=agent, tools=[find_pet])
# Invoke
result = await asyncio.to_thread(executor.invoke, {"question": "hello"})
assert result == {"foo": "meow", "question": "hello"}
# ainvoke
result = await executor.ainvoke({"question": "hello"})
assert result == {"foo": "meow", "question": "hello"}
# astream
results = [r async for r in executor.astream({"question": "hello"})]
assert results == [
{
"actions": [
AgentAction(
tool="find_pet",
Domain
Subdomains
Source
Frequently Asked Questions
What does test_runnable_with_multi_action_per_step() do?
test_runnable_with_multi_action_per_step() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/test_agent.py.
Where is test_runnable_with_multi_action_per_step() defined?
test_runnable_with_multi_action_per_step() is defined in libs/langchain/tests/unit_tests/agents/test_agent.py at line 642.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free