motleycrew.agents.crewai

Modules

agent_with_config

crewai

crewai_agent

class motleycrew.agents.crewai.CrewAIAgentWithConfig(*args, **kwargs)

Bases: object

__init__(*args, **kwargs)

Subclass for CrewAI Agent that overrides the execute_task method to include a config parameter.

Parameters:
  • *args

  • **kwargs

execute_task(task: Any, context: str | None = None, tools: List[Any] | None = None, config: RunnableConfig | None = None) str

Execute a task with the agent.

Parameters:
  • task – Task to execute.

  • context – Context to execute the task in.

  • tools – Tools to use for the task.

Returns:

Output of the agent

class motleycrew.agents.crewai.CrewAIMotleyAgentParent(goal: str, prompt_prefix: str | None = None, description: str | None = None, name: str | None = None, agent_factory: MotleyAgentFactory[CrewAIAgentWithConfig] | None = None, tools: Sequence[MotleySupportedTool] | None = None, force_output_handler: bool = False, verbose: bool = False)

Bases: MotleyAgentParent

Base MotleyCrew wrapper for CrewAI agents.

__init__(goal: str, prompt_prefix: str | None = None, description: str | None = None, name: str | None = None, agent_factory: MotleyAgentFactory[CrewAIAgentWithConfig] | None = None, tools: Sequence[MotleySupportedTool] | None = None, force_output_handler: bool = False, verbose: bool = False)
Parameters:
  • goal – Goal of the agent.

  • prompt_prefix – Prefix to the agent’s prompt. Can be used for providing additional context, such as the agent’s role or backstory.

  • description

    Description of the agent.

    Unlike the prompt prefix, it is not included in the prompt. The description is only used for describing the agent’s purpose when giving it as a tool to other agents.

  • name – Name of the agent. The name is used for identifying the agent when it is given as a tool to other agents, as well as for logging purposes. It is not included in the agent’s prompt.

  • agent_factory

    Factory function to create the agent. The factory function should accept a dictionary of tools and return a CrewAIAgentWithConfig instance.

    See motleycrew.common.types.MotleyAgentFactory for more details.

    Alternatively, you can use the from_agent() method to wrap an existing CrewAIAgentWithConfig.

  • tools – Tools to add to the agent.

  • force_output_handler – Whether to force the agent to return through an output handler. NOTE: This is currently not supported for CrewAI agents.

  • verbose – Whether to log verbose output.

invoke(input: dict, config: RunnableConfig | None = None, **kwargs: Any) Any

Transform a single input into an output. Override to implement.

Parameters:
  • input – The input to the Runnable.

  • config – A config to use when invoking the Runnable. The config supports standard keys like ‘tags’, ‘metadata’ for tracing purposes, ‘max_concurrency’ for controlling how much work to do in parallel, and other keys. Please refer to the RunnableConfig for more details.

Returns:

The output of the Runnable.

materialize()

Materialize the agent by creating the agent instance using the agent factory. This method should be called before invoking the agent for the first time.

set_cache_handler(cache_handler: Any) None
set_rpm_controller(rpm_controller: Any) None
static from_agent(agent: CrewAIAgentWithConfig, tools: Sequence[MotleySupportedTool] | None = None, verbose: bool = False) CrewAIMotleyAgentParent

Create a CrewAIMotleyAgentParent from a CrewAIAgentWithConfig instance.

Using this method, you can wrap an existing CrewAIAgentWithConfig without providing a factory function.

Parameters:
  • agent – CrewAIAgentWithConfig instance to wrap.

  • tools – Tools to add to the agent.

  • verbose – Whether to log verbose output.

as_tool(**kwargs) MotleyTool

Convert the agent to a tool to be used by other agents via delegation.

Parameters:

kwargs – Additional arguments to pass to the tool. See motleycrew.tools.tool.MotleyTool for more details.

class motleycrew.agents.crewai.CrewAIMotleyAgent(role: str, goal: str, backstory: str, prompt_prefix: str | None = None, description: str | None = None, delegation: bool = False, tools: Sequence[MotleySupportedTool] | None = None, force_output_handler: bool = False, llm: Any | None = None, verbose: bool = False)

Bases: CrewAIMotleyAgentParent

MotleyCrew wrapper for CrewAI Agent.

This wrapper is made to mimic the CrewAI agent’s interface. That is why it has mostly the same arguments.

__init__(role: str, goal: str, backstory: str, prompt_prefix: str | None = None, description: str | None = None, delegation: bool = False, tools: Sequence[MotleySupportedTool] | None = None, force_output_handler: bool = False, llm: Any | None = None, verbose: bool = False)
Parameters:
  • rolerole param of the CrewAI Agent.

  • goalgoal param of the CrewAI Agent.

  • backstorybackstory param of the CrewAI Agent.

  • prompt_prefix – Prefix to the agent’s prompt. Can be used for providing additional context, such as the agent’s role or backstory.

  • description

    Description of the agent.

    Unlike the prompt prefix, it is not included in the prompt. The description is only used for describing the agent’s purpose when giving it as a tool to other agents.

  • delegation – Whether to allow delegation or not. Delegation is not supported in this wrapper. Instead, pass the agents you want to delegate to as tools.

  • tools – Tools to add to the agent.

  • llm – LLM instance to use.

  • force_output_handler – Whether to force the use of an output handler. NOTE: This is currently not supported for CrewAI agents.

  • verbose – Whether to log verbose output.