Spaces:
Sleeping
Sleeping
Update crewai/agent.py
Browse files- crewai/agent.py +6 -12
crewai/agent.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import uuid
|
| 2 |
from typing import Any, List, Optional
|
| 3 |
|
| 4 |
-
from langchain.agents.agent import RunnableAgent
|
| 5 |
from langchain.agents.format_scratchpad import format_log_to_str
|
|
|
|
| 6 |
from langchain.memory import ConversationSummaryMemory
|
| 7 |
from langchain.tools.render import render_text_description
|
| 8 |
from langchain_core.runnables.config import RunnableConfig
|
| 9 |
from langchain_openai import ChatOpenAI
|
|
|
|
| 10 |
from pydantic import (
|
| 11 |
UUID4,
|
| 12 |
BaseModel,
|
|
@@ -30,10 +31,8 @@ from crewai.utilities import I18N, Logger, Prompts, RPMController
|
|
| 30 |
|
| 31 |
class Agent(BaseModel):
|
| 32 |
"""Represents an agent in a system.
|
| 33 |
-
|
| 34 |
Each agent has a role, a goal, a backstory, and an optional language model (llm).
|
| 35 |
The agent can also have memory, can operate in verbose mode, and can delegate tasks to other agents.
|
| 36 |
-
|
| 37 |
Attributes:
|
| 38 |
agent_executor: An instance of the CrewAgentExecutor class.
|
| 39 |
role: The role of the agent.
|
|
@@ -130,12 +129,10 @@ class Agent(BaseModel):
|
|
| 130 |
tools: Optional[List[Any]] = None,
|
| 131 |
) -> str:
|
| 132 |
"""Execute a task with the agent.
|
| 133 |
-
|
| 134 |
Args:
|
| 135 |
task: Task to execute.
|
| 136 |
context: Context to execute the task in.
|
| 137 |
tools: Tools to use for the task.
|
| 138 |
-
|
| 139 |
Returns:
|
| 140 |
Output of the agent
|
| 141 |
"""
|
|
@@ -164,27 +161,24 @@ class Agent(BaseModel):
|
|
| 164 |
|
| 165 |
def set_cache_handler(self, cache_handler: CacheHandler) -> None:
|
| 166 |
"""Set the cache handler for the agent.
|
| 167 |
-
|
| 168 |
Args:
|
| 169 |
cache_handler: An instance of the CacheHandler class.
|
| 170 |
"""
|
| 171 |
self.cache_handler = cache_handler
|
| 172 |
self.tools_handler = ToolsHandler(cache=self.cache_handler)
|
| 173 |
-
self.
|
| 174 |
|
| 175 |
def set_rpm_controller(self, rpm_controller: RPMController) -> None:
|
| 176 |
"""Set the rpm controller for the agent.
|
| 177 |
-
|
| 178 |
Args:
|
| 179 |
rpm_controller: An instance of the RPMController class.
|
| 180 |
"""
|
| 181 |
if not self._rpm_controller:
|
| 182 |
self._rpm_controller = rpm_controller
|
| 183 |
-
self.
|
| 184 |
|
| 185 |
-
def
|
| 186 |
"""Create an agent executor for the agent.
|
| 187 |
-
|
| 188 |
Returns:
|
| 189 |
An instance of the CrewAgentExecutor class.
|
| 190 |
"""
|
|
@@ -240,4 +234,4 @@ class Agent(BaseModel):
|
|
| 240 |
|
| 241 |
@staticmethod
|
| 242 |
def __tools_names(tools) -> str:
|
| 243 |
-
return ", ".join([t.name for t in tools])
|
|
|
|
| 1 |
import uuid
|
| 2 |
from typing import Any, List, Optional
|
| 3 |
|
|
|
|
| 4 |
from langchain.agents.format_scratchpad import format_log_to_str
|
| 5 |
+
from langchain.agents.agent import RunnableAgent
|
| 6 |
from langchain.memory import ConversationSummaryMemory
|
| 7 |
from langchain.tools.render import render_text_description
|
| 8 |
from langchain_core.runnables.config import RunnableConfig
|
| 9 |
from langchain_openai import ChatOpenAI
|
| 10 |
+
from langchain_core.language_models import BaseLanguageModel
|
| 11 |
from pydantic import (
|
| 12 |
UUID4,
|
| 13 |
BaseModel,
|
|
|
|
| 31 |
|
| 32 |
class Agent(BaseModel):
|
| 33 |
"""Represents an agent in a system.
|
|
|
|
| 34 |
Each agent has a role, a goal, a backstory, and an optional language model (llm).
|
| 35 |
The agent can also have memory, can operate in verbose mode, and can delegate tasks to other agents.
|
|
|
|
| 36 |
Attributes:
|
| 37 |
agent_executor: An instance of the CrewAgentExecutor class.
|
| 38 |
role: The role of the agent.
|
|
|
|
| 129 |
tools: Optional[List[Any]] = None,
|
| 130 |
) -> str:
|
| 131 |
"""Execute a task with the agent.
|
|
|
|
| 132 |
Args:
|
| 133 |
task: Task to execute.
|
| 134 |
context: Context to execute the task in.
|
| 135 |
tools: Tools to use for the task.
|
|
|
|
| 136 |
Returns:
|
| 137 |
Output of the agent
|
| 138 |
"""
|
|
|
|
| 161 |
|
| 162 |
def set_cache_handler(self, cache_handler: CacheHandler) -> None:
|
| 163 |
"""Set the cache handler for the agent.
|
|
|
|
| 164 |
Args:
|
| 165 |
cache_handler: An instance of the CacheHandler class.
|
| 166 |
"""
|
| 167 |
self.cache_handler = cache_handler
|
| 168 |
self.tools_handler = ToolsHandler(cache=self.cache_handler)
|
| 169 |
+
self.__create_agent_executor()
|
| 170 |
|
| 171 |
def set_rpm_controller(self, rpm_controller: RPMController) -> None:
|
| 172 |
"""Set the rpm controller for the agent.
|
|
|
|
| 173 |
Args:
|
| 174 |
rpm_controller: An instance of the RPMController class.
|
| 175 |
"""
|
| 176 |
if not self._rpm_controller:
|
| 177 |
self._rpm_controller = rpm_controller
|
| 178 |
+
self.__create_agent_executor()
|
| 179 |
|
| 180 |
+
def __create_agent_executor(self) -> None:
|
| 181 |
"""Create an agent executor for the agent.
|
|
|
|
| 182 |
Returns:
|
| 183 |
An instance of the CrewAgentExecutor class.
|
| 184 |
"""
|
|
|
|
| 234 |
|
| 235 |
@staticmethod
|
| 236 |
def __tools_names(tools) -> str:
|
| 237 |
+
return ", ".join([t.name for t in tools])
|