Custom tools are now framework-agnostic#123
Conversation
- Introduce `ToolFactory`, `CustomToolRegistry`, and `ToolCatalogEntry` in `reloaded-code-core` so external frameworks can register and enumerate custom tools without coupling to agents/serdesai - Move tool catalog types from `reloaded-code-agents` into `reloaded-code-core` so `AgentRuntimeBuilder` can accept core catalogs directly - Wire custom tools through the serdesai `AgentRuntime` builder and expose a test-stub factory for framework users - Update docs, READMEs, and examples across all three crates
WalkthroughThis PR implements a comprehensive custom tool registration system: it adds ToolFactory and registry types to core, extends the tool catalog with ToolCatalogKind::Custom and system-prompt tracking, exposes custom-tool registration on AgentRuntimeBuilder and stores registries in AgentRuntime, and materializes custom tools in SerdesAI's build pipeline (with adapter glue, errors, tests, and extensive documentation updates). Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/reloaded-code-agents/README.md (1)
368-368: 💤 Low valueUnused link reference definition.
The
ToolBuildContextreference is defined but not used in the document. Consider either:
- Using it where
ToolBuildContextis mentioned (e.g., line 285 in the code comment)- Removing the unused reference
Proposed fix: Remove the unused reference
[`ToolFactory`]: https://docs.rs/reloaded_code_core/latest/reloaded_code_core/trait.ToolFactory.html [`ToolContext`]: https://docs.rs/reloaded_code_core/latest/reloaded_code_core/trait.ToolContext.html -[`ToolBuildContext`]: https://docs.rs/reloaded_code_core/latest/reloaded_code_core/struct.ToolBuildContext.html🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/reloaded-code-agents/README.md` at line 368, Remove the unused Markdown reference definition for ToolBuildContext in the README: either delete the unused reference line "`[ToolBuildContext]: https://docs.rs/reloaded_code_core/latest/reloaded_code_core/struct.ToolBuildContext.html`" or replace occurrences of the plain text "ToolBuildContext" elsewhere in the document with the reference-style link (e.g., "ToolBuildContext[ToolBuildContext]") so the reference is actually used; look for the symbol "ToolBuildContext" in the README (e.g., the mention around line ~285) and update or remove the reference accordingly.docs/src/tools.md (1)
480-481: 💤 Low valueUnused link reference definitions.
The link references for ToolFactory and ToolContext are defined but not used in the document. Consider either:
- Using these references in the "Custom tools" section (e.g., change line 121's inline code to a link)
- Removing the unused references
Option 1: Use the references
In the custom tools section around line 121, change:
-| [**custom**](`#custom-tools`) | `ToolFactory` | User-defined tool registered by the embedder | +| [**custom**](`#custom-tools`) | [`ToolFactory`] | User-defined tool registered by the embedder |And in the code example explanation around line 137, change:
-impl ToolContext for WebSearchFactory { +impl [`ToolContext`] for WebSearchFactory {Option 2: Remove the unused references
-[`ToolFactory`]: https://docs.rs/reloaded-code-core/latest/reloaded_code_core/trait.ToolFactory.html -[`ToolContext`]: https://docs.rs/reloaded-code-core/latest/reloaded_code_core/trait.ToolContext.html🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/src/tools.md` around lines 480 - 481, The docs define unused reference links [`ToolFactory`] and [`ToolContext`]; either convert the inline code mentions of ToolFactory and ToolContext in the "Custom tools" section (replace plain inline code occurrences with the link references `[ToolFactory]` and `[ToolContext]` wherever those types are discussed, including the code example explanation) so the references are used, or remove the two link reference definitions entirely if you prefer not to link them; update any surrounding explanatory text to use the chosen form consistently.src/reloaded-code-core/README.md (1)
382-383: ⚡ Quick winRemove unused link definitions.
The link definitions for
ToolContext::nameandToolPromptare not referenced anywhere in this document. Static analysis correctly flagged these as unused.🧹 Remove unused link definitions
[`ToolContext`]: crate::context::ToolContext -[`ToolContext::name`]: crate::context::ToolContext::name -[`ToolPrompt`]: crate::context::ToolPrompt [`ToolFactory`]: crate::ToolFactory🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/reloaded-code-core/README.md` around lines 382 - 383, Remove the unused Markdown link definitions for `ToolContext::name` and `ToolPrompt` from the README (they appear as [`ToolContext::name`]: crate::context::ToolContext::name and [`ToolPrompt`]: crate::context::ToolPrompt); delete those two link definition lines and ensure no remaining references to `ToolContext::name` or `ToolPrompt` exist elsewhere in the document before committing.src/reloaded-code-serdesai/src/agent_runtime/build.rs (1)
174-183: ⚡ Quick winUpdate the
# Errorsdoc to cover custom-tool materialization.This function now materializes
ToolCatalogKind::Custom, so two things are stale:
- Line 177's "(this function only handles standard tools)" is no longer accurate.
- The
# Errorslist omits the newly reachableUnknownCustomToolandCustomToolDowncastFailedvariants.These propagate up to
build_agentandAgentBuildContext::build(task.rs Lines 164-174 and 292-302), whose# Errorssections are also missing the new variants.📝 Proposed doc update
/// # Errors /// -/// Returns [`AgentBuildError::UnsupportedToolKind`] when the runtime catalog contains an -/// unrecognized [`ToolCatalogKind`] variant (this function only handles standard tools). +/// Returns [`AgentBuildError::UnsupportedToolKind`] when the runtime catalog contains a +/// [`ToolCatalogKind`] variant this adapter cannot materialise. +/// +/// Returns [`AgentBuildError::UnknownCustomTool`] when a `ToolCatalogKind::Custom` entry has +/// no factory registered in `custom_tool_registry`. +/// +/// Returns [`AgentBuildError::CustomToolDowncastFailed`] when a custom tool factory returns a +/// value that cannot be downcast to `Box<dyn serdes_ai::Tool<()>>`. /// /// Returns [`AgentBuildError::ToolSettingsValidation`] when resolver creation or settings🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/reloaded-code-serdesai/src/agent_runtime/build.rs` around lines 174 - 183, Update the function-level `# Errors` doc in build.rs to remove the phrase "(this function only handles standard tools)" and add the two newly reachable AgentBuildError variants resulting from custom-tool materialization: `AgentBuildError::UnknownCustomTool` and `AgentBuildError::CustomToolDowncastFailed` (these arise when handling `ToolCatalogKind::Custom` during tool materialization). Also propagate the same doc changes to `build_agent` and `AgentBuildContext::build` (they now can return `UnknownCustomTool` and `CustomToolDowncastFailed`) so their `# Errors` lists include those variants alongside the existing ones.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/reloaded-code-agents/src/runtime/builder.rs`:
- Around line 12-18: AgentRuntimeBuilder lost its Clone derive which is a
source-incompatible breaking change; restore Clone on AgentRuntimeBuilder
(re-add #[derive(Clone, Debug)] or equivalent) and make CustomToolRegistry
itself cloneable instead of removing builder clonability — either implement
Clone for CustomToolRegistry or change its storage to a shared cloneable type
(e.g., wrap the registry inner data in Arc/Arc<Mutex<_>> or an
Arc<CustomToolRegistryInner>) and update construction/uses accordingly so
AgentRuntimeBuilder can derive/implement Clone again.
---
Nitpick comments:
In `@docs/src/tools.md`:
- Around line 480-481: The docs define unused reference links [`ToolFactory`]
and [`ToolContext`]; either convert the inline code mentions of ToolFactory and
ToolContext in the "Custom tools" section (replace plain inline code occurrences
with the link references `[ToolFactory]` and `[ToolContext]` wherever those
types are discussed, including the code example explanation) so the references
are used, or remove the two link reference definitions entirely if you prefer
not to link them; update any surrounding explanatory text to use the chosen form
consistently.
In `@src/reloaded-code-agents/README.md`:
- Line 368: Remove the unused Markdown reference definition for ToolBuildContext
in the README: either delete the unused reference line "`[ToolBuildContext]:
https://docs.rs/reloaded_code_core/latest/reloaded_code_core/struct.ToolBuildContext.html`"
or replace occurrences of the plain text "ToolBuildContext" elsewhere in the
document with the reference-style link (e.g.,
"ToolBuildContext[ToolBuildContext]") so the reference is actually used; look
for the symbol "ToolBuildContext" in the README (e.g., the mention around line
~285) and update or remove the reference accordingly.
In `@src/reloaded-code-core/README.md`:
- Around line 382-383: Remove the unused Markdown link definitions for
`ToolContext::name` and `ToolPrompt` from the README (they appear as
[`ToolContext::name`]: crate::context::ToolContext::name and [`ToolPrompt`]:
crate::context::ToolPrompt); delete those two link definition lines and ensure
no remaining references to `ToolContext::name` or `ToolPrompt` exist elsewhere
in the document before committing.
In `@src/reloaded-code-serdesai/src/agent_runtime/build.rs`:
- Around line 174-183: Update the function-level `# Errors` doc in build.rs to
remove the phrase "(this function only handles standard tools)" and add the two
newly reachable AgentBuildError variants resulting from custom-tool
materialization: `AgentBuildError::UnknownCustomTool` and
`AgentBuildError::CustomToolDowncastFailed` (these arise when handling
`ToolCatalogKind::Custom` during tool materialization). Also propagate the same
doc changes to `build_agent` and `AgentBuildContext::build` (they now can return
`UnknownCustomTool` and `CustomToolDowncastFailed`) so their `# Errors` lists
include those variants alongside the existing ones.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eb3467ee-8785-4faa-91b4-e2e77f0bd29f
📒 Files selected for processing (30)
README.MDdocs/src/agents.mddocs/src/architecture.mddocs/src/getting-started.mddocs/src/guides/custom-framework.mddocs/src/tools.mdsrc/reloaded-code-agents/ARCHITECTURE.mdsrc/reloaded-code-agents/README.mdsrc/reloaded-code-agents/src/lib.rssrc/reloaded-code-agents/src/path/resolver.rssrc/reloaded-code-agents/src/runtime/builder.rssrc/reloaded-code-agents/src/runtime/mod.rssrc/reloaded-code-agents/src/runtime/state.rssrc/reloaded-code-agents/src/runtime/task.rssrc/reloaded-code-core/README.mdsrc/reloaded-code-core/src/context/mod.rssrc/reloaded-code-core/src/custom_tool/factory.rssrc/reloaded-code-core/src/custom_tool/mod.rssrc/reloaded-code-core/src/custom_tool/registry.rssrc/reloaded-code-core/src/custom_tool/test_stubs.rssrc/reloaded-code-core/src/lib.rssrc/reloaded-code-core/src/system_prompt.rssrc/reloaded-code-core/src/tool_catalog.rssrc/reloaded-code-serdesai/README.mdsrc/reloaded-code-serdesai/src/agent_ext.rssrc/reloaded-code-serdesai/src/agent_runtime/build.rssrc/reloaded-code-serdesai/src/agent_runtime/mod.rssrc/reloaded-code-serdesai/src/agent_runtime/task.rssrc/reloaded-code-serdesai/src/agent_runtime/test_stubs.rssrc/reloaded-code-serdesai/src/lib.rs
💤 Files with no reviewable changes (1)
- src/reloaded-code-agents/src/runtime/mod.rs
The `[ToolBuildContext]` link reference at the end of the README was never used - all occurrences of ToolBuildContext in the document are inside a Rust code block, where Markdown references don't render.
- Removed `[Agents]`, `[agent files]`, `[`ToolFactory`]`, `[`ToolContext`]` link definitions that had no corresponding references in the document.
Dropped `[ToolContext::name]` and `[ToolPrompt]` link definitions from `src/reloaded-code-core/README.md` because they had no corresponding references elsewhere in the document.
…lization - Remove stale "(this function only handles standard tools)" note from attach_standard_tools - Add UnknownCustomTool and CustomToolDowncastFailed variants to attach_standard_tools docs - Propagate the same two variants to AgentBuildContext::build and build_agent docs - Use intra-doc link style [ToolCatalogKind::Custom] for consistency
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/reloaded-code-serdesai/src/agent_runtime/task.rs (1)
348-348: ⚡ Quick winAdd targeted tests for custom-tool error paths wired here.
Line 348 introduces the custom-tool registry into build materialization, but this module’s tests don’t currently exercise
UnknownCustomTool/CustomToolDowncastFailedpaths. Adding two focused tests here would lock in this contract and prevent silent regressions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/reloaded-code-serdesai/src/agent_runtime/task.rs` at line 348, Add two unit tests that exercise the custom-tool error paths invoked via context.runtime.custom_tool_registry(): one test should simulate a missing custom tool in the registry and assert that the code returns/propagates UnknownCustomTool, and the other should simulate a tool present but failing type conversion and assert CustomToolDowncastFailed is returned; implement these by constructing a test Runtime/Context with a fake custom_tool_registry() that either lacks the tool key or returns a boxed object that will fail the downcast, then call the same build/materialization entrypoint used in production and assert the exact error variants are produced.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/reloaded-code-serdesai/src/agent_runtime/task.rs`:
- Line 348: Add two unit tests that exercise the custom-tool error paths invoked
via context.runtime.custom_tool_registry(): one test should simulate a missing
custom tool in the registry and assert that the code returns/propagates
UnknownCustomTool, and the other should simulate a tool present but failing type
conversion and assert CustomToolDowncastFailed is returned; implement these by
constructing a test Runtime/Context with a fake custom_tool_registry() that
either lacks the tool key or returns a boxed object that will fail the downcast,
then call the same build/materialization entrypoint used in production and
assert the exact error variants are produced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a85273ba-c0ca-41e2-88ca-efe28c8a5e22
📒 Files selected for processing (5)
docs/src/tools.mdsrc/reloaded-code-agents/README.mdsrc/reloaded-code-core/README.mdsrc/reloaded-code-serdesai/src/agent_runtime/build.rssrc/reloaded-code-serdesai/src/agent_runtime/task.rs
💤 Files with no reviewable changes (1)
- src/reloaded-code-core/README.md
✅ Files skipped from review due to trivial changes (1)
- src/reloaded-code-agents/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
- src/reloaded-code-serdesai/src/agent_runtime/build.rs
What's new
You can now write a custom tool once and use it with any ReloadedCode adapter, such as
reloaded-code-serdesaior future integrations.How it works
We moved the shared tool catalog into
reloaded-code-coreand added a clean registration API. Here's an example using SerdesAI:The SerdesAI build layer will look up the factory, and call
create(),downcasting to the framework's tool trait.
If something goes wrong, you get clear errors:
UnknownCustomToolif a catalogentry has no registered factory, or
CustomToolDowncastFailedif the type doesn't match.