contrib/toolregistry: add ToolRegistry and AgenticSession#2292
Open
lex00 wants to merge 5 commits intotemporalio:masterfrom
Open
contrib/toolregistry: add ToolRegistry and AgenticSession#2292lex00 wants to merge 5 commits intotemporalio:masterfrom
lex00 wants to merge 5 commits intotemporalio:masterfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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>
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
contrib/toolregistrypackage 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 requiredRunWithSession— crash-safe wrapper that checkpoints conversation history viaRecordHeartbeaton each turn and restores on retry; session survives both activity crashes and provider-side session expiry since state is stored locallyAnthropicProviderandOpenAIProviderMockProviderfor unit testing without a live API keyFromMCPTools— converts a list of MCP tool descriptors into a populated registryBug fix included
The Anthropic provider now sets
is_error: trueon 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_agentsand TypeScript's@temporalio/ai-sdkare Python/TypeScript only), so this is the recommended path for direct Anthropic/OpenAI calls in Go.Proposal: temporalio/proposals#107
Checklist
MockProvider(no API key required); newproviders_test.gotestsis_errorpropagation usinghttptest.NewServer; integration tests gated onRUN_INTEGRATION_TESTS=1