Skip to content

Add toolset() method to AgentBuilder for AbstractToolset integration #5

Description

@acoliver

Summary

Add a .toolset() method to AgentBuilder that allows registering an AbstractToolset (like McpToolset) with an agent.

Motivation

Currently, AgentBuilder supports registering individual tools via:

  • .tool_fn() - register a closure as a tool
  • .tool_fn_async() - register an async closure
  • .tool_with_executor() - register with a custom executor

However, there's no way to register an entire AbstractToolset which would import all its tools. This is needed to integrate McpToolset (from serdes-ai-mcp) with agents.

Proposed API

let mcp_toolset = McpToolset::stdio("npx", &["-y", "@mcp/server"]).await?;

let agent = agent(model)
    .system_prompt("You have access to filesystem tools.")
    .toolset(mcp_toolset)  // <-- New method
    .build()
    .await?;  // Note: build() may need to become async

Implementation Considerations

  1. Async in Builder: AbstractToolset::get_tools() is async, so either:

    • Make build() async
    • Discover tools lazily at first run
    • Store toolset and discover at agent creation
  2. Multiple Toolsets: Support chaining .toolset(ts1).toolset(ts2) for multiple MCP servers

  3. Tool Routing: Track which toolset owns which tool to route call_tool correctly

  4. Lifecycle: Call toolset.enter() when agent starts and toolset.exit() when done

  5. Name Conflicts: Handle tool name collisions between toolsets (error or prefix)

Related

  • AbstractToolset trait in serdes-ai-toolsets
  • McpToolset in serdes-ai-mcp
  • AgentBuilder in serdes-ai-agent

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions