Skip to content

task_tool

langroid/agent/tools/task_tool.py

A tool that allows agents to delegate a task to a sub-agent with

specific tools enabled.

TaskTool

Bases: ToolMessage

Tool that spawns a sub-agent with specified tools to handle a task.

The sub-agent can be given a custom name for identification in logs. If no name is provided, a random unique name starting with 'agent' will be generated.

handle(agent)

Handle the TaskTool by creating a sub-agent with specified tools and running the task non-interactively.

Parameters:

Name Type Description Default
agent ChatAgent

The parent ChatAgent that is handling this tool

required
Source code in langroid/agent/tools/task_tool.py
def handle(self, agent: ChatAgent) -> Optional[ChatDocument]:
    """

    Handle the TaskTool by creating a sub-agent with specified tools
    and running the task non-interactively.

    Args:
        agent: The parent ChatAgent that is handling this tool
    """

    task = self._set_up_task(agent)
    # Run the task on the prompt, and return the result
    result = task.run(self.prompt, turns=self.max_iterations or 10)
    return result

handle_async(agent) async

Async method to handle the TaskTool by creating a sub-agent with specified tools and running the task non-interactively.

Parameters:

Name Type Description Default
agent ChatAgent

The parent ChatAgent that is handling this tool

required
Source code in langroid/agent/tools/task_tool.py
async def handle_async(self, agent: ChatAgent) -> Optional[ChatDocument]:
    """
    Async method to handle the TaskTool by creating a sub-agent with specified tools
    and running the task non-interactively.

    Args:
        agent: The parent ChatAgent that is handling this tool
    """
    task = self._set_up_task(agent)
    # Run the task on the prompt, and return the result
    result = await task.run_async(self.prompt, turns=self.max_iterations or 10)
    return result