Skip to content

Commit 0525749

Browse files
committed
docs(showcase/langgraph-fastapi): region markers for agentic-chat + tool-rendering
Same pattern as langgraph-typescript. The weather-tool-backend region already existed in src/agents/src/tool_rendering_agent.py; just added the file to the manifest highlight so the bundler picks it up.
1 parent 51de3d4 commit 0525749

5 files changed

Lines changed: 124 additions & 0 deletions

File tree

showcase/integrations/langgraph-fastapi/manifest.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ demos:
7878
- agent-capabilities
7979
route: /demos/tool-rendering
8080
animated_preview_url:
81+
highlight:
82+
- src/agents/src/tool_rendering_agent.py
83+
- src/app/demos/tool-rendering/page.tsx
8184
- id: hitl
8285
name: In-Chat Human in the Loop (Original)
8386
description: User approves agent actions before execution
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/langgraph-fastapi/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/langgraph-fastapi/src/app/demos/tool-rendering/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function ToolRenderingDemo() {
2727
}
2828

2929
function Chat() {
30+
// @region[render-weather-tool]
3031
useRenderTool({
3132
name: "get_weather",
3233
parameters: z.object({
@@ -61,6 +62,7 @@ function Chat() {
6162
);
6263
},
6364
});
65+
// @endregion[render-weather-tool]
6466

6567
useConfigureSuggestions({
6668
suggestions: [
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Docs-only snippet — not imported or rendered. Mastra's tool-rendering
2+
// demo at page.tsx exercises the get_weather renderer only; the docs
3+
// page at /generative-ui/tool-rendering also teaches the search_flights
4+
// per-tool pattern and the wildcard catch-all. These two regions show
5+
// what those would look like in the same Mastra demo shape, so the
6+
// docs can render real teaching code rather than a missing-snippet box.
7+
//
8+
// See chat-component.snippet.tsx in agentic-chat for the same pattern.
9+
10+
import { useRenderTool, useDefaultRenderTool } from "@copilotkit/react-core/v2";
11+
import { z } from "zod";
12+
13+
type CatchallToolStatus = "in_progress" | "complete" | "error";
14+
15+
interface FlightSearchResult {
16+
origin?: string;
17+
destination?: string;
18+
flights?: unknown[];
19+
}
20+
21+
function FlightListCard(_props: {
22+
loading: boolean;
23+
origin: string;
24+
destination: string;
25+
flights: unknown[];
26+
}) {
27+
return null;
28+
}
29+
30+
function CustomCatchallRenderer(_props: {
31+
name: string;
32+
parameters: unknown;
33+
status: CatchallToolStatus;
34+
result: unknown;
35+
}) {
36+
return null;
37+
}
38+
39+
function parseJsonResult<T>(_result: unknown): T {
40+
return {} as T;
41+
}
42+
43+
export function FlightToolRenderers() {
44+
// @region[render-flight-tool]
45+
// Per-tool renderer: search_flights → branded FlightListCard.
46+
useRenderTool(
47+
{
48+
name: "search_flights",
49+
parameters: z.object({
50+
origin: z.string(),
51+
destination: z.string(),
52+
}),
53+
render: ({ parameters, result, status }) => {
54+
const loading = status !== "complete";
55+
const parsed = parseJsonResult<FlightSearchResult>(result);
56+
return (
57+
<FlightListCard
58+
loading={loading}
59+
origin={parameters?.origin ?? parsed.origin ?? ""}
60+
destination={parameters?.destination ?? parsed.destination ?? ""}
61+
flights={parsed.flights ?? []}
62+
/>
63+
);
64+
},
65+
},
66+
[],
67+
);
68+
// @endregion[render-flight-tool]
69+
70+
// @region[catchall-renderer]
71+
// Wildcard catch-all for every remaining tool — anything the agent might
72+
// call that doesn't have a dedicated useRenderTool registration.
73+
useDefaultRenderTool(
74+
{
75+
render: ({ name, parameters, status, result }) => (
76+
<CustomCatchallRenderer
77+
name={name}
78+
parameters={parameters}
79+
status={status as CatchallToolStatus}
80+
result={result}
81+
/>
82+
),
83+
},
84+
[],
85+
);
86+
// @endregion[catchall-renderer]
87+
}

0 commit comments

Comments
 (0)