feat(rig-core): add ToolCallContext for per-call runtime context in tool dispatch#1537
Open
redroy44 wants to merge 2 commits into0xPlaygrounds:mainfrom
Open
feat(rig-core): add ToolCallContext for per-call runtime context in tool dispatch#1537redroy44 wants to merge 2 commits into0xPlaygrounds:mainfrom
redroy44 wants to merge 2 commits into0xPlaygrounds:mainfrom
Conversation
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.
Summary
ToolCallContext, a type-erased, cloneable type-map (modeled afterhttp::Extensions'AnyClonepattern) that lets callers inject per-call runtime values (auth tokens, session IDs, conversation state) into tool executionToolServerHandle→ channel →ToolServer→ToolSet→ToolType→ToolDyn→ToolToolandToolDynimplementations continue to work without changesNew public API
ToolCallContext(struct)new(),insert<T>(),get<T>(),get_mut<T>(),remove<T>(),contains<T>(). Re-exported from crate root.Tool::call_with_context(args, &ctx)call(). Override to access context.ToolDyn::call_with_context(args, ctx)call(). Blanket impl threads toTool::call_with_context.ToolSet::call_with_context(name, args, ctx)ToolServerHandle::call_tool_with_context(name, args, ctx)No existing public API signatures were changed. No breaking changes.
Design
ToolCallContextusesOption<Box<HashMap<TypeId, Box<dyn AnyClone>>>>so empty contexts (the common path) have zero allocation. WASM-compatible viacfg(target_family = "wasm")gating onSend + Syncbounds.Delegation direction:
_with_contextmethod + empty contextTooltrait: newcall_with_contextdefault delegates tocall(ignoring context)Test plan
ToolCallContext(insert/get/get_mut/remove/clone/contains/debug/empty allocation)ToolServerdispatchcargo clippy --lib --tests -- -D warningscleancargo fmtcleanThis PR was generated with AI assistance (Claude).
Fixes #1536