Harrison/return intermediate (#1633)

Co-authored-by: Mario Kostelac <mario@intercom.io>
This commit is contained in:
Harrison Chase
2023-03-13 07:54:29 -07:00
committed by GitHub
parent 72b461e257
commit aed9f9febe
2 changed files with 54 additions and 7 deletions

View File

@@ -230,6 +230,36 @@ def test_agent_tool_return_direct() -> None:
assert output == "misalignment"
def test_agent_tool_return_direct_in_intermediate_steps() -> None:
"""Test agent using tools that return directly."""
tool = "Search"
responses = [
f"FooBarBaz\nAction: {tool}\nAction Input: misalignment",
"Oh well\nAction: Final Answer\nAction Input: curses foiled again",
]
fake_llm = FakeListLLM(responses=responses)
tools = [
Tool(
name="Search",
func=lambda x: x,
description="Useful for searching",
return_direct=True,
),
]
agent = initialize_agent(
tools,
fake_llm,
agent="zero-shot-react-description",
return_intermediate_steps=True,
)
resp = agent("when was langchain made")
assert resp["output"] == "misalignment"
assert len(resp["intermediate_steps"]) == 1
action, _action_intput = resp["intermediate_steps"][0]
assert action.tool == "Search"
def test_agent_with_new_prefix_suffix() -> None:
"""Test agent initilization kwargs with new prefix and suffix."""
fake_llm = FakeListLLM(