Skip to content

Commit 78467f4

Browse files
committed
fix cli example
1 parent 9ba3771 commit 78467f4

File tree

8 files changed

+60
-27
lines changed

8 files changed

+60
-27
lines changed

apps/client-cli-example/README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
1-
# AG-UI CLI
1+
# AG-UI CLI Example
2+
3+
A command-line chat interface demonstrating the AG-UI client with a Mastra agent. This example shows how to build an interactive CLI application that streams agent responses and tool calls in real-time.
4+
5+
## Features
6+
7+
- Interactive chat loop with streaming responses
8+
- Real-time tool call visualization (weather and browser tools)
9+
- Message history persistence using LibSQL
10+
- Built with `@ag-ui/client` and `@ag-ui/mastra`
11+
12+
## Prerequisites
13+
14+
- Node.js 22.13.0 or later
15+
- OpenAI API key
16+
17+
## Setup
18+
19+
1. Install dependencies from the repository root:
20+
21+
```bash
22+
pnpm install
23+
```
24+
25+
2. Set your OpenAI API key:
26+
```bash
27+
export OPENAI_API_KEY=your_api_key_here
28+
```
29+
30+
## Usage
31+
32+
Run the CLI:
33+
34+
```bash
35+
pnpm start
36+
```
37+
38+
Try these example prompts:
39+
40+
- "What's the weather in San Francisco?"
41+
- "Browse https://example.com"
42+
43+
Press `Ctrl+D` to quit.
44+
45+
## How It Works
46+
47+
This example uses:
48+
49+
- **MastraAgent**: Wraps a Mastra agent with AG-UI protocol support
50+
- **Event Handlers**: Streams text deltas, tool calls, and results to the console
51+
- **Memory**: Persists conversation history in a local SQLite database

apps/client-cli-example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"@ag-ui/client": "workspace:*",
1313
"@ag-ui/core": "workspace:*",
1414
"@ag-ui/mastra": "workspace:*",
15-
"@ai-sdk/openai": "1.3.22",
1615
"@mastra/client-js": "1.0.0-beta.2",
1716
"@mastra/core": "1.0.0-beta.2",
1817
"@mastra/libsql": "1.0.0-beta.0",

apps/client-cli-example/src/agent.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { openai } from "@ai-sdk/openai";
21
import { Agent } from "@mastra/core/agent";
32
import { MastraAgent } from "@ag-ui/mastra";
43
import { Memory } from "@mastra/memory";
@@ -7,7 +6,6 @@ import { weatherTool } from "./tools/weather.tool";
76
import { browserTool } from "./tools/browser.tool";
87

98
export const agent = new MastraAgent({
10-
// @ts-ignore
119
agent: new Agent({
1210
name: "AG-UI Agent",
1311
instructions: `
@@ -26,13 +24,13 @@ export const agent = new MastraAgent({
2624
Use the browserTool to browse the web.
2725
2826
`,
29-
model: openai("gpt-4o-mini"),
27+
model: "openai/gpt-4o-mini",
3028
tools: { weatherTool, browserTool },
3129
memory: new Memory({
3230
storage: new LibSQLStore({
31+
id: "mastra-cli-example-db",
3332
url: "file:./mastra.db",
3433
}),
3534
}),
3635
}),
37-
threadId: "1",
3836
});

apps/client-cli-example/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as readline from "readline";
2-
import { agent } from "./agent";
32
import { randomUUID } from "@ag-ui/client";
3+
import { agent } from "./agent";
44

55
const rl = readline.createInterface({
66
input: process.stdin,

apps/client-cli-example/src/tools/browser.tool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export const browserTool = createTool({
99
url: z.string().describe("URL to browse"),
1010
}),
1111
outputSchema: z.string(),
12-
execute: async ({ context }) => {
13-
open(context.url);
14-
return `Browsed ${context.url}`;
12+
execute: async (inputData) => {
13+
open(inputData.url);
14+
return `Browsed ${inputData.url}`;
1515
},
1616
});

apps/client-cli-example/src/tools/weather.tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export const weatherTool = createTool({
3535
conditions: z.string(),
3636
location: z.string(),
3737
}),
38-
execute: async ({ context }) => {
39-
return await getWeather(context.location);
38+
execute: async (inputData) => {
39+
return await getWeather(inputData.location);
4040
},
4141
});
4242

integrations/mastra/typescript/src/mastra.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class MastraAgent extends AbstractAgent {
188188
threadId: input.threadId,
189189
memoryConfig: {
190190
workingMemory: {
191+
scope: "thread",
191192
enabled: true,
192193
},
193194
},

pnpm-lock.yaml

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)