Add support to delegate work

This commit is contained in:
Joao Moura
2023-11-10 18:15:45 -03:00
parent d6989b7959
commit 6ff18128a7
15 changed files with 1786 additions and 1636 deletions

View File

@@ -18,7 +18,7 @@ def test_agent_creation():
assert agent.backstory == "test backstory"
assert agent.tools == []
def test_agent_default_value():
def test_agent_default_values():
agent = Agent(
role="test role",
goal="test goal",
@@ -29,6 +29,7 @@ def test_agent_default_value():
assert agent.llm.model_name == "gpt-4"
assert agent.llm.temperature == 0.7
assert agent.llm.verbose == False
assert agent.allow_delegation == True
def test_custom_llm():
agent = Agent(
@@ -50,11 +51,12 @@ def test_agent_execution():
agent = Agent(
role="test role",
goal="test goal",
backstory="test backstory"
backstory="test backstory",
allow_delegation=False
)
output = agent.execute_task("How much is 1 + 1?")
assert output == "1 + 1 equals 2."
assert output == "1 + 1 = 2"
@pytest.mark.vcr()
def test_agent_execution_with_tools():
@@ -73,8 +75,35 @@ def test_agent_execution_with_tools():
role="test role",
goal="test goal",
backstory="test backstory",
tools=[multiplier]
tools=[multiplier],
allow_delegation=False
)
output = agent.execute_task("What is 3 times 4")
assert output == "3 times 4 is 12."
assert output == "3 times 4 is 12"
@pytest.mark.vcr()
def test_agent_execution_with_specific_tools():
from langchain.tools import tool
@tool
def multiplier(numbers) -> float:
"""Useful for when you need to multiply two numbers together.
The input to this tool should be a comma separated list of numbers of
length two, representing the two numbers you want to multiply together.
For example, `1,2` would be the input if you wanted to multiply 1 by 2."""
a, b = numbers.split(',')
return int(a) * int(b)
agent = Agent(
role="test role",
goal="test goal",
backstory="test backstory",
allow_delegation=False
)
output = agent.execute_task(
task="What is 3 times 4",
tools=[multiplier]
)
assert output == "12"