feat: Claude Agent SDK with Temporal — durable agent execution#54
Open
febinct wants to merge 2 commits intotemporalio:mainfrom
Open
feat: Claude Agent SDK with Temporal — durable agent execution#54febinct wants to merge 2 commits intotemporalio:mainfrom
febinct wants to merge 2 commits intotemporalio:mainfrom
Conversation
|
Febin .Sathar seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
4c4d332 to
b8ce97d
Compare
Add a new cookbook example demonstrating how to run the Claude Agent SDK (claude-code-sdk) inside a Temporal workflow for durable agent execution. Key patterns demonstrated: - Background heartbeats via asyncio.create_task() (independent of event stream) - Staleness guard to detect hung agents (15-min idle threshold) - Response deduplication (AssistantMessage vs StreamEvent) - Errors modeled as completions (not exceptions) Includes workflow tests (mocked activities) and activity tests (mocked SDK). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b8ce97d to
496316e
Compare
Capture session_id from SystemMessage(init) events and support resuming conversations via --resume flag. The SDK stores sessions as JSONL files on disk; passing resume_session_id tells it to continue from a previous session. Co-Authored-By: Claude Opus 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.
Summary
Adds a new cookbook example (
agents/claude_agent_sdk_python/) demonstrating how to run the Claude Agent SDK (claude-code-sdk) inside a Temporal workflow for durable, observable agent execution.Unlike the existing
agentic_loop_tool_call_claude_pythonexample that builds a manual tool-calling loop with the Messages API, this example delegates the entire agentic loop to the Claude Agent SDK — the SDK handles tool selection, execution, and multi-turn conversation internally. The Temporal activity wraps this as a single long-running operation with streaming event collection.Key patterns demonstrated
asyncio.create_task()sends Temporal heartbeats every 60s, independent of the SDK event stream. Critical for long-running tools (e.g., git operations) that emit no events for extended periods.StreamEvent(incremental chunks) andAssistantMessage(complete blocks) with the same text. OnlyAssistantMessageis accumulated to avoid doubling the response.AgentOutput(status="error")rather than raising exceptions.Files
README.mdmodels.pyactivities/agent_executor.pyworkflows/agent.pyworker.pystart_workflow.pytests/test_workflow.pytests/test_activity.pyContext
These patterns were developed running Claude Agent SDK in production with Temporal for Slack-triggered and webhook-triggered agent execution. The three key patterns (heartbeats, staleness, dedup) solved real production issues — we stripped them down to a minimal, self-contained cookbook example.
Test plan
uv syncresolves dependenciesuv sync --extra test && uv run pytest tests/ -vpasses all testsuv run python -m workerstarts successfully (with local Temporal)uv run python -m start_workflow "hello"executes and returns a response🤖 Generated with Claude Code