Skip to content

Commit 1ae1c30

Browse files
committed
docs(showcase/claude-sdk-python): region markers across 10 cells
Brings claude-sdk-python to feature parity with langgraph-python on the shell-docs snippet audit. 10 (framework x cell) targets advanced from B (missing regions) to A (ready), following the patterns established in CopilotKit#4326 (mastra), CopilotKit#4361 (smalls batch 1), CopilotKit#4363 (ms-agent), and CopilotKit#4369 (google-adk). Frontend regions (in-place markers): - agentic-chat: configure-suggestions, provider-setup - frontend-tools: frontend-tool-handler, frontend-tool-registration - headless-complete: page-send-message - open-gen-ui: minimal-provider-setup - open-gen-ui-advanced: sandbox-function-registration (multi-file: page.tsx + sandbox-functions.ts) - readonly-state-agent-context: context-provider-sketch, use-agent-context-call - tool-rendering: render-weather-tool - tool-rendering-custom-catchall: use-default-render-tool-wildcard - tool-rendering-default-catchall: default-catchall-zero-config Runtime regions (route.ts, in-place): - open-gen-ui: minimal-runtime-flag - open-gen-ui-advanced: advanced-runtime-config (both names share one block — server config is identical) Backend regions (Python, in-place): - subagents: subagent-setup wraps SUB_AGENT_PROMPTS plus _invoke_sub_agent; supervisor-delegation-tools wraps _delegation_tool_schema plus SUPERVISOR_TOOLS — captures the Claude Agent SDK idiom (Anthropic tool schemas plus a manual run loop) rather than langgraph-python's @tool/create_agent shape. Sibling teaching files (production demo carries QA hooks irrelevant to the docs page): - agentic-chat/chat-component.snippet.tsx — minimal Chat for the prebuilt-chat docs page - tool-rendering/render-flight-tool.snippet.tsx — flight + catchall renderer patterns; production demo only registers a weather renderer - tool-rendering/weather_tool.snippet.py — single-tool teaching example for the Anthropic tool-schema idiom; production agent.py declares get_weather inside a shared TOOLS list with dispatch via _execute_tool Markers are comment-only and stripped from rendered output, so the runtime demos are byte-for-byte unchanged. No manifest edits.
1 parent 88e28bd commit 1ae1c30

15 files changed

Lines changed: 223 additions & 0 deletions

File tree

showcase/integrations/claude-sdk-python/src/agents/subagents_agent.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
DEFAULT_ANTHROPIC_MODEL = "claude-3-5-sonnet-20241022"
5555

5656

57+
# @region[subagent-setup]
58+
# Each sub-agent is defined by its own system prompt; `_invoke_sub_agent`
59+
# (below) issues a single-shot Anthropic call as that sub-agent. They
60+
# don't share memory or tools with the supervisor — the supervisor only
61+
# ever sees what the sub-agent returns as a tool result.
5762
# @region[subagents-system-prompts]
5863
SUB_AGENT_PROMPTS: dict[str, str] = {
5964
"research_agent": (
@@ -89,6 +94,14 @@
8994
)
9095

9196

97+
# @region[supervisor-delegation-tools]
98+
# The supervisor delegates by calling tools. Each entry in
99+
# `SUPERVISOR_TOOLS` is an Anthropic tool schema that the supervisor LLM
100+
# "calls" to delegate work; the run loop in `run_subagents_agent` (see
101+
# the subagents-delegation-flow region) runs the matching sub-agent
102+
# synchronously, records the delegation into shared agent state, and
103+
# returns the sub-agent's output as a tool_result the supervisor can
104+
# read on its next step.
92105
def _delegation_tool_schema(name: str, description: str) -> dict[str, Any]:
93106
return {
94107
"name": name,
@@ -128,6 +141,7 @@ def _delegation_tool_schema(name: str, description: str) -> dict[str, Any]:
128141
"Delegate a critique task. Returns 2-3 actionable critiques.",
129142
),
130143
]
144+
# @endregion[supervisor-delegation-tools]
131145

132146

133147
# @region[subagents-invocation]
@@ -156,6 +170,7 @@ async def _invoke_sub_agent(
156170
raise RuntimeError("sub-agent returned empty response")
157171
return text
158172
# @endregion[subagents-invocation]
173+
# @endregion[subagent-setup]
159174

160175

161176
def _convert_messages(input_data: RunAgentInput) -> list[dict[str, Any]]:

showcase/integrations/claude-sdk-python/src/app/api/copilotkit-ogui/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export const POST = async (req: NextRequest) => {
2929
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
3030
endpoint: "/api/copilotkit-ogui",
3131
serviceAdapter: new ExperimentalEmptyAdapter(),
32+
// @region[minimal-runtime-flag]
33+
// @region[advanced-runtime-config]
3234
// Server-side config is identical for minimal and advanced cells —
3335
// the advanced behaviour (sandbox -> host function calls) is wired
3436
// entirely on the frontend via `openGenerativeUI.sandboxFunctions` on
@@ -43,6 +45,8 @@ export const POST = async (req: NextRequest) => {
4345
agents: ["open-gen-ui", "open-gen-ui-advanced"],
4446
},
4547
}),
48+
// @endregion[advanced-runtime-config]
49+
// @endregion[minimal-runtime-flag]
4650
});
4751
return await handleRequest(req);
4852
} catch (error: unknown) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Docs-only snippet — not imported or rendered. The actual route is served
2+
// by page.tsx, which carries QA hooks (frontend tools, render tools, agent
3+
// context) that aren't relevant to the prebuilt-chat docs page. This file
4+
// gives the docs a minimal Chat definition to point at via the
5+
// chat-component region without disturbing the runtime demo.
6+
//
7+
// Why a sibling file: the bundler walks every file in the demo folder and
8+
// extracts region markers from each, so a docs-targeted teaching example
9+
// can live alongside the production demo without being wired into the
10+
// route. See: showcase/scripts/bundle-demo-content.ts.
11+
12+
import {
13+
CopilotChat,
14+
useConfigureSuggestions,
15+
} from "@copilotkit/react-core/v2";
16+
17+
// @region[chat-component]
18+
export function Chat() {
19+
useConfigureSuggestions({
20+
suggestions: [
21+
{ title: "Write a sonnet", message: "Write a short sonnet about AI." },
22+
],
23+
available: "always",
24+
});
25+
26+
return <CopilotChat agentId="agentic_chat" className="h-full rounded-2xl" />;
27+
}
28+
// @endregion[chat-component]

showcase/integrations/claude-sdk-python/src/app/demos/agentic-chat/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import { z } from "zod";
1313

1414
export default function AgenticChatDemo() {
1515
return (
16+
// @region[provider-setup]
1617
<CopilotKit runtimeUrl="/api/copilotkit" agent="agentic_chat">
1718
<Chat />
1819
</CopilotKit>
20+
// @endregion[provider-setup]
1921
);
2022
}
2123

@@ -68,6 +70,7 @@ function Chat() {
6870
},
6971
});
7072

73+
// @region[configure-suggestions]
7174
useConfigureSuggestions({
7275
suggestions: [
7376
{
@@ -81,6 +84,7 @@ function Chat() {
8184
],
8285
available: "always",
8386
});
87+
// @endregion[configure-suggestions]
8488

8589
return (
8690
<div

showcase/integrations/claude-sdk-python/src/app/demos/frontend-tools/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function Chat() {
2222
"var(--copilot-kit-background-color)",
2323
);
2424

25+
// @region[frontend-tool-registration]
2526
useFrontendTool({
2627
name: "change_background",
2728
description:
@@ -31,14 +32,17 @@ function Chat() {
3132
.string()
3233
.describe("The CSS background value. Prefer gradients."),
3334
}),
35+
// @region[frontend-tool-handler]
3436
handler: async ({ background }: { background: string }) => {
3537
setBackground(background);
3638
return {
3739
status: "success",
3840
message: `Background changed to ${background}`,
3941
};
4042
},
43+
// @endregion[frontend-tool-handler]
4144
});
45+
// @endregion[frontend-tool-registration]
4246

4347
useConfigureSuggestions({
4448
suggestions: [

showcase/integrations/claude-sdk-python/src/app/demos/headless-complete/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default function HeadlessCompleteDemo() {
5151
}
5252

5353
function Chat() {
54+
// @region[page-send-message]
5455
const threadId = useMemo(() => crypto.randomUUID(), []);
5556
const { agent } = useAgent({ agentId: AGENT_ID, threadId });
5657
const { copilotkit } = useCopilotKit();
@@ -101,6 +102,7 @@ function Chat() {
101102
}
102103
// eslint-disable-next-line react-hooks/exhaustive-deps
103104
}, [agent]);
105+
// @endregion[page-send-message]
104106

105107
return (
106108
<CopilotChatConfigurationProvider agentId={AGENT_ID} threadId={threadId}>

showcase/integrations/claude-sdk-python/src/app/demos/open-gen-ui-advanced/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import { openGenUiSuggestions } from "./suggestions";
2323

2424
export default function OpenGenUiAdvancedDemo() {
2525
return (
26+
// @region[sandbox-function-registration]
27+
// Pass the sandbox-function array on the `openGenerativeUI` provider prop.
28+
// The built-in `OpenGenerativeUIActivityRenderer` wires these as callable
29+
// remotes inside the agent-authored iframe.
2630
<CopilotKit
2731
runtimeUrl="/api/copilotkit-ogui"
2832
agent="open-gen-ui-advanced"
@@ -34,6 +38,7 @@ export default function OpenGenUiAdvancedDemo() {
3438
</div>
3539
</div>
3640
</CopilotKit>
41+
// @endregion[sandbox-function-registration]
3742
);
3843
}
3944

showcase/integrations/claude-sdk-python/src/app/demos/open-gen-ui-advanced/sandbox-functions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z } from "zod";
22

3+
// @region[sandbox-function-registration]
34
/**
45
* Host-side functions that agent-authored, sandboxed UIs can invoke from
56
* inside the iframe via `Websandbox.connection.remote.<name>(args)`.
@@ -54,3 +55,4 @@ export const openGenUiSandboxFunctions = [
5455
},
5556
},
5657
];
58+
// @endregion[sandbox-function-registration]

showcase/integrations/claude-sdk-python/src/app/demos/open-gen-ui/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ const minimalSuggestions = [
8787

8888
export default function OpenGenUiDemo() {
8989
return (
90+
// @region[minimal-provider-setup]
91+
// Minimal Open Generative UI frontend: the built-in activity renderer is
92+
// registered by CopilotKitProvider, so a plain <CopilotChat /> is enough —
93+
// no custom tool renderers, no activity-renderer registration.
94+
// We DO pass `openGenerativeUI.designSkill` to swap in visualisation-tuned
95+
// guidance in place of the default shadcn design skill.
9096
<CopilotKit
9197
runtimeUrl="/api/copilotkit-ogui"
9298
agent="open-gen-ui"
@@ -98,6 +104,7 @@ export default function OpenGenUiDemo() {
98104
</div>
99105
</div>
100106
</CopilotKit>
107+
// @endregion[minimal-provider-setup]
101108
);
102109
}
103110

showcase/integrations/claude-sdk-python/src/app/demos/readonly-state-agent-context/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ const ACTIVITIES = [
3737
];
3838

3939
function DemoContent() {
40+
// @region[context-provider-sketch]
4041
const [userName, setUserName] = useState("Atai");
4142
const [userTimezone, setUserTimezone] = useState("America/Los_Angeles");
4243
const [recentActivity, setRecentActivity] = useState<string[]>([
4344
ACTIVITIES[0],
4445
ACTIVITIES[2],
4546
]);
47+
// @endregion[context-provider-sketch]
4648

49+
// @region[use-agent-context-call]
4750
useAgentContext({
4851
description: "The currently logged-in user's display name",
4952
value: userName,
@@ -56,6 +59,7 @@ function DemoContent() {
5659
description: "The user's recent activity in the app, newest first",
5760
value: recentActivity,
5861
});
62+
// @endregion[use-agent-context-call]
5963

6064
useConfigureSuggestions({
6165
suggestions: [

0 commit comments

Comments
 (0)