motleycrew.tools
MotleyTool class and tools library.
Modules
- class motleycrew.tools.MotleyTool(tool: BaseTool | None = None, name: str | None = None, description: str | None = None, args_schema: BaseModel | None = None, return_direct: bool = False, exceptions_to_reflect: List[Type[Exception]] | None = None, retry_config: RetryConfig | None = None)
Bases:
Runnable
Base tool class compatible with MotleyAgents.
It is a wrapper for Langchain BaseTool, containing all necessary adapters and converters.
- __init__(tool: BaseTool | None = None, name: str | None = None, description: str | None = None, args_schema: BaseModel | None = None, return_direct: bool = False, exceptions_to_reflect: List[Type[Exception]] | None = None, retry_config: RetryConfig | None = None)
Initialize the MotleyTool.
- Parameters:
name – Name of the tool (required if tool is None).
description – Description of the tool (required if tool is None).
args_schema – Schema of the tool arguments (required if tool is None).
tool – Langchain BaseTool to wrap.
return_direct – If True, the tool’s output will be returned directly to the user.
exceptions_to_reflect – List of exceptions to reflect back to the agent.
retry_config – Configuration for retry behavior. If None, exceptions will not be retried.
- property name
Name of the tool.
- property description
Description of the tool.
- property args_schema
Schema of the tool arguments.
- invoke(input: str | 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.
- run(*args, **kwargs)
- static from_langchain_tool(langchain_tool: BaseTool, return_direct: bool = False, exceptions_to_reflect: List[Exception] | None = None, retry_config: RetryConfig | None = None) MotleyTool
Create a MotleyTool from a Langchain tool.
- Parameters:
langchain_tool – Langchain tool to convert.
return_direct – If True, the tool’s output will be returned directly to the user.
exceptions_to_reflect – List of exceptions to reflect back to the agent.
retry_config – Configuration for retry behavior. If None, exceptions will not be retried.
- Returns:
MotleyTool instance.
- static from_llama_index_tool(llama_index_tool: None, return_direct: bool = False, exceptions_to_reflect: List[Exception] | None = None, retry_config: RetryConfig | None = None) MotleyTool
Create a MotleyTool from a LlamaIndex tool.
- Parameters:
llama_index_tool – LlamaIndex tool to convert.
return_direct – If True, the tool’s output will be returned directly to the user.
exceptions_to_reflect – List of exceptions to reflect back to the agent.
retry_config – Configuration for retry behavior. If None, exceptions will not be retried.
- Returns:
MotleyTool instance.
- static from_crewai_tool(crewai_tool: None, return_direct: bool = False, exceptions_to_reflect: List[Exception] | None = None, retry_config: RetryConfig | None = None) MotleyTool
Create a MotleyTool from a CrewAI tool.
- Parameters:
crewai_tool – CrewAI tool to convert.
return_direct – If True, the tool’s output will be returned directly to the user.
exceptions_to_reflect – List of exceptions to reflect back to the agent.
retry_config – Configuration for retry behavior. If None, exceptions will not be retried.
- Returns:
MotleyTool instance.
- static from_motley_agent(agent: MotleyAgentAbstractParent, return_direct: bool = False, exceptions_to_reflect: List[Exception] | None = None, retry_config: RetryConfig | None = None) MotleyTool
Convert an agent to a tool to be used by other agents via delegation.
- Parameters:
agent – The MotleyAgent to convert to a tool.
return_direct – If True, the tool’s output will be returned directly to the user.
exceptions_to_reflect – List of exceptions to reflect back to the agent.
retry_config – Configuration for retry behavior. If None, exceptions will not be retried.
- Returns:
The tool representation of the agent.
- static from_supported_tool(tool: MotleyTool | BaseTool | None | MotleyAgentAbstractParent, return_direct: bool = False, exceptions_to_reflect: List[Exception] | None = None, retry_config: RetryConfig | None = None) MotleyTool
Create a MotleyTool from any supported tool type.
- Parameters:
tool – Tool of any supported type. Currently, we support tools from Langchain, LlamaIndex, as well as motleycrew agents.
return_direct – If True, the tool’s output will be returned directly to the user.
exceptions_to_reflect – List of exceptions to reflect back to the agent.
retry_config – Configuration for retry behavior. If None, exceptions will not be retried.
- Returns:
MotleyTool instance.
- to_langchain_tool() BaseTool
Convert the MotleyTool to a Langchain tool.
- Returns:
Langchain tool.
- to_llama_index_tool() None
Convert the MotleyTool to a LlamaIndex tool.
- Returns:
LlamaIndex tool.
- to_autogen_tool() Callable
Convert the MotleyTool to an AutoGen tool.
An AutoGen tool is basically a function. AutoGen infers the tool input schema from the function signature. For this reason, because we can’t generate the signature dynamically, we can only convert tools with a single input field.
- Returns:
AutoGen tool function.
- to_crewai_tool() None
Description
- Return type:
Crewai__BaseTool
- class motleycrew.tools.RetryConfig(max_retries: int = 3, wait_time: float = 1.0, backoff_factor: float = 2.0, exceptions_to_retry: ~typing.Tuple[~typing.Type[Exception]] = (<class 'Exception'>, ))
Bases:
object
Configuration for retry behavior of MotleyTool.
- max_retries
Maximum number of retry attempts.
- Type:
int
- wait_time
Base wait time between retries in seconds.
- Type:
float
- backoff_factor
Multiplicative factor for exponential backoff.
- Type:
float
- exceptions_to_retry
Exceptions that should trigger a retry.
- Type:
List[Type[Exception]]
- max_retries: int = 3
- wait_time: float = 1.0
- backoff_factor: float = 2.0
- exceptions_to_retry: Tuple[Type[Exception]] = (<class 'Exception'>,)
- __init__(max_retries: int = 3, wait_time: float = 1.0, backoff_factor: float = 2.0, exceptions_to_retry: ~typing.Tuple[~typing.Type[Exception]] = (<class 'Exception'>, )) None
- exception motleycrew.tools.DirectOutput(output: Any)
Bases:
BaseException
Auxiliary exception to return a tool’s output directly.
When the tool returns an output, this exception is raised with the output. It is then handled by the agent, who should gracefully return the output to the user.
- __init__(output: Any)