diff --git a/docs/core-concepts/Agents.md b/docs/core-concepts/Agents.md index 1f6c77328..928aa356a 100644 --- a/docs/core-concepts/Agents.md +++ b/docs/core-concepts/Agents.md @@ -31,6 +31,7 @@ description: What are crewAI Agents and how to use them. | **Allow Delegation** *(optional)* | Agents can delegate tasks or questions to one another, ensuring that each task is handled by the most suitable agent. Default is `True`. | | **Step Callback** *(optional)* | A function that is called after each step of the agent. This can be used to log the agent's actions or to perform other operations. It will overwrite the crew `step_callback`. | | **Cache** *(optional)* | Indicates if the agent should use a cache for tool usage. Default is `True`. | +| **runnable_config** *(optional)* | A Langchain supported RunnableConfig to be used by the AgentExecutor. Default is `None`. | ## Creating an Agent @@ -64,4 +65,4 @@ agent = Agent( ``` ## Conclusion -Agents are the building blocks of the CrewAI framework. By understanding how to define and interact with agents, you can create sophisticated AI systems that leverage the power of collaborative intelligence. \ No newline at end of file +Agents are the building blocks of the CrewAI framework. By understanding how to define and interact with agents, you can create sophisticated AI systems that leverage the power of collaborative intelligence. diff --git a/src/crewai/agent.py b/src/crewai/agent.py index d8b2cdec5..805be26fc 100644 --- a/src/crewai/agent.py +++ b/src/crewai/agent.py @@ -7,6 +7,7 @@ from langchain.tools.render import render_text_description from langchain_core.agents import AgentAction from langchain_core.callbacks import BaseCallbackHandler +from langchain_core.runnables import RunnableConfig from langchain_openai import ChatOpenAI from pydantic import ( UUID4, @@ -48,6 +49,7 @@ class Agent(BaseModel): tools: Tools at agents disposal step_callback: Callback to be executed after each step of the agent execution. callbacks: A list of callback functions from the langchain library that are triggered during the agent's execution process + runnable_config: A runnable configuration to be used by the AgentExecutor """ __hash__ = object.__hash__ # type: ignore @@ -130,6 +132,10 @@ class Agent(BaseModel): response_template: Optional[str] = Field( default=None, description="Response format for the agent." ) + runnable_config: Optional[RunnableConfig] = Field( + default=None, + description="A runnable configuration to be used by the AgentExecutor", + ) _original_role: str | None = None _original_goal: str | None = None @@ -192,6 +198,7 @@ def execute_task( task: Any, context: Optional[str] = None, tools: Optional[List[Any]] = None, + runnable_config: Optional[RunnableConfig] = None, ) -> str: """Execute a task with the agent. @@ -199,6 +206,7 @@ def execute_task( task: Task to execute. context: Context to execute the task in. tools: Tools to use for the task. + runnable_config: A runnable configuration to be used by the AgentExecutor. Overrides the runnable_config attribute. Returns: Output of the agent @@ -238,7 +246,8 @@ def execute_task( "input": task_prompt, "tool_names": self.agent_executor.tools_names, "tools": self.agent_executor.tools_description, - } + }, + config=runnable_config or self.runnable_config, )["output"] if self.max_rpm: