motleycrew.tools.tool
Classes
|
Base tool class compatible with MotleyAgents. |
Exceptions
|
Auxiliary exception to return a tool's output directly. |
- exception motleycrew.tools.tool.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)
- class motleycrew.tools.tool.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[Exception] | 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[Exception] | 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.
- 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) 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.
- Returns:
MotleyTool instance.
- static from_llama_index_tool(llama_index_tool: None, return_direct: bool = False, exceptions_to_reflect: List[Exception] | 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.
- Returns:
MotleyTool instance.
- static from_crewai_tool(crewai_tool: None, return_direct: bool = False, exceptions_to_reflect: List[Exception] | 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.
- Returns:
MotleyTool instance.
- static from_motley_agent(agent: MotleyAgentAbstractParent, return_direct: bool = False, exceptions_to_reflect: List[Exception] | None = None) MotleyTool
Convert an agent to a tool to be used by other agents via delegation.
- 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) 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.
- 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