← 输入框|github.com|刷新
Skip to content

Add Claude Agent SDK samples - #403

Draft
patbeqo wants to merge 2 commits into
mainfrom
claude-agent-sdk-samples
Draft

patbeqo wants to merge 2 commits into
mainfrom
claude-agent-sdk-samples

Conversation

@patbeqo

@patbeqo patbeqo commented Oct 26, 2026 •

Copy link
Copy Markdown

Draft. Depends on the unreleased temporalio-claude-agent-sdk from temporalio/ai-integrations#169, pinned to a commit on that branch. Before this leaves draft, the pin moves to the PyPI release.

Adds claude_agent_sdk_plugin/, samples for the Claude Agent SDK integration. Each Workflow is plain Claude Agent SDK code with a TemporalTransport, and every sample runs offline against a scripted API, so no key is needed.

Sample What it shows
agent_chat Multi-turn chat driven by Updates, with Continue-As-New that resumes Claude Code's session.
tools One @tool computed in the Workflow and one that runs an Activity.
streaming Token-by-token output through a Workflow Stream.
human_in_the_loop can_use_tool waits durably on an Update: approve, deny or cancel.
structured_output A JSON-schema result validated as a Pydantic model.
fork_session One conversation forked into parallel branches.
multi_agent Claude Code's native subagents: a coordinator, a researcher and a writer.
plugin_with_custom_transport A Claude Code plugin run in a Docker Sandbox by a custom Connector.
open_telemetry One trace across the Workflow, its Activities and Claude Code.

Testing

ruff, mypy and the 24 offline tests pass. Every sample's Worker was also stopped mid-turn and restarted, and each resumed with the correct result.

@@ -0,0 +1,80 @@
# Agent Chat

A multi-turn chat with Claude that lives in one Workflow. Each message is a `send_message` Update that returns Claude's reply, and `end_conversation` ends the chat. Start here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is end_conversation also an update or is it a signal?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to say its a signal.

Scripted model, no credentials. The same Worker, plugin, Workflow, and Claude Code subprocess run, and each reply counts the earlier replies Claude Code sent in its request:

```bash
CLAUDE_OFFLINE=1 uv run --group claude-agent-sdk claude_agent_sdk_plugin/agent_chat/run_worker.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make offline the default, and run it live if ANTHROPIC_API_KEY is passed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

"command": "echo 'Hello from Claude Code' > hello.txt"
},
"tool_name": "Bash",
"tool_use_id": "toolu_hello"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "toolu"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the format of the tool response from Anthropic.

Comment thread claude_agent_sdk_plugin/mcp/workflow.py Outdated
},
strict_mcp_config=True,
tools=[],
allowed_tools=["mcp__echo__echo"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all the underscores? Is this a built-in tool?

@patbeqo patbeqo Oct 28, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mcp__<mcp_name>__<tool_name> is the naming format Claude Code uses.

@@ -0,0 +1,67 @@
# Plugins

Give Claude Code your own skill by passing it a Claude Code plugin, and see Claude use it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you could also provide MCP servers with a plugin?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to include a sample for this.

Comment thread README.md Outdated
* [batch_sliding_window](batch_sliding_window) - Batch processing with a sliding window of child workflows.
* [bedrock](bedrock) - Orchestrate a chatbot with Amazon Bedrock.
* [bedrock_agentcore/strands_agent](bedrock_agentcore/strands_agent) - Run a AWS Strands Agent with Temporal Plugin on AgentCore Worker.
* [claude_agent_sdk_plugin](claude_agent_sdk_plugin) - Run Claude Code agents as durable Temporal workflows with the Claude Agent SDK (chat, tools, MCP, streaming, approvals, subagents, sandboxes, plugins).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would any other samples be useful? Maybe one for a custom transport?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few more samples.

@patbeqo
patbeqo force-pushed the claude-agent-sdk-samples branch from 2cce724 to b0c0239 Compare October 27, 2026 21:13
@patbeqo
patbeqo force-pushed the claude-agent-sdk-samples branch from b0c0239 to b5492bf Compare October 29, 2026 00:24
@patbeqo
patbeqo force-pushed the claude-agent-sdk-samples branch from b5492bf to 7a09333 Compare October 29, 2026 00:55
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