From 29d91513d594d296c7463a789a4a10fb7539e577 Mon Sep 17 00:00:00 2001 From: Joao Moura Date: Sun, 5 Nov 2023 14:19:32 -0300 Subject: [PATCH] updating agent --- crewai/agent.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/crewai/agent.py b/crewai/agent.py index 19d7bdbdf..aab00a884 100644 --- a/crewai/agent.py +++ b/crewai/agent.py @@ -1,6 +1,6 @@ """Generic agent.""" -from typing import List, Any +from typing import List from pydantic import BaseModel, Field from langchain.tools import Tool @@ -10,21 +10,39 @@ from langchain.tools.render import render_text_description from langchain.agents.format_scratchpad import format_log_to_str from langchain.agents.output_parsers import ReActSingleInputOutputParser -from .prompts import AGENT_EXECUTION_PROMPT +from .prompts import Prompts class Agent(BaseModel): + """Generic agent implementation.""" role: str = Field(description="Role of the agent") goal: str = Field(description="Objective of the agent") backstory: str = Field(description="Backstory of the agent") - tools: List[Tool] = Field(description="Tools at agents disposal") - llm: str = Field(description="LLM of the agent", default=OpenAI( - temperature=0.7, - model="gpt-4", - verbose=True - )) + tools: List[Tool] = Field( + description="Tools at agents disposal", + default=[] + ) + prompts: Prompts = Field( + description="Prompts class for the agent.", + default=Prompts + ) + llm: str = Field( + description="LLM of the agent", + default=OpenAI( + temperature=0.7, + model="gpt-4", + verbose=True + ) + ) def execute(self, task: str) -> str: - prompt = AGENT_EXECUTION_PROMPT.partial( + """ + Execute a task with the agent. + Parameters: + task (str): Task to execute + Returns: + output (str): Output of the agent + """ + prompt = Prompts.AGENT_EXECUTION_PROMPT.partial( tools=render_text_description(self.tools), tool_names=self.__tools_names(), backstory=self.backstory,