-
Notifications
You must be signed in to change notification settings - Fork 914
feat!(mastra): Support 1.0.0-beta #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0bea326
5da63e8
a62f159
4e06521
d2aeeb8
b8190c1
9ba3771
78467f4
69bfb25
0050d12
9d01d7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,51 @@ | ||
| # AG-UI CLI | ||
| # AG-UI CLI Example | ||
|
|
||
| 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. | ||
|
|
||
| ## Features | ||
|
|
||
| - Interactive chat loop with streaming responses | ||
| - Real-time tool call visualization (weather and browser tools) | ||
| - Message history persistence using LibSQL | ||
| - Built with `@ag-ui/client` and `@ag-ui/mastra` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js 22.13.0 or later | ||
| - OpenAI API key | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Install dependencies from the repository root: | ||
|
|
||
| ```bash | ||
| pnpm install | ||
| ``` | ||
|
|
||
| 2. Set your OpenAI API key: | ||
| ```bash | ||
| export OPENAI_API_KEY=your_api_key_here | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| Run the CLI: | ||
|
|
||
| ```bash | ||
| pnpm start | ||
| ``` | ||
|
|
||
| Try these example prompts: | ||
|
|
||
| - "What's the weather in San Francisco?" | ||
| - "Browse https://example.com" | ||
|
|
||
| Press `Ctrl+D` to quit. | ||
|
|
||
| ## How It Works | ||
|
|
||
| This example uses: | ||
|
|
||
| - **MastraAgent**: Wraps a Mastra agent with AG-UI protocol support | ||
| - **Event Handlers**: Streams text deltas, tool calls, and results to the console | ||
| - **Memory**: Persists conversation history in a local SQLite database |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import { openai } from "@ai-sdk/openai"; | ||
| import { Agent } from "@mastra/core/agent"; | ||
| import { MastraAgent } from "@ag-ui/mastra"; | ||
| import { Memory } from "@mastra/memory"; | ||
|
|
@@ -7,7 +6,6 @@ import { weatherTool } from "./tools/weather.tool"; | |
| import { browserTool } from "./tools/browser.tool"; | ||
|
|
||
| export const agent = new MastraAgent({ | ||
| // @ts-ignore | ||
| agent: new Agent({ | ||
| name: "AG-UI Agent", | ||
| instructions: ` | ||
|
|
@@ -26,13 +24,13 @@ export const agent = new MastraAgent({ | |
| Use the browserTool to browse the web. | ||
|
|
||
| `, | ||
| model: openai("gpt-4o-mini"), | ||
| model: "openai/gpt-4o-mini", | ||
| tools: { weatherTool, browserTool }, | ||
| memory: new Memory({ | ||
| storage: new LibSQLStore({ | ||
| id: "mastra-cli-example-db", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| url: "file:./mastra.db", | ||
| }), | ||
| }), | ||
| }), | ||
| threadId: "1", | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,8 @@ export const browserTool = createTool({ | |
| url: z.string().describe("URL to browse"), | ||
| }), | ||
| outputSchema: z.string(), | ||
| execute: async ({ context }) => { | ||
| open(context.url); | ||
| return `Browsed ${context.url}`; | ||
| execute: async (inputData) => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| open(inputData.url); | ||
| return `Browsed ${inputData.url}`; | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,3 +141,6 @@ dist | |
| vite.config.js.timestamp-* | ||
| vite.config.ts.timestamp-* | ||
| .vite/ | ||
|
|
||
| # Mastra files | ||
| .mastra | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,6 @@ import { ServerStarterAgent } from "@ag-ui/server-starter"; | |
| import { ServerStarterAllFeaturesAgent } from "@ag-ui/server-starter-all-features"; | ||
| import { MastraClient } from "@mastra/client-js"; | ||
| import { MastraAgent } from "@ag-ui/mastra"; | ||
| import { VercelAISDKAgent } from "@ag-ui/vercel-ai-sdk"; | ||
| import { openai } from "@ai-sdk/openai"; | ||
| import { LangGraphAgent, LangGraphHttpAgent } from "@ag-ui/langgraph"; | ||
| import { AgnoAgent } from "@ag-ui/agno"; | ||
| import { LlamaIndexAgent } from "@ag-ui/llamaindex"; | ||
|
|
@@ -119,6 +117,7 @@ export const agentsIntegrations: AgentIntegrationConfig[] = [ | |
| }, | ||
| }, | ||
| { | ||
| // To use this, run "pnpm mastra:dev" in a separate terminal window | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe this is valid. I'm pretty sure the mastra:dev script would run the mastra-agent-local agent listed below, but I'm not entirely sure since that's whats bundled into the dojo (and not listed in the exports). This script entry's existence may be entirely invalid. Regardless, the agent with id
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand it the local agent one imports the mastra class, the remote one initializes a MastraClient which needs an URL. I got it working like that so that’s why I added the comment |
||
| id: "mastra", | ||
| agents: async () => { | ||
| const mastraClient = new MastraClient({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| OPENAI_API_KEY="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mastra now has its own model router so we can remove AI SDK usage