Adding tool caching a loop execution prevention. (#25)

* Adding tool caching a loop execution prevention.

This adds some guardrails, to both prevent the same tool to be used
consecutively and also caching tool's results across the entire crew
so it cuts down execution time and eventual LLM calls.

This plays a huge role for smaller opensource models that usually fall
into those behaviors patterns.

It also includes some smaller improvements around the tool prompt and
agent tools, all with the same intention of guiding models into
better conform with agent instructions.
This commit is contained in:
João Moura
2023-12-29 22:35:23 -03:00
committed by GitHub
parent 5cc230263c
commit af9e749edb
14 changed files with 3046 additions and 54 deletions

View File

@@ -16,7 +16,7 @@ class AgentTools(BaseModel):
return [
Tool.from_function(
func=self.delegate_work,
name="Delegate Work to Co-Worker",
name="Delegate work to co-worker",
description=dedent(
f"""Useful to delegate a specific task to one of the
following co-workers: [{', '.join([agent.role for agent in self.agents])}].
@@ -28,7 +28,7 @@ class AgentTools(BaseModel):
),
Tool.from_function(
func=self.ask_question,
name="Ask Question to Co-Worker",
name="Ask question to co-worker",
description=dedent(
f"""Useful to ask a question, opinion or take from on
of the following co-workers: [{', '.join([agent.role for agent in self.agents])}].
@@ -53,10 +53,10 @@ class AgentTools(BaseModel):
try:
agent, task, information = command.split("|")
except ValueError:
return "Error executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|information`."
return "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|task|information`."
if not agent or not task or not information:
return "Error executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|question|information`."
return "\nError executing tool. Missing exact 3 pipe (|) separated values. For example, `coworker|question|information`."
agent = [
available_agent
@@ -65,9 +65,7 @@ class AgentTools(BaseModel):
]
if len(agent) == 0:
return (
"Error executing tool. Co-worker not found, double check the co-worker."
)
return f"\nError executing tool. Co-worker mentioned on the Action Input not found, it must to be one of the following options: {', '.join([agent.role for agent in self.agents])}."
agent = agent[0]
result = agent.execute_task(task, information)