Skip to content

Commit ffeb9c3

Browse files
committed
add clients tutorial
1 parent 0405c96 commit ffeb9c3

File tree

2 files changed

+29
-51
lines changed

2 files changed

+29
-51
lines changed

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"group": "Quickstart",
2222
"pages": [
2323
"quickstart/applications",
24+
"quickstart/clients",
2425
{
2526
"group": "Build integrations",
2627
"pages": [

docs/quickstart/client.mdx renamed to docs/quickstart/clients.mdx

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Client"
2+
title: "Build clients"
33
description:
44
"Build a conversational CLI agent from scratch using AG-UI and Mastra"
55
---
@@ -127,7 +127,7 @@ pnpm add @ag-ui/client @ag-ui/core @ag-ui/mastra
127127
pnpm add @mastra/core @mastra/memory @mastra/libsql
128128

129129
# AI SDK and utilities
130-
pnpm add @ai-sdk/openai
130+
pnpm add @ai-sdk/openai zod@^3.25
131131
```
132132

133133
## Step 3 – Create your agent
@@ -304,14 +304,6 @@ Let's break down what happens when you send a message:
304304
Now that you have a working chat interface, let's add some real-world
305305
capabilities by creating tools. We'll start with a weather tool.
306306

307-
### Install additional dependencies
308-
309-
First, install the packages we need for tools:
310-
311-
```bash
312-
pnpm add zod
313-
```
314-
315307
### Create your first tool
316308

317309
Let's create a weather tool that your agent can use. Create the directory
@@ -445,36 +437,15 @@ function getWeatherCondition(code: number): string {
445437
Now let's update our agent to use the weather tool. Update `src/agent.ts`:
446438

447439
```typescript
448-
import { openai } from "@ai-sdk/openai"
449-
import { Agent } from "@mastra/core/agent"
450-
import { MastraAgent } from "@ag-ui/mastra"
451-
import { Memory } from "@mastra/memory"
452-
import { LibSQLStore } from "@mastra/libsql"
453-
import { weatherTool } from "./tools/weather.tool"
440+
import { weatherTool } from "./tools/weather.tool" // <--- Import the tool
454441
455442
export const agent = new MastraAgent({
456443
agent: new Agent({
457-
name: "AG-UI Assistant",
458-
instructions: `
459-
You are a helpful AI assistant with weather capabilities.
444+
// ...
460445

461-
When helping users get weather details:
462-
- Always ask for a location if none is provided
463-
- If the location name isn't in English, translate it to English
464-
- For locations with multiple parts (e.g. "New York, NY"), use the most specific part
465-
- Include relevant details like temperature, humidity, wind conditions
466-
- Keep responses conversational and informative
467-
- Always use the weatherTool to fetch current weather data
446+
tools: { weatherTool }, // <--- Add the tool to the agent
468447

469-
For other questions, be friendly and helpful!
470-
`,
471-
model: openai("gpt-4o"),
472-
tools: { weatherTool },
473-
memory: new Memory({
474-
storage: new LibSQLStore({
475-
url: "file:./assistant.db",
476-
}),
477-
}),
448+
// ...
478449
}),
479450
threadId: "main-conversation",
480451
})
@@ -486,21 +457,27 @@ Update your CLI interface in `src/index.ts` to handle tool events:
486457

487458
```typescript
488459
// Add these new event handlers to your agent.runAgent call:
489-
onToolCallStartEvent({ event }) {
490-
console.log(`🔧 Using ${event.toolCallName}...`)
491-
},
492-
onToolCallArgsEvent({ event }) {
493-
// Show tool arguments being built (optional)
494-
process.stdout.write(event.delta)
495-
},
496-
onToolCallEndEvent() {
497-
console.log("")
498-
},
499-
onToolCallResultEvent({ event }) {
500-
if (event.content) {
501-
console.log("✅ Tool completed successfully")
502-
}
503-
},
460+
await agent.runAgent(
461+
{}, // No additional configuration needed
462+
{
463+
// ... existing event handlers ...
464+
465+
onToolCallStartEvent({ event }) {
466+
console.log("🔧 Tool call:", event.toolCallName)
467+
},
468+
onToolCallArgsEvent({ event }) {
469+
process.stdout.write(event.delta)
470+
},
471+
onToolCallEndEvent() {
472+
console.log("")
473+
},
474+
onToolCallResultEvent({ event }) {
475+
if (event.content) {
476+
console.log("🔍 Tool call result:", event.content)
477+
}
478+
},
479+
}
480+
)
504481
```
505482

506483
### Test your weather tool
@@ -610,7 +587,7 @@ me the weather website".
610587

611588
## Step 9 – Deploy your client
612589

613-
### Build for production
590+
### Building your client
614591

615592
Create a production build:
616593

0 commit comments

Comments
 (0)