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
-
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
-
Multiple Toolsets: Support chaining .toolset(ts1).toolset(ts2) for multiple MCP servers
-
Tool Routing: Track which toolset owns which tool to route call_tool correctly
-
Lifecycle: Call toolset.enter() when agent starts and toolset.exit() when done
-
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
Summary
Add a
.toolset()method toAgentBuilderthat allows registering anAbstractToolset(likeMcpToolset) with an agent.Motivation
Currently,
AgentBuildersupports 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 executorHowever, there's no way to register an entire
AbstractToolsetwhich would import all its tools. This is needed to integrateMcpToolset(fromserdes-ai-mcp) with agents.Proposed API
Implementation Considerations
Async in Builder:
AbstractToolset::get_tools()is async, so either:build()asyncMultiple Toolsets: Support chaining
.toolset(ts1).toolset(ts2)for multiple MCP serversTool Routing: Track which toolset owns which tool to route
call_toolcorrectlyLifecycle: Call
toolset.enter()when agent starts andtoolset.exit()when doneName Conflicts: Handle tool name collisions between toolsets (error or prefix)
Related
AbstractToolsettrait inserdes-ai-toolsetsMcpToolsetinserdes-ai-mcpAgentBuilderinserdes-ai-agent