|
| 1 | +# AWS Strands Integration for AG-UI (TypeScript) |
| 2 | + |
| 3 | +`@ag-ui/strands-server` is the TypeScript twin of the Python adapter. Give us any `@strands-agents/sdk` agent, wrap it with `StrandsAgent`, and wire it to HTTP via `createStrandsServer` or `addStrandsEndpoint`. The config surface, event ordering, and helper APIs all mirror the Python version so you can switch languages without relearning the integration. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js 18+ |
| 8 | +- `pnpm` (recommended) or npm |
| 9 | +- A Strands-compatible model key (Gemini, Bedrock, etc.) |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +Run the bundled demo to see shared-state + tool behaviors in action: |
| 14 | + |
| 15 | +```bash |
| 16 | +cd integrations/aws-strands/typescript-server/examples |
| 17 | +pnpm install |
| 18 | +pnpm dev |
| 19 | +``` |
| 20 | + |
| 21 | +It mounts `http://localhost:8000/runs` and streams AG-UI events for a Strands agent that owns three tools (`get_weather`, `set_theme_color`, `update_proverbs`). The demo highlights `stateContextBuilder`, `stateFromArgs`, and `skipMessagesSnapshot`. |
| 22 | + |
| 23 | +To embed it directly: |
| 24 | + |
| 25 | +```ts |
| 26 | +const baseAgent = new Agent({ systemPrompt: "Be helpful.", tools: [...] }); |
| 27 | +const aguiAgent = new StrandsAgent(baseAgent, "demo_agent", "Demo agent", config); |
| 28 | +const server = createStrandsServer(aguiAgent, "/runs"); |
| 29 | +server.listen(8000); |
| 30 | +``` |
| 31 | + |
| 32 | +## Architecture Overview |
| 33 | + |
| 34 | +- **StrandsAgent** – wraps `agent.streamAsync` / `stream` and emits AG-UI events (`run_started`, deltas, tool calls, PredictState, snapshots, finish/error) identically to the Python adapter. |
| 35 | +- **Configuration layer** – `StrandsAgentConfig`, `ToolBehavior`, and `PredictStateMapping` expose the same hooks: `stateContextBuilder`, `argsStreamer`, `stateFromArgs`, `stateFromResult`, `customResultHandler`, etc. |
| 36 | +- **Transport helpers** – `createStrandsServer`, `createStrandsHandler`, and `addStrandsEndpoint` reuse the shared `EventEncoder` to deliver SSE or newline-delimited JSON from Express-compatible apps. |
| 37 | + |
| 38 | +## Key Files |
| 39 | + |
| 40 | +| File | Purpose | |
| 41 | +| -------------------------------- | -------------------------------------------------------------------------------------- | |
| 42 | +| `src/agent.ts` | Converts Strands streaming events into AG-UI protocol events | |
| 43 | +| `src/config.ts` | Configuration primitives (`StrandsAgentConfig`, `ToolBehavior`, `PredictStateMapping`) | |
| 44 | +| `src/endpoint.ts` | HTTP/SSE helpers | |
| 45 | +| `examples/src/proverbs-agent.ts` | Runnable demo showcasing shared-state behaviors | |
| 46 | + |
| 47 | +## Development |
| 48 | + |
| 49 | +```bash |
| 50 | +pnpm install |
| 51 | +pnpm run build # tsup build (CJS + ESM + d.ts) |
| 52 | +pnpm run typecheck # tsc --noEmit |
| 53 | +pnpm run dev # tsup --watch |
| 54 | +``` |
| 55 | + |
| 56 | +Only `dist/` and this README ship in the npm package; everything else stays ignored via `.npmignore`. |
0 commit comments