motleycrew.agents.langchain.tool_calling_react

Functions

check_variables(prompt)

create_tool_calling_react_agent(llm, tools, ...)

get_relevant_default_prompt(llm, ...)

render_text_description(tools)

Classes

ReActToolCallingMotleyAgent(tools[, ...])

Universal ReAct-style agent that supports tool calling.

motleycrew.agents.langchain.tool_calling_react.check_variables(prompt: ChatPromptTemplate)
motleycrew.agents.langchain.tool_calling_react.render_text_description(tools: list[BaseTool]) str
motleycrew.agents.langchain.tool_calling_react.get_relevant_default_prompt(llm: BaseChatModel, force_output_handler: bool) ChatPromptTemplate
motleycrew.agents.langchain.tool_calling_react.create_tool_calling_react_agent(llm: BaseChatModel, tools: Sequence[BaseTool], prompt: ChatPromptTemplate, output_handlers: Sequence[BaseTool], force_output_handler: bool, intermediate_steps_processor: Callable | None = None) Runnable
class motleycrew.agents.langchain.tool_calling_react.ReActToolCallingMotleyAgent(tools: Sequence[MotleySupportedTool], description: str | None = None, name: str | None = None, prompt_prefix: str | ChatPromptTemplate | None = None, prompt: ChatPromptTemplate | None = None, chat_history: bool | GetSessionHistoryCallable = True, force_output_handler: bool = False, handle_parsing_errors: bool = True, handle_tool_errors: bool = True, llm: BaseChatModel | None = None, max_iterations: int | None = 15, intermediate_steps_processor: Callable | None = None, runnable_config: RunnableConfig | None = None, verbose: bool = False)

Bases: LangchainMotleyAgent

Universal ReAct-style agent that supports tool calling.

This agent only works with newer models that support tool calling. If you are using an older model, you should use motleycrew.agents.langchain.LegacyReActMotleyAgent instead.

__init__(tools: Sequence[MotleySupportedTool], description: str | None = None, name: str | None = None, prompt_prefix: str | ChatPromptTemplate | None = None, prompt: ChatPromptTemplate | None = None, chat_history: bool | GetSessionHistoryCallable = True, force_output_handler: bool = False, handle_parsing_errors: bool = True, handle_tool_errors: bool = True, llm: BaseChatModel | None = None, max_iterations: int | None = 15, intermediate_steps_processor: Callable | None = None, runnable_config: RunnableConfig | None = None, verbose: bool = False)
Parameters:
  • tools – Tools to add to the agent.

  • description – Description of the agent.

  • name – Name of the agent.

  • prompt_prefix – Prefix to the agent’s prompt.

  • prompt – The prompt to use. See Prompt section below for more on the expected input variables.

  • chat_history – Whether to use chat history or not. If True, uses InMemoryChatMessageHistory. If a callable is passed, it is used to get the chat history by session_id. See langchain_core.runnables.history.RunnableWithMessageHistory for more details.

  • force_output_handler – Whether to force the agent to return through an output handler. If True, at least one tool must have return_direct set to True.

  • handle_parsing_errors – Whether to handle parsing errors.

  • handle_tool_errors – Whether to handle tool errors. If True, handle_tool_error and handle_validation_error in all tools are set to True.

  • llm – Language model to use.

  • max_iterations – The maximum number of agent iterations.

  • intermediate_steps_processor – Function that modifies the intermediate steps array in some way before each agent iteration.

  • runnable_config – Default Langchain config to use when invoking the agent. It can be used to add callbacks, metadata, etc.

  • verbose – Whether to log verbose output.

Prompt:

The prompt must have agent_scratchpad, chat_history, and additional_notes ``MessagesPlaceholder``s. If a prompt is not passed in, the default one is used.

The default prompt slightly varies depending on the language model used. See motleycrew.agents.langchain.tool_calling_react_prompts for more details.