mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-28 17:48:13 +00:00
adding context to agent task execution
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"""Generic agent."""
|
"""Generic agent."""
|
||||||
|
|
||||||
from typing import List
|
from typing import List, Any
|
||||||
from pydantic.v1 import BaseModel, Field
|
from pydantic.v1 import BaseModel, Field
|
||||||
|
|
||||||
from langchain.tools import Tool
|
from langchain.tools import Tool
|
||||||
@@ -23,7 +23,7 @@ class Agent(BaseModel):
|
|||||||
role: str = Field(description="Role of the agent")
|
role: str = Field(description="Role of the agent")
|
||||||
goal: str = Field(description="Objective of the agent")
|
goal: str = Field(description="Objective of the agent")
|
||||||
backstory: str = Field(description="Backstory of the agent")
|
backstory: str = Field(description="Backstory of the agent")
|
||||||
tools: List[Tool] = Field(
|
tools: List[Any] = Field(
|
||||||
description="Tools at agents disposal",
|
description="Tools at agents disposal",
|
||||||
default=[]
|
default=[]
|
||||||
)
|
)
|
||||||
@@ -66,7 +66,7 @@ class Agent(BaseModel):
|
|||||||
handle_parsing_errors=True
|
handle_parsing_errors=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def execute_task(self, task: str) -> str:
|
def execute_task(self, task: str, context: str = None) -> str:
|
||||||
"""
|
"""
|
||||||
Execute a task with the agent.
|
Execute a task with the agent.
|
||||||
Parameters:
|
Parameters:
|
||||||
@@ -74,6 +74,13 @@ class Agent(BaseModel):
|
|||||||
Returns:
|
Returns:
|
||||||
output (str): Output of the agent
|
output (str): Output of the agent
|
||||||
"""
|
"""
|
||||||
|
if context:
|
||||||
|
task = "\n".join([
|
||||||
|
task,
|
||||||
|
"\nThis is the context you are working with:",
|
||||||
|
context
|
||||||
|
])
|
||||||
|
|
||||||
return self.agent_executor.invoke({
|
return self.agent_executor.invoke({
|
||||||
"input": task,
|
"input": task,
|
||||||
"tool_names": self.__tools_names(),
|
"tool_names": self.__tools_names(),
|
||||||
|
|||||||
Reference in New Issue
Block a user