Skip to content

packages/tool-registry: add ToolRegistry and AgenticSession#2008

Open
lex00 wants to merge 3 commits intotemporalio:mainfrom
lex00:feat/tool-registry
Open

packages/tool-registry: add ToolRegistry and AgenticSession#2008
lex00 wants to merge 3 commits intotemporalio:mainfrom
lex00:feat/tool-registry

Conversation

@lex00
Copy link
Copy Markdown

@lex00 lex00 commented Apr 13, 2026

What was changed

New @temporalio/tool-registry package for running LLM tool-calling loops inside Temporal activities.

  • ToolRegistry — maps tool names to JSON Schema definitions and handler functions
  • runToolLoop — standalone tool loop, no Temporal worker required
  • agenticSession — crash-safe helper that checkpoints conversation history via activity.heartbeat() on each turn and restores on retry; session survives both activity crashes and provider-side session expiry since state is stored locally
  • Built-in Anthropic and OpenAI providers
  • MockProvider and ResponseBuilder for unit testing without a live API key
  • MCP tool import via ToolRegistry.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: true on 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-registry runs 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-sdk when you are already using the Vercel AI SDK; use @temporalio/tool-registry for direct Anthropic/OpenAI calls or cross-SDK portability.

Proposal: temporalio/proposals#107

Checklist

  1. Related to: Add ToolRegistry + AgenticSession proposal proposals#107
  2. How was this tested: unit tests with MockProvider (no API key required); integration tests against live Anthropic and OpenAI APIs gated on RUN_INTEGRATION_TESTS=1 (skipped by default)
  3. Any docs updates needed? Yes — docs.temporal.io update to follow after merge

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lex00 lex00 requested a review from a team as a code owner April 13, 2026 03:53
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 13, 2026

CLA assistant check
All committers have signed the CLA.

lex00 and others added 2 commits April 12, 2026 23:23
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants