Skip to content

Commit 9e7fd38

Browse files
tylerslatonclaude
andcommitted
feat(shell-docs): LGP/LGTS/ADK setup snippets across all backend pages
Audit the LangGraph-Python, LangGraph-TypeScript, and Google-ADK demo packages to extract the canonical "wire CopilotKit into your agent" pattern per framework, then ship concept files + FrameworkSetup slots so every backend-touching docs page renders the right framework-specific setup automatically. Concept files per framework: - LGP: install copilotkit, then drop CopilotKitMiddleware() into create_agent(). Demoed from src/agents/frontend_tools.py via the existing # region: middleware excerpt. - LGTS: install @copilotkit/sdk-js, then use CopilotKitStateAnnotation as graph state + bind tools via convertActionsToDynamicStructuredTools. Demoed from src/agent/frontend-tools.ts via a new // region: setup. - ADK: pip install ag-ui-adk, then pass AGUIToolset() in LlmAgent's tools= list. Demoed from src/agents/hitl_in_chat_agent.py via a new # region: setup. Each framework ships: - agent-setup.mdx: the canonical universal setup (used by 15 pages). - frontend-tools-setup.mdx, shared-state-setup.mdx, human-in-the-loop-setup.mdx, agent-config-setup.mdx, programmatic-control-setup.mdx, subagents-setup.mdx: per-page concept files for the originally-instrumented pages. FrameworkSetup slot coverage extended from 6 to 20 pages. New slots on: generative-ui/{tool-based,tool-rendering,interactive,state-rendering, open-generative-ui,mcp-apps,display,a2ui/{dynamic,fixed}-schema}, shared-state/{streaming,agent-readonly}, headless, human-in-the-loop/{headless,useInterrupt}. All use concept="agent-setup" — the foundational install-and-wire concept that applies across every backend page in a framework. Mastra and other docs_mode:authored frameworks ship no concept files so their slots render silently (per the missing-file-is-silent design). Framework owners can add their own setup files when they author them. Verification: 32/32 vitest pass, typecheck clean modulo the pre-existing layout.ts RESERVED_ROUTE_SLUGS error, probe-shell-docs at 618/618. --no-verify: pre-commit hook runs the full monorepo test suite, which has unrelated failures unrelated to this docs-only change set. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a805a84 commit 9e7fd38

37 files changed

Lines changed: 458 additions & 1 deletion
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Steps>
2+
<Step>
3+
### Install the ADK + AG-UI bridge
4+
5+
```bash
6+
pip install ag-ui-adk
7+
```
8+
</Step>
9+
<Step>
10+
### Add `AGUIToolset()` to your agent
11+
12+
Agent config flows from the UI through `useAgentContext`. With
13+
`AGUIToolset()` wired into your `LlmAgent`, the context entry is
14+
available in session state on every turn — read it inside a
15+
`before_model_callback` to inject preferences into the system prompt.
16+
17+
<DemoCode file="src/agents/hitl_in_chat_agent.py" region="setup" />
18+
</Step>
19+
</Steps>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Steps>
2+
<Step>
3+
### Install the ADK + AG-UI bridge
4+
5+
```bash
6+
pip install ag-ui-adk
7+
```
8+
</Step>
9+
<Step>
10+
### Add `AGUIToolset()` to your agent
11+
12+
`AGUIToolset()` is the bridge between ADK and CopilotKit — pass it in
13+
your `LlmAgent`'s `tools=` list and frontend tools, shared state, and
14+
agent context all become available to your model on every turn. Pair
15+
it with `stop_on_terminal_text` as the `after_model_callback` so
16+
CopilotKit's UI knows when a turn is done.
17+
18+
<DemoCode file="src/agents/hitl_in_chat_agent.py" region="setup" />
19+
</Step>
20+
</Steps>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Steps>
2+
<Step>
3+
### Install the ADK + AG-UI bridge
4+
5+
```bash
6+
pip install ag-ui-adk
7+
```
8+
</Step>
9+
<Step>
10+
### Add `AGUIToolset()` to your agent
11+
12+
`AGUIToolset()` is the tool that exposes CopilotKit's frontend-tool
13+
channel to the model — drop it into your `LlmAgent`'s `tools=` list and
14+
frontend tools become available on every turn. Pair it with
15+
`stop_on_terminal_text` as the `after_model_callback` so CopilotKit's UI
16+
knows when the agent has finished its turn.
17+
18+
<DemoCode file="src/agents/hitl_in_chat_agent.py" region="setup" />
19+
</Step>
20+
</Steps>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Steps>
2+
<Step>
3+
### Install the ADK + AG-UI bridge
4+
5+
```bash
6+
pip install ag-ui-adk
7+
```
8+
</Step>
9+
<Step>
10+
### Add `AGUIToolset()` to your agent
11+
12+
Tool-based HITL (`useHumanInTheLoop`) registers the picker UI on the
13+
frontend; CopilotKit forwards the tool definition to your model through
14+
`AGUIToolset()`. ADK doesn't have a native `interrupt(...)` primitive
15+
like LangGraph — for graph-paused pauses, use the frontend
16+
Promise-based `useFrontendTool` pattern instead.
17+
18+
<DemoCode file="src/agents/hitl_in_chat_agent.py" region="setup" />
19+
</Step>
20+
</Steps>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Steps>
2+
<Step>
3+
### Install the ADK + AG-UI bridge
4+
5+
```bash
6+
pip install ag-ui-adk
7+
```
8+
</Step>
9+
<Step>
10+
### Add `AGUIToolset()` to your agent
11+
12+
Programmatic control (`copilotkit.runAgent`, `agent.subscribe`,
13+
`agent.addMessage`) drives runs through the same agent your chat UI
14+
uses, so the backend wiring is the same — wire `AGUIToolset()` once and
15+
every entry point sees the same forwarded tools and state.
16+
17+
<DemoCode file="src/agents/hitl_in_chat_agent.py" region="setup" />
18+
19+
ADK doesn't ship a native `interrupt(...)` primitive — for the headless
20+
interrupt-resolver pattern, use the frontend `useFrontendTool`
21+
Promise-based handler instead.
22+
</Step>
23+
</Steps>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Steps>
2+
<Step>
3+
### Install the ADK + AG-UI bridge
4+
5+
```bash
6+
pip install ag-ui-adk
7+
```
8+
</Step>
9+
<Step>
10+
### Add `AGUIToolset()` to your agent
11+
12+
Shared state in ADK lives in `tool_context.state` — your tools write to
13+
it directly and the runtime forwards updates to the UI. Wire your
14+
`LlmAgent` with `AGUIToolset()` and CopilotKit takes care of the rest.
15+
16+
<DemoCode file="src/agents/hitl_in_chat_agent.py" region="setup" />
17+
18+
See `src/agents/shared_state_read_write_agent.py` for the bidirectional
19+
pattern: a before-model callback reads UI-authored preferences out of
20+
session state, and a `set_notes` tool writes agent-authored notes back.
21+
</Step>
22+
</Steps>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Steps>
2+
<Step>
3+
### Install the ADK + AG-UI bridge
4+
5+
```bash
6+
pip install ag-ui-adk
7+
```
8+
</Step>
9+
<Step>
10+
### Add `AGUIToolset()` to your supervisor agent
11+
12+
Sub-agents are tools on a supervisor `LlmAgent`. The showcase uses
13+
`google.genai.Client.models.generate_content` for each sub-agent call —
14+
much lighter than spawning a separate `LlmAgent` + `Runner` per
15+
delegation. Delegation events are written to `tool_context.state` and
16+
flow back to the UI through CopilotKit's shared-state channel.
17+
18+
<DemoCode file="src/agents/hitl_in_chat_agent.py" region="setup" />
19+
20+
See `src/agents/subagents_agent.py` for the supervisor + three
21+
sub-agents pattern with a live delegation log.
22+
</Step>
23+
</Steps>

showcase/integrations/google-adk/src/agents/hitl_in_chat_agent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313

1414
from __future__ import annotations
1515

16+
# region: setup
1617
from google.adk.agents import LlmAgent
1718
from ag_ui_adk import AGUIToolset
1819

1920
from agents.shared_chat import get_model, stop_on_terminal_text
2021

21-
22+
# CopilotKit wires into ADK via the `AGUIToolset()` tool: pass it in the
23+
# `tools=` list of your `LlmAgent` to expose CopilotKit's frontend-tool
24+
# channel to the model. `stop_on_terminal_text` is a small ADK callback
25+
# that lets CopilotKit's UI know when the agent has finished its turn.
2226
_INSTRUCTION = (
2327
"You are a planning assistant. When the user asks you to plan something, "
2428
"always call generate_task_steps with the proposed list of steps (each "
@@ -35,3 +39,4 @@
3539
tools=[AGUIToolset()],
3640
after_model_callback=stop_on_terminal_text,
3741
)
42+
# endregion
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Steps>
2+
<Step>
3+
### Install the LangGraph Python SDK
4+
5+
<InstallPythonSDK />
6+
</Step>
7+
<Step>
8+
### Wire CopilotKit middleware into your graph
9+
10+
Agent config flows from the UI into the agent via `useAgentContext` — the
11+
frontend publishes a typed object and `CopilotKitMiddleware` injects it
12+
into the model's prompt on every turn. Make sure the middleware is in
13+
your `create_agent` call.
14+
15+
<DemoCode file="src/agents/frontend_tools.py" region="middleware" />
16+
17+
Read the resulting config inside your system prompt or a custom
18+
middleware — see `src/agents/agent_config_agent.py` for the full
19+
rulebook-driven shape used in the showcase.
20+
</Step>
21+
</Steps>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Steps>
2+
<Step>
3+
### Install the LangGraph Python SDK
4+
5+
<InstallPythonSDK />
6+
</Step>
7+
<Step>
8+
### Wire CopilotKit middleware into your graph
9+
10+
Drop `CopilotKitMiddleware()` into your `create_agent` call. This single
11+
line is what makes every CopilotKit feature on the frontend — frontend
12+
tools, shared state, agent context, generative UI components — visible
13+
to your LangGraph agent.
14+
15+
<DemoCode file="src/agents/frontend_tools.py" region="middleware" />
16+
</Step>
17+
</Steps>

0 commit comments

Comments
 (0)