add return_direct flag to tool (#537)

adds a return_direct flag to tools, which just returns the tool output
as the final output
This commit is contained in:
Harrison Chase
2023-01-06 06:40:32 -08:00
committed by GitHub
parent 1f248c47f3
commit 4974f49bb7
4 changed files with 126 additions and 24 deletions

View File

@@ -169,3 +169,24 @@ def test_agent_with_callbacks_not_verbose() -> None:
assert handler.starts == 0
assert handler.ends == 0
assert handler.errors == 0
def test_agent_tool_return_direct() -> 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("Search", lambda x: x, "Useful for searching", return_direct=True),
]
agent = initialize_agent(
tools,
fake_llm,
agent="zero-shot-react-description",
)
output = agent.run("when was langchain made")
assert output == "misalignment"