Skip to content

Commit 928a4bf

Browse files
authored
Merge pull request ag-ui-protocol#241 from ag-ui-protocol/feat/restore-time-travel
2 parents a8f37ef + c08e98b commit 928a4bf

File tree

53 files changed

+4924
-4146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4924
-4146
lines changed

typescript-sdk/apps/dojo/scripts/generate-content-json.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,57 +140,60 @@ async function getFeatureFrontendFiles(featureId: string) {
140140
}
141141

142142
const integrationsFolderPath = '../../../integrations'
143-
const agentFilesMapper: Record<string, (agentKeys: string[]) => Record<string, string>> = {
143+
const agentFilesMapper: Record<string, (agentKeys: string[]) => Record<string, string[]>> = {
144144
'middleware-starter': () => ({
145-
agentic_chat: path.join(__dirname, integrationsFolderPath, `/middleware-starter/src/index.ts`)
145+
agentic_chat: [path.join(__dirname, integrationsFolderPath, `/middleware-starter/src/index.ts`)]
146146
}),
147147
'pydantic-ai': (agentKeys: string[]) => {
148148
return agentKeys.reduce((acc, agentId) => ({
149149
...acc,
150-
[agentId]: `https://github.com/pydantic/pydantic-ai/blob/main/examples/pydantic_ai_examples/ag_ui/api/${agentId}.py`
150+
[agentId]: [`https://github.com/pydantic/pydantic-ai/blob/main/examples/pydantic_ai_examples/ag_ui/api/${agentId}.py`]
151151
}), {})
152152
},
153153
'server-starter': () => ({
154-
agentic_chat: path.join(__dirname, integrationsFolderPath, `/server-starter/server/python/example_server/__init__.py`)
154+
agentic_chat: [path.join(__dirname, integrationsFolderPath, `/server-starter/server/python/example_server/__init__.py`)]
155155
}),
156156
'server-starter-all-features': (agentKeys: string[]) => {
157157
return agentKeys.reduce((acc, agentId) => ({
158158
...acc,
159-
[agentId]: path.join(__dirname, integrationsFolderPath, `/server-starter/server/python/example_server/${agentId}.py`)
159+
[agentId]: [path.join(__dirname, integrationsFolderPath, `/server-starter-all-features/server/python/example_server/${agentId}.py`)]
160160
}), {})
161161
},
162162
'mastra': () => ({
163-
agentic_chat: path.join(__dirname, integrationsFolderPath, `/mastra/example/src/mastra/agents/weather-agent.ts`)
163+
agentic_chat: [path.join(__dirname, integrationsFolderPath, `/mastra/example/src/mastra/agents/weather-agent.ts`)]
164164
}),
165165
'mastra-agent-lock': () => ({
166-
agentic_chat: path.join(__dirname, integrationsFolderPath, `/mastra/example/src/mastra/agents/weather-agent.ts`)
166+
agentic_chat: [path.join(__dirname, integrationsFolderPath, `/mastra/example/src/mastra/agents/weather-agent.ts`)]
167167
}),
168168
'vercel-ai-sdk': () => ({
169-
agentic_chat: path.join(__dirname, integrationsFolderPath, `/vercel-ai-sdk/src/index.ts`)
169+
agentic_chat: [path.join(__dirname, integrationsFolderPath, `/vercel-ai-sdk/src/index.ts`)]
170170
}),
171171
'langgraph': (agentKeys: string[]) => {
172172
return agentKeys.reduce((acc, agentId) => ({
173173
...acc,
174-
[agentId]: path.join(__dirname, integrationsFolderPath, `/langgraph/examples/agents/${agentId}/agent.py`)
174+
[agentId]: [
175+
path.join(__dirname, integrationsFolderPath, `/langgraph/examples/python/agents/${agentId}/agent.py`),
176+
path.join(__dirname, integrationsFolderPath, `/langgraph/examples/typescript/src/agents/${agentId}/agent.ts`)
177+
]
175178
}), {})
176179
},
177180
'langgraph-fastapi': (agentKeys: string[]) => {
178181
return agentKeys.reduce((acc, agentId) => ({
179182
...acc,
180-
[agentId]: path.join(__dirname, integrationsFolderPath, `/langgraph/python/ag_ui_langgraph/examples/agents/${agentId}.py`)
183+
[agentId]: [path.join(__dirname, integrationsFolderPath, `/langgraph/examples/python/agents/${agentId}/agent.py`)]
181184
}), {})
182185
},
183186
'agno': () => ({}),
184187
'llama-index': (agentKeys: string[]) => {
185188
return agentKeys.reduce((acc, agentId) => ({
186189
...acc,
187-
[agentId]: path.join(__dirname, integrationsFolderPath, `/llamaindex/server-py/server/routers/${agentId}.py`)
190+
[agentId]: [path.join(__dirname, integrationsFolderPath, `/llamaindex/server-py/server/routers/${agentId}.py`)]
188191
}), {})
189192
},
190193
'crewai': (agentKeys: string[]) => {
191194
return agentKeys.reduce((acc, agentId) => ({
192195
...acc,
193-
[agentId]: path.join(__dirname, integrationsFolderPath, `/crewai/python/ag_ui_crewai/examples/${agentId}.py`)
196+
[agentId]: [path.join(__dirname, integrationsFolderPath, `/crewai/python/ag_ui_crewai/examples/${agentId}.py`)]
194197
}), {})
195198
}
196199
}
@@ -202,14 +205,16 @@ async function runGenerateContent() {
202205
const agentsPerFeatures = agentConfig.agentKeys
203206

204207
const agentFilePaths = agentFilesMapper[agentConfig.id](agentConfig.agentKeys)
208+
205209
// Per feature, assign all the frontend files like page.tsx as well as all agent files
206210
for (const featureId of agentsPerFeatures) {
211+
const agentFilePathsForFeature = agentFilePaths[featureId] ?? []
207212
// @ts-expect-error -- redundant error about indexing of a new object.
208213
result[`${agentConfig.id}::${featureId}`] = [
209214
// Get all frontend files for the feature
210215
...(await getFeatureFrontendFiles(featureId)),
211216
// Get the agent (python/TS) file
212-
await getFile(agentFilePaths[featureId])
217+
...(await Promise.all(agentFilePathsForFeature.map(async f => await getFile(f))))
213218
]
214219
}
215220
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function ToolBasedGenerativeUI({ params }: ToolBasedGenerativeUIP
5151
agent="tool_based_generative_ui"
5252
>
5353
<div
54-
className={`${isMobile ? 'h-screen' : 'min-h-full'} w-full relative overflow-hidden`}
54+
className={`${isMobile ? 'h-screen' : 'min-h-full flex'} w-full relative overflow-hidden`}
5555
style={
5656
{
5757
// "--copilot-kit-primary-color": "#222",
@@ -336,7 +336,7 @@ function Haiku() {
336336
<div className="flex h-full w-full">
337337
{/* Thumbnail List */}
338338
{Boolean(generatedHaikus.length) && !isMobile && (
339-
<div className="w-40 p-4 border-r border-gray-200 overflow-y-auto overflow-x-hidden max-w-1">
339+
<div className="w-40 p-4 border-r border-gray-200 overflow-y-auto overflow-x-hidden">
340340
{generatedHaikus.map((haiku, index) => (
341341
<div
342342
key={index}

typescript-sdk/apps/dojo/src/files.json

Lines changed: 96 additions & 31 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

typescript-sdk/integrations/langgraph/examples/agents/agentic_chat/agent.py renamed to typescript-sdk/integrations/langgraph/examples/python/agents/agentic_chat/agent.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
A simple agentic chat flow using LangGraph instead of CrewAI.
33
"""
44

5-
from typing import Dict, List, Any, Optional
5+
from typing import List, Any
6+
import os
67

78
# Updated imports for LangGraph
89
from langchain_core.runnables import RunnableConfig
@@ -76,5 +77,16 @@ async def chat_node(state: AgentState, config: RunnableConfig):
7677
workflow.add_edge(START, "chat_node")
7778
workflow.add_edge("chat_node", END)
7879

80+
# Conditionally use a checkpointer based on the environment
81+
# Check for multiple indicators that we're running in LangGraph dev/API mode
82+
is_fast_api = os.environ.get("LANGGRAPH_FAST_API", "false").lower() == "true"
83+
7984
# Compile the graph
80-
agentic_chat_graph = workflow.compile()
85+
if is_fast_api:
86+
# For CopilotKit and other contexts, use MemorySaver
87+
from langgraph.checkpoint.memory import MemorySaver
88+
memory = MemorySaver()
89+
graph = workflow.compile(checkpointer=memory)
90+
else:
91+
# When running in LangGraph API/dev, don't use a custom checkpointer
92+
graph = workflow.compile()
File renamed without changes.

typescript-sdk/integrations/langgraph/examples/agents/agentic_generative_ui/agent.py renamed to typescript-sdk/integrations/langgraph/examples/python/agents/agentic_generative_ui/agent.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
An example demonstrating agentic generative UI using LangGraph.
33
"""
44

5-
import json
65
import asyncio
7-
from typing import Dict, List, Any, Optional, Literal
6+
from typing import List, Any
7+
import os
8+
89
# LangGraph imports
910
from langchain_core.runnables import RunnableConfig
1011
from langgraph.graph import StateGraph, END, START
@@ -189,5 +190,16 @@ async def chat_node(state: AgentState, config: RunnableConfig):
189190
workflow.add_edge("start_flow", "chat_node")
190191
workflow.add_edge("chat_node", END)
191192

193+
# Conditionally use a checkpointer based on the environment
194+
# Check for multiple indicators that we're running in LangGraph dev/API mode
195+
is_fast_api = os.environ.get("LANGGRAPH_FAST_API", "false").lower() == "true"
196+
192197
# Compile the graph
193-
graph = workflow.compile()
198+
if is_fast_api:
199+
# For CopilotKit and other contexts, use MemorySaver
200+
from langgraph.checkpoint.memory import MemorySaver
201+
memory = MemorySaver()
202+
graph = workflow.compile(checkpointer=memory)
203+
else:
204+
# When running in LangGraph API/dev, don't use a custom checkpointer
205+
graph = workflow.compile()

0 commit comments

Comments
 (0)