Add #[tool] macro for ergonomic tool creation#24
Merged
irshadnilam merged 9 commits intoagents-sh:mainfrom Nov 12, 2025
Merged
Conversation
This commit simplifies the tool macro implementation and optimizes tool storage patterns across the codebase. Key changes: - Tool macro now generates structs implementing BaseTool directly - Removed support for custom tool names (function name = tool name) - Changed tool storage from Arc<dyn BaseTool> to Box<dyn BaseTool> - BaseToolset.get_tools() returns Vec<&dyn BaseTool> (borrowed refs) - MCPToolset uses OnceCell for lazy initialization - OpenApiToolSet updated to match new storage pattern - RecordingTool made cloneable for testing convenience - All tests updated and passing Performance benefits: - Reduced allocations (references instead of Arc clones) - Maintained efficient sharing via Arc for internal resources - Lazy initialization preserved for MCP tools
Integrated upstream changes including: - React-based dev UI - WASM compatibility improvements for MCP/OpenAPI - Streaming delay fixes - Additional test coverage All our tool macro changes preserved: - Struct generation with BaseTool implementation - Box storage with borrowed references - Generic with_tool methods - RecordingTool Clone support Conflicts resolved in: - Cargo.lock (regenerated) - radkit/tests/worker_execution.rs (combined assertions)
irshadnilam
approved these changes
Nov 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a procedural macro that simplifies tool definition and refactors tool storage for better ergonomics and performance.
Key Changes
#[tool]macro generates tool structs - Function name becomes the tool nameArc<dyn BaseTool>toBox<dyn BaseTool>for unique ownershipBaseToolset::get_tools()now returnsVec<&dyn BaseTool>with lifetimeswith_tool()accepts anyBaseToolimplementationUsage
Before:
After:
Benefits
Implementation Details
The macro generates a zero-sized struct that implements BaseTool:
Toolsets store tools as
Vec<Box<dyn BaseTool>>and return borrowed references viaget_tools() -> Vec<&dyn BaseTool>, eliminating unnecessary Arc cloning while maintaining efficient access patterns.