Skip to content

Commit 14c2ffe

Browse files
committed
test(dojo): add langgraph backend tool rendering tests
Signed-off-by: Tyler Slaton <[email protected]>
1 parent 34f9b43 commit 14c2ffe

File tree

4 files changed

+133
-24
lines changed

4 files changed

+133
-24
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("[MastraAgentLocal] Backend Tool Rendering displays weather cards", async ({ page }) => {
4+
// Set shorter default timeout for this test
5+
test.setTimeout(30000); // 30 seconds total
6+
7+
await page.goto("/langgraph-fastapi/feature/backend_tool_rendering");
8+
9+
// Verify suggestion buttons are visible
10+
await expect(page.getByRole("button", { name: "Weather in San Francisco" })).toBeVisible({
11+
timeout: 5000,
12+
});
13+
14+
// Click first suggestion and verify weather card appears
15+
await page.getByRole("button", { name: "Weather in San Francisco" }).click();
16+
17+
// Wait for either test ID or fallback to "Current Weather" text
18+
const weatherCard = page.getByTestId("weather-card");
19+
const currentWeatherText = page.getByText("Current Weather");
20+
21+
// Try test ID first, fallback to text
22+
try {
23+
await expect(weatherCard).toBeVisible({ timeout: 10000 });
24+
} catch (e) {
25+
// Fallback to checking for "Current Weather" text
26+
await expect(currentWeatherText.first()).toBeVisible({ timeout: 10000 });
27+
}
28+
29+
// Verify weather content is present (use flexible selectors)
30+
const hasHumidity = await page
31+
.getByText("Humidity")
32+
.isVisible()
33+
.catch(() => false);
34+
const hasWind = await page
35+
.getByText("Wind")
36+
.isVisible()
37+
.catch(() => false);
38+
const hasCityName = await page
39+
.locator("h3")
40+
.filter({ hasText: /San Francisco/i })
41+
.isVisible()
42+
.catch(() => false);
43+
44+
// At least one of these should be true
45+
expect(hasHumidity || hasWind || hasCityName).toBeTruthy();
46+
47+
// Click second suggestion
48+
await page.getByRole("button", { name: "Weather in New York" }).click();
49+
await page.waitForTimeout(2000);
50+
51+
// Verify at least one weather-related element is still visible
52+
const weatherElements = await page.getByText(/Weather|Humidity|Wind|Temperature/i).count();
53+
expect(weatherElements).toBeGreaterThan(0);
54+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("[MastraAgentLocal] Backend Tool Rendering displays weather cards", async ({ page }) => {
4+
// Set shorter default timeout for this test
5+
test.setTimeout(30000); // 30 seconds total
6+
7+
await page.goto("/langgraph/feature/backend_tool_rendering");
8+
9+
// Verify suggestion buttons are visible
10+
await expect(page.getByRole("button", { name: "Weather in San Francisco" })).toBeVisible({
11+
timeout: 5000,
12+
});
13+
14+
// Click first suggestion and verify weather card appears
15+
await page.getByRole("button", { name: "Weather in San Francisco" }).click();
16+
17+
// Wait for either test ID or fallback to "Current Weather" text
18+
const weatherCard = page.getByTestId("weather-card");
19+
const currentWeatherText = page.getByText("Current Weather");
20+
21+
// Try test ID first, fallback to text
22+
try {
23+
await expect(weatherCard).toBeVisible({ timeout: 10000 });
24+
} catch (e) {
25+
// Fallback to checking for "Current Weather" text
26+
await expect(currentWeatherText.first()).toBeVisible({ timeout: 10000 });
27+
}
28+
29+
// Verify weather content is present (use flexible selectors)
30+
const hasHumidity = await page
31+
.getByText("Humidity")
32+
.isVisible()
33+
.catch(() => false);
34+
const hasWind = await page
35+
.getByText("Wind")
36+
.isVisible()
37+
.catch(() => false);
38+
const hasCityName = await page
39+
.locator("h3")
40+
.filter({ hasText: /San Francisco/i })
41+
.isVisible()
42+
.catch(() => false);
43+
44+
// At least one of these should be true
45+
expect(hasHumidity || hasWind || hasCityName).toBeTruthy();
46+
47+
// Click second suggestion
48+
await page.getByRole("button", { name: "Weather in New York" }).click();
49+
await page.waitForTimeout(2000);
50+
51+
// Verify at least one weather-related element is still visible
52+
const weatherElements = await page.getByText(/Weather|Humidity|Wind|Temperature/i).count();
53+
expect(weatherElements).toBeGreaterThan(0);
54+
});

typescript-sdk/integrations/langgraph/examples/python/agents/dojo.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from fastapi import FastAPI
44

55
from dotenv import load_dotenv
6+
67
load_dotenv()
78

89
os.environ["LANGGRAPH_FAST_API"] = "true"
@@ -15,6 +16,7 @@
1516
from .agentic_chat.agent import graph as agentic_chat_graph
1617
from .agentic_generative_ui.agent import graph as agentic_generative_ui_graph
1718
from .agentic_chat_reasoning.agent import graph as agentic_chat_reasoning_graph
19+
from .backend_tool_rendering.agent import graph as backend_tool_rendering_graph
1820
from .subgraphs.agent import graph as subgraphs_graph
1921

2022
app = FastAPI(title="LangGraph Dojo Example Server")
@@ -24,7 +26,12 @@
2426
"agentic_chat": LangGraphAgent(
2527
name="agentic_chat",
2628
description="An example for an agentic chat flow using LangGraph.",
27-
graph=agentic_chat_graph
29+
graph=agentic_chat_graph,
30+
),
31+
"backend_tool_rendering": LangGraphAgent(
32+
name="backend_tool_rendering",
33+
description="An example for a backend tool rendering flow.",
34+
graph=backend_tool_rendering_graph,
2835
),
2936
"tool_based_generative_ui": LangGraphAgent(
3037
name="tool_based_generative_ui",
@@ -63,60 +70,53 @@
6370
),
6471
}
6572

73+
add_langgraph_fastapi_endpoint(
74+
app=app, agent=agents["agentic_chat"], path="/agent/agentic_chat"
75+
)
76+
6677
add_langgraph_fastapi_endpoint(
6778
app=app,
68-
agent=agents["agentic_chat"],
69-
path="/agent/agentic_chat"
79+
agent=agents["backend_tool_rendering"],
80+
path="/agent/backend_tool_rendering",
7081
)
7182

83+
7284
add_langgraph_fastapi_endpoint(
7385
app=app,
7486
agent=agents["tool_based_generative_ui"],
75-
path="/agent/tool_based_generative_ui"
87+
path="/agent/tool_based_generative_ui",
7688
)
7789

7890
add_langgraph_fastapi_endpoint(
79-
app=app,
80-
agent=agents["agentic_generative_ui"],
81-
path="/agent/agentic_generative_ui"
91+
app=app, agent=agents["agentic_generative_ui"], path="/agent/agentic_generative_ui"
8292
)
8393

8494
add_langgraph_fastapi_endpoint(
85-
app=app,
86-
agent=agents["human_in_the_loop"],
87-
path="/agent/human_in_the_loop"
95+
app=app, agent=agents["human_in_the_loop"], path="/agent/human_in_the_loop"
8896
)
8997

9098
add_langgraph_fastapi_endpoint(
91-
app=app,
92-
agent=agents["shared_state"],
93-
path="/agent/shared_state"
99+
app=app, agent=agents["shared_state"], path="/agent/shared_state"
94100
)
95101

96102
add_langgraph_fastapi_endpoint(
97103
app=app,
98104
agent=agents["predictive_state_updates"],
99-
path="/agent/predictive_state_updates"
105+
path="/agent/predictive_state_updates",
100106
)
101107

102108
add_langgraph_fastapi_endpoint(
103109
app=app,
104110
agent=agents["agentic_chat_reasoning"],
105-
path="/agent/agentic_chat_reasoning"
111+
path="/agent/agentic_chat_reasoning",
106112
)
107113

108114
add_langgraph_fastapi_endpoint(
109-
app=app,
110-
agent=agents["subgraphs"],
111-
path="/agent/subgraphs"
115+
app=app, agent=agents["subgraphs"], path="/agent/subgraphs"
112116
)
113117

118+
114119
def main():
115120
"""Run the uvicorn server."""
116121
port = int(os.getenv("PORT", "8000"))
117-
uvicorn.run(
118-
"agents.dojo:app",
119-
host="0.0.0.0",
120-
port=port,
121-
reload=True
122-
)
122+
uvicorn.run("agents.dojo:app", host="0.0.0.0", port=port, reload=True)

typescript-sdk/integrations/langgraph/examples/python/langgraph.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"dependencies": ["."],
55
"graphs": {
66
"agentic_chat": "./agents/agentic_chat/agent.py:graph",
7+
"backend_tool_rendering": "./agents/backend_tool_rendering/agent.py:graph",
78
"agentic_generative_ui": "./agents/agentic_generative_ui/agent.py:graph",
89
"human_in_the_loop": "./agents/human_in_the_loop/agent.py:graph",
910
"predictive_state_updates": "./agents/predictive_state_updates/agent.py:graph",

0 commit comments

Comments
 (0)