Loading...
Loading...
Build AI agent UIs using the AG-UI protocol with pydantic-ai (Python backend) and CopilotKit (React frontend). Use when creating agentic chat interfaces, human-in-the-loop workflows, generative UIs with state management, tool-based rendering, shared state between frontend and backend, or predictive state updates. Covers FastAPI integration, state events (StateSnapshotEvent, StateDeltaEvent, CustomEvent), useCoAgent hooks, useCopilotAction for tool rendering, and real-time agent-frontend synchronization.
npx skill4agent add arthrod/conejo-skills ag-ui-pydantic┌─────────────────┐ AG-UI Protocol ┌──────────────────┐
│ Pydantic AI │ ◄──────────────────────►│ CopilotKit │
│ (FastAPI) │ Events & State │ (React/Next) │
└─────────────────┘ └──────────────────┘from pydantic_ai import Agent
agent = Agent('openai:gpt-4o-mini')
app = agent.to_ag_ui() # Creates FastAPI-compatible ASGI app<CopilotKit runtimeUrl="/api/copilotkit" agent="myAgent">
<CopilotChat />
</CopilotKit>references/backend-patterns.md#agentic-chatStateDepsfrom pydantic_ai.ag_ui import StateDeps
agent = Agent('openai:gpt-4o-mini', deps_type=StateDeps[MyStateModel])
app = agent.to_ag_ui(deps=StateDeps(MyStateModel()))references/backend-patterns.md#shared-stateStateSnapshotEventStateDeltaEventCustomEventreferences/backend-patterns.md#generative-uirenderAndWaitForResponsereferences/frontend-patterns.md#human-in-the-loopreferences/backend-patterns.md#predictive-state@agent.tool_plain
async def update_ui(data: str) -> StateSnapshotEvent:
return StateSnapshotEvent(
type=EventType.STATE_SNAPSHOT,
snapshot={"field": data}
)useCoAgentconst { state, setState } = useCoAgent({
name: "myAgent",
initialState: { /* ... */ }
});references/backend-patterns.mdreferences/frontend-patterns.mdag-ui-copilotkit