|
1 | | -# @ag-ui/mastra |
| 1 | +# @ag-ui/langchain |
2 | 2 |
|
3 | | -Implementation of the AG-UI protocol for Mastra. |
4 | | - |
5 | | -Connects Mastra agents (local and remote) to frontend applications via the AG-UI protocol. Supports streaming responses, memory management, and tool execution. |
| 3 | +Implementation of the AG-UI protocol for LangChain. |
6 | 4 |
|
7 | 5 | ## Installation |
8 | 6 |
|
9 | 7 | ```bash |
10 | | -npm install @ag-ui/mastra |
11 | | -pnpm add @ag-ui/mastra |
12 | | -yarn add @ag-ui/mastra |
| 8 | +npm install @ag-ui/langchain |
| 9 | +pnpm add @ag-ui/langchain |
| 10 | +yarn add @ag-ui/langchain |
13 | 11 | ``` |
14 | 12 |
|
15 | 13 | ## Usage |
16 | 14 |
|
17 | 15 | ```ts |
18 | | -import { MastraAgent } from "@ag-ui/mastra"; |
19 | | -import { mastra } from "./mastra"; // Your Mastra instance |
| 16 | +import { LangChainAgent } from "@ag-ui/langchain"; |
20 | 17 |
|
21 | 18 | // Create an AG-UI compatible agent |
22 | | -const agent = new MastraAgent({ |
23 | | - agent: mastra.getAgent("weather-agent"), |
24 | | - resourceId: "user-123", |
25 | | -}); |
26 | | - |
27 | | -// Run with streaming |
28 | | -const result = await agent.runAgent({ |
29 | | - messages: [{ role: "user", content: "What's the weather like?" }], |
30 | | -}); |
31 | | -``` |
32 | | - |
33 | | -## Features |
34 | | - |
35 | | -- **Local & remote agents** – Works with in-process and network Mastra agents |
36 | | -- **Memory integration** – Automatic thread and working memory management |
37 | | -- **Tool streaming** – Real-time tool call execution and results |
38 | | -- **State management** – Bidirectional state synchronization |
39 | | - |
40 | | -## To run the example server in the dojo |
41 | | - |
42 | | -```bash |
43 | | -cd integrations/mastra/typescript/examples |
44 | | -pnpm install |
45 | | -pnpm run dev |
| 19 | +const agent = new LangChainAgent({ |
| 20 | + chainFn: async ({ messages, tools, threadId }) => { |
| 21 | + // Your chosen llm model |
| 22 | + const { ChatOpenAI } = await import("@langchain/openai"); |
| 23 | + const chatOpenAI = new ChatOpenAI({ model: "gpt-4o" }); |
| 24 | + const model = chatOpenAI.bindTools(tools, { |
| 25 | + strict: true, |
| 26 | + }); |
| 27 | + return model.stream(messages, { tools, metadata: { conversation_id: threadId } }); |
| 28 | + }, |
| 29 | +}) |
46 | 30 | ``` |
0 commit comments