Skip to content

Enable Agents as Tools #135

@bibryam

Description

@bibryam

Background
The current Dapper Agents platform supports multi-agent interactions via asynchronous messaging, which can be overkill for tightly-coupled workflows. This feature introduces the ability for agents to invoke other agents synchronously as tools. It allows modular agent design where a central agent can delegate tasks to specialized agents dynamically, with direct, inline responses.

Scenarion
You define a parent agent (the Orchestrator) responsible for handling user input and delegating tasks. Separately, you define two specialized agents:

  • FlightSearchAgent, a flight search expert that uses a search_flights tool to find flight options.
  • HotelSearchAgent, a hotel booking expert that uses a search_hotels tool to find hotel options.
    Each specialized agent is defined with its own purpose, tools, and instructions. You then wrap both agents using agent_tool() and include them in the Orchestrator agent’s tool list. This setup allows the Orchestrator to synchronously invoke the specialized agents at runtime, just like any other tool, enabling tightly-coupled, multi-agent workflows.

Acceptance Criteria
Support wrapping an agent as a callable tool
Allow an agent to include other agents in its toolset.
Invocation is synchronous and returns the child agent's final result.

Pseudo Code

 from dapr_agents import Agent, tool, agent_tool
from pydantic import BaseModel
from typing import List

# Schemas
class DestinationSchema(BaseModel):
    destination: str

class FlightOption(BaseModel):
    airline: str
    price: float

class HotelOption(BaseModel):
    hotel_name: str
    price_per_night: float

# Flight search tool
@tool(args_model=DestinationSchema)
def search_flights(destination: str) -> List[FlightOption]:
    return [FlightOption(airline="SkyHigh", price=450.00)]

# Hotel search tool
@tool(args_model=DestinationSchema)
def search_hotels(destination: str) -> List[HotelOption]:
    return [HotelOption(hotel_name="Hotel Zen", price_per_night=120.00)]

# Specialized agents
search_flights_agent = Agent(
    name="FlightSearchAgent",
    role="Flight search expert",
    instructions=["Find flights using tools"],
    tools=[search_flights]
)

search_hotels_agent = Agent(
    name="HotelSearchAgent",
    role="Hotel booking expert",
    instructions=["Find hotels using tools"],
    tools=[search_hotels]
)

# Wrap agents as tools
flight_tool = agent_tool(search_flights_agent)
hotel_tool = agent_tool(search_hotels_agent)

# Orchestrator agent
orchestrator_agent = Agent(
    name="Orchestrator",
    role="Handles user travel requests",
    instructions=["Interpret user needs and delegate to agent tools"],
    tools=[flight_tool, hotel_tool]
)

# Usage
await orchestrator_agent.run("I need to book a trip to Tokyo including flights and hotel")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions