Files
Tyler Slaton 36020b061f feat(examples): add Claude Agent SDK starters (Python + TypeScript)
Two clonable starter templates showing CopilotKit driving a Claude Agent SDK
agent over AG-UI, mirroring the langgraph-python showcase (todos canvas, charts,
flight cards, dynamic dashboards, HITL, theme, threads drawer).

Each agent is a thin, idiomatic layer on the official ag-ui-claude-sdk /
@ag-ui/claude-agent-sdk adapters: three backend tools (query_data, search_flights,
generate_a2ui) live in per-tool modules and are wired into ClaudeAgentAdapter,
while the shared todo board is driven by the adapter's built-in ag_ui_update_state
tool. The default model is claude-sonnet-5 and local dev uses a real
ANTHROPIC_API_KEY (matching the official AG-UI dojo). Both instances are
registered in the _parity manifest so their frontends stay synced with the
langgraph-python north-star.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 17:27:28 -07:00

37 lines
1.1 KiB
Python

"""query_data tool — returns rows from the sample financial database."""
from __future__ import annotations
import csv
import json
from pathlib import Path
from typing import Any
from claude_agent_sdk import tool
# Read the CSV once at import. The notes column can contain unquoted commas, so
# keep the first N-1 fields and join the remainder into the last column.
_CSV_PATH = Path(__file__).parent / "db.csv"
with open(_CSV_PATH, newline="") as _f:
_reader = csv.reader(_f)
_header = next(_reader)
_last = len(_header) - 1
_CACHED_DATA = [
{
**{_header[i]: (row[i] if i < len(row) else "") for i in range(_last)},
_header[_last]: ",".join(row[_last:]),
}
for row in _reader
if row
]
@tool(
"query_data",
"Query the financial database with a natural-language query. Always call "
"this before rendering a chart so the UI has data to plot.",
{"query": str},
)
async def query_data(args: dict[str, Any]) -> dict[str, Any]:
return {"content": [{"type": "text", "text": json.dumps(_CACHED_DATA)}]}