contrib: add tool_registry package with AgenticSession support#1435
contrib: add tool_registry package with AgenticSession support#1435lex00 wants to merge 4 commits intotemporalio:mainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…viders - Wrap dispatch() calls in try/except in both AnthropicProvider and OpenAIProvider; handler exceptions no longer crash the activity - Set is_error=True on Anthropic tool result blocks when a handler raises, matching the Anthropic API spec; OpenAI has no equivalent field - Add tests covering handler error → is_error propagation and successful handler → no is_error - Update README feature matrix to clarify positioning vs framework plugins Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add adispatch() to ToolRegistry for async handler support; sync dispatch() raises TypeError with helpful message for async handlers; providers use adispatch - Make AnthropicProvider and OpenAIProvider run_turn/run_loop async - Rename AgenticSession.issues → results in _session.py and testing.py - Add ScheduleToCloseTimeout guidance to README - Update tests: new adispatch tests, async handler end-to-end test, fix message indices in provider tests, rename issues→results in test_agentic_session.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Shows a code review agent that proposes auto-fixes requiring human sign-off before application. The tool handler blocks on a Temporal workflow signal, heartbeating manually while waiting. Key behaviors demonstrated: - Rejection reason returned to LLM as tool result so it can revise approach - Deterministic workflow IDs make crash-retry idempotent: re-attaches to the existing approval workflow rather than sending a duplicate notification - Manual heartbeat loop inside the handler keeps the activity alive during long human review windows Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The One addition worth considering for the 1. Trust-gated tool access within the session. If the session knows the agent identity, async with agentic_session(
provider=AnthropicProvider(),
agent_id="fleet-agent-xyz",
min_tool_trust=0.80 # tools requiring higher trust are blocked for this agent
) as session:
result = await session.run_tool_loop(registry, messages)2. Per-session behavioral audit trail. Each heartbeat checkpoint is a natural attestation point — the session state at each checkpoint can include the agent identity alongside the conversation history. If the session is later audited (e.g., for EU AI Act Article 12 compliance), the checkpoints provide a timestamped, crash-survivor record of which agent made which decisions. The |
What was changed
New optional contrib package
temporalio[tool-registry]for running LLM tool-calling loops inside Temporal activities.ToolRegistry— maps tool names to JSON Schema definitions and handler functionsrun_tool_loop— standalone tool loop, no Temporal worker requiredagentic_session— crash-safe context manager 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.from_mcp_tools()Bug fix included
Handler exceptions in the initial implementation were not caught, causing them to propagate out of the activity. All six SDK providers now catch handler errors and feed them back to the model. Anthropic providers additionally set
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
openai_agents,google_adk_agents, andlanggraph. Those integrations run each model call as a separate Temporal activity using server-side session IDs.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. Useopenai_agents/google_adk_agents/langgraphwhen you are already using those frameworks; usetool_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)