Skip to content

contrib/toolregistry: add ToolRegistry and AgenticSession#2292

Open
lex00 wants to merge 5 commits intotemporalio:masterfrom
lex00:feat/tool-registry
Open

contrib/toolregistry: add ToolRegistry and AgenticSession#2292
lex00 wants to merge 5 commits intotemporalio:masterfrom
lex00:feat/tool-registry

Conversation

@lex00
Copy link
Copy Markdown

@lex00 lex00 commented Apr 13, 2026

What was changed

New contrib/toolregistry 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
  • RunWithSession — crash-safe wrapper that checkpoints conversation history via RecordHeartbeat on each turn and restores on retry; session survives both activity crashes and provider-side session expiry since state is stored locally
  • Built-in AnthropicProvider and OpenAIProvider
  • MockProvider for unit testing without a live API key
  • FromMCPTools — converts a list of MCP tool descriptors into a populated registry

Bug fix included

The Anthropic provider now sets is_error: true on tool result maps when a handler returns an error, matching the Anthropic API spec and letting the model distinguish a failed tool invocation from a tool that returned an error string. 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. Go has no framework-level LLM integration (Python's openai_agents/google_adk_agents and TypeScript's @temporalio/ai-sdk are Python/TypeScript only), so this is the recommended path for direct Anthropic/OpenAI calls in Go.

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); new providers_test.go tests is_error propagation using httptest.NewServer; integration tests gated on RUN_INTEGRATION_TESTS=1
  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 4 commits April 12, 2026 22:40
Adds MCPTool struct and FromMCPTools constructor that converts a list of
MCP tool descriptors into a populated ToolRegistry. Handlers default to
no-ops; callers override with Register after construction. Nil InputSchema
is normalized to an empty object schema.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ests

- Set is_error=true on Anthropic tool result maps when a handler returns
  an error, matching the Anthropic API spec; OpenAI has no equivalent field
- Add providers_test.go with tests for is_error propagation on handler
  error and absence of is_error on successful handlers
- Update README to clarify positioning vs Python/TypeScript framework plugins

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…async dispatch, timeout docs

- Rename AgenticSession.Issues → Results and MarshalIssue → MarshalResult across
  session.go, testing.go, and all test files
- Remove the unused system string parameter from RunToolLoop and
  AgenticSession.RunToolLoop (system is captured at provider construction time;
  the parameter was a no-op that silently dropped caller-supplied values)
- Add ScheduleToCloseTimeout guidance to README

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The quickstart example used `issues` as the local collector variable, left
over from before the AgenticSession field was renamed to `Results` in round 2.
Rename to `results` so the example is consistent with the other SDK READMEs.

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