Skip to content

Commit 0f7dc73

Browse files
committed
feat: PydanticAI support
Add support for the PydanticAI integration. Add missing background change confirmation. Increase agentic generation ui page size to allow it to display results from the PydanticAI integration better. Add a description for the human in the loop generate_task_steps tool, so the PydanticAI example works as expected. Merge write_document and confirm_changes tool into one, which allows it work correctly with the PydanticAI example, without the need for the agent to perform two separate tool calls. Sort the features, so they are easier to find when reading the code and implementing new integrations. Fixes: #5
1 parent 32a74f0 commit 0f7dc73

File tree

17 files changed

+391
-49
lines changed

17 files changed

+391
-49
lines changed

typescript-sdk/apps/dojo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@ag-ui/llamaindex": "workspace:*",
1717
"@ag-ui/mastra": "workspace:*",
1818
"@ag-ui/middleware-starter": "workspace:*",
19+
"@ag-ui/pydantic-ai": "workspace:*",
1920
"@ag-ui/server-starter": "workspace:*",
2021
"@ag-ui/server-starter-all-features": "workspace:*",
2122
"@ag-ui/vercel-ai-sdk": "workspace:*",

typescript-sdk/apps/dojo/src/agents.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AgnoAgent } from "@ag-ui/agno";
1313
import { LlamaIndexAgent } from "@ag-ui/llamaindex";
1414
import { CrewAIAgent } from "@ag-ui/crewai";
1515
import { mastra } from "./mastra";
16+
import { PydanticAIAgent } from "@ag-ui/pydantic-ai";
1617

1718
export const agentsIntegrations: AgentIntegrationConfig[] = [
1819
{
@@ -23,6 +24,31 @@ export const agentsIntegrations: AgentIntegrationConfig[] = [
2324
};
2425
},
2526
},
27+
{
28+
id: "pydantic-ai",
29+
agents: async () => {
30+
return {
31+
agentic_chat: new PydanticAIAgent({
32+
url: "http://localhost:9000/agentic_chat/",
33+
}),
34+
agentic_generative_ui: new PydanticAIAgent({
35+
url: "http://localhost:9000/agentic_generative_ui/",
36+
}),
37+
human_in_the_loop: new PydanticAIAgent({
38+
url: "http://localhost:9000/human_in_the_loop/",
39+
}),
40+
predictive_state_updates: new PydanticAIAgent({
41+
url: "http://localhost:9000/predictive_state_updates/",
42+
}),
43+
shared_state: new PydanticAIAgent({
44+
url: "http://localhost:9000/shared_state/",
45+
}),
46+
tool_based_generative_ui: new PydanticAIAgent({
47+
url: "http://localhost:9000/tool_based_generative_ui/",
48+
}),
49+
};
50+
},
51+
},
2652
{
2753
id: "server-starter",
2854
agents: async () => {

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/agentic_chat/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const Chat = () => {
4242
],
4343
handler: ({ background }) => {
4444
setBackground(background);
45+
return {
46+
status: "success",
47+
message: `Background changed to ${background}`,
48+
};
4549
},
4650
});
4751

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/agentic_generative_ui/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const Chat = () => {
4242

4343
return (
4444
<div className="flex">
45-
<div className="bg-gray-100 rounded-lg w-[500px] p-4 text-black space-y-2">
45+
<div className="bg-gray-100 rounded-lg w-[800px] p-4 text-black space-y-2">
4646
{state.steps.map((step, index) => {
4747
if (step.status === "completed") {
4848
return (
@@ -55,7 +55,7 @@ const Chat = () => {
5555
index === state.steps.findIndex((s) => s.status === "pending")
5656
) {
5757
return (
58-
<div key={index} className="text-3xl font-bold text-slate-700">
58+
<div key={index} className="text-2xl font-bold text-slate-700">
5959
<Spinner />
6060
{step.description}
6161
</div>

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/human_in_the_loop/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const Chat = () => {
9999
});
100100
useCopilotAction({
101101
name: "generate_task_steps",
102+
description: "Generates a list of steps for the user to perform",
102103
parameters: [
103104
{
104105
name: "steps",

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/predictive_state_updates/page.tsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,36 @@ const DocumentEditor = () => {
128128
}, [text]);
129129

130130
useCopilotAction({
131-
name: "confirm_changes",
132-
renderAndWaitForResponse: ({ args, respond, status }) => (
133-
<ConfirmChanges
134-
args={args}
135-
respond={respond}
136-
status={status}
137-
onReject={() => {
138-
editor?.commands.setContent(fromMarkdown(currentDocument));
139-
setAgentState({ document: currentDocument });
140-
}}
141-
onConfirm={() => {
142-
editor?.commands.setContent(fromMarkdown(agentState?.document || ""));
143-
setCurrentDocument(agentState?.document || "");
144-
setAgentState({ document: agentState?.document || "" });
145-
}}
146-
/>
147-
),
131+
name: "write_document",
132+
description: `Present the proposed changes to the user for review`,
133+
parameters: [
134+
{
135+
name: "document",
136+
type: "string",
137+
description: "The full updated document in markdown format",
138+
},
139+
],
140+
renderAndWaitForResponse({ args, status, respond }) {
141+
if (status === "executing") {
142+
return (
143+
<ConfirmChanges
144+
args={args}
145+
respond={respond}
146+
status={status}
147+
onReject={() => {
148+
editor?.commands.setContent(fromMarkdown(currentDocument));
149+
setAgentState({ document: currentDocument });
150+
}}
151+
onConfirm={() => {
152+
editor?.commands.setContent(fromMarkdown(agentState?.document || ""));
153+
setCurrentDocument(agentState?.document || "");
154+
setAgentState({ document: agentState?.document || "" });
155+
}}
156+
/>
157+
);
158+
}
159+
return <></>;
160+
},
148161
});
149162

150163
return (

typescript-sdk/apps/dojo/src/config.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ export const featureConfig: FeatureConfig[] = [
2323
description: "Chat with your Copilot and call frontend tools",
2424
tags: ["Chat", "Tools", "Streaming"],
2525
}),
26-
createFeatureConfig({
27-
id: "human_in_the_loop",
28-
name: "Human in the loop",
29-
description: "Plan a task together and direct the Copilot to take the right steps",
30-
tags: ["HITL", "Interactivity"],
31-
}),
3226
createFeatureConfig({
3327
id: "agentic_generative_ui",
3428
name: "Agentic Generative UI",
3529
description: "Assign a long running task to your Copilot and see how it performs!",
3630
tags: ["Generative ui (agent)", "Long running task"],
3731
}),
3832
createFeatureConfig({
39-
id: "tool_based_generative_ui",
40-
name: "Tool Based Generative UI",
41-
description: "Haiku generator that uses tool based generative UI.",
42-
tags: ["Generative ui (action)", "Tools"],
33+
id: "human_in_the_loop",
34+
name: "Human in the loop",
35+
description: "Plan a task together and direct the Copilot to take the right steps",
36+
tags: ["HITL", "Interactivity"],
37+
}),
38+
createFeatureConfig({
39+
id: "predictive_state_updates",
40+
name: "Predictive State Updates",
41+
description: "Use collaboration to edit a document in real time with your Copilot",
42+
tags: ["State", "Streaming", "Tools"],
4343
}),
4444
createFeatureConfig({
4545
id: "shared_state",
@@ -48,10 +48,10 @@ export const featureConfig: FeatureConfig[] = [
4848
tags: ["Agent State", "Collaborating"],
4949
}),
5050
createFeatureConfig({
51-
id: "predictive_state_updates",
52-
name: "Predictive State Updates",
53-
description: "Use collaboration to edit a document in real time with your Copilot",
54-
tags: ["State", "Streaming", "Tools"],
51+
id: "tool_based_generative_ui",
52+
name: "Tool Based Generative UI",
53+
description: "Haiku generator that uses tool based generative UI.",
54+
tags: ["Generative ui (action)", "Tools"],
5555
}),
5656
];
5757

typescript-sdk/apps/dojo/src/menu.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ export const menuIntegrations: MenuIntegrationConfig[] = [
66
name: "Middleware Starter",
77
features: ["agentic_chat"],
88
},
9+
{
10+
id: "pydantic-ai",
11+
name: "Pydantic AI",
12+
features: [
13+
"agentic_chat",
14+
"human_in_the_loop",
15+
"agentic_generative_ui",
16+
"tool_based_generative_ui",
17+
"shared_state",
18+
"predictive_state_updates",
19+
],
20+
},
921
{
1022
id: "server-starter",
1123
name: "Server Starter",

typescript-sdk/integrations/langgraph/examples/agents/predictive_state_updates/agent.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,9 @@ async def chat_node(state: AgentState, config: RunnableConfig):
127127
"content": "Document written.",
128128
"tool_call_id": tool_call_id
129129
}
130-
131-
# Add confirmation tool call
132-
confirm_tool_call = {
133-
"role": "assistant",
134-
"content": "",
135-
"tool_calls": [{
136-
"id": str(uuid.uuid4()),
137-
"function": {
138-
"name": "confirm_changes",
139-
"arguments": "{}"
140-
}
141-
}]
142-
}
143-
144-
messages = messages + [tool_response, confirm_tool_call]
145-
130+
131+
messages = messages + [tool_response]
132+
146133
# Return Command to route to end
147134
return Command(
148135
goto=END,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.turbo
2+
.DS_Store
3+
.git
4+
.gitignore
5+
.idea
6+
.vscode
7+
.env
8+
__tests__
9+
src
10+
tsup.config.ts
11+
tsconfig.json
12+
jest.config.js

0 commit comments

Comments
 (0)