packages/tool-registry: add ToolRegistry and AgenticSession#2008
Open
lex00 wants to merge 3 commits intotemporalio:mainfrom
Open
packages/tool-registry: add ToolRegistry and AgenticSession#2008lex00 wants to merge 3 commits intotemporalio:mainfrom
lex00 wants to merge 3 commits intotemporalio:mainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Apr 13, 2026
…viders - Wrap dispatch() calls in try/catch in both AnthropicProvider and OpenAIProvider; handler exceptions no longer propagate out of the loop - Set is_error=true on Anthropic tool result blocks when a handler throws, matching the Anthropic API spec; OpenAI has no equivalent field - Add tests covering handler error → is_error and no is_error on success - Update README feature matrix to clarify positioning vs framework plugins Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Update ToolHandler type to string | Promise<string>; make dispatch() async - Update FakeToolRegistry.dispatch to async; both providers await registry.dispatch - AnthropicProvider uses Promise.all for parallel async tool dispatch - Rename AgenticSession.issues → results and CheckpointState.issues → results across session.ts, testing.ts, and all test files - Add ScheduleToCloseTimeout guidance to README - Add async handler test to registry.test.ts; fix testing.test.ts assertions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
What was changed
New
@temporalio/tool-registrypackage for running LLM tool-calling loops inside Temporal activities.ToolRegistry— maps tool names to JSON Schema definitions and handler functionsrunToolLoop— standalone tool loop, no Temporal worker requiredagenticSession— crash-safe helper that checkpoints conversation history viaactivity.heartbeat()on each turn and restores on retry; session survives both activity crashes and provider-side session expiry since state is stored locallyMockProviderandResponseBuilderfor unit testing without a live API keyToolRegistry.fromMcpTools()Bug fix included
Handler exceptions were not caught, causing them to propagate out of the activity. Both providers now catch handler errors and feed them back to the model. The Anthropic provider additionally sets
is_error: trueon the tool result block (per the Anthropic API spec); OpenAI has no equivalent field.Why?
Temporal activities are a natural fit for LLM tool-calling loops, but every team reimplements the same boilerplate. This contrib package standardizes the pattern across all six Temporal SDKs.
This is a different layer from
@temporalio/ai-sdk. That integration runs each model call as a separate Temporal activity using Vercel AI SDK abstractions.@temporalio/tool-registryruns the entire conversation in one activity using local heartbeat state — which survives server-side session expiry and works identically across all six SDKs. Use@temporalio/ai-sdkwhen you are already using the Vercel AI SDK; use@temporalio/tool-registryfor direct Anthropic/OpenAI calls or cross-SDK portability.Proposal: temporalio/proposals#107
Checklist
MockProvider(no API key required); integration tests against live Anthropic and OpenAI APIs gated onRUN_INTEGRATION_TESTS=1(skipped by default)