|
| 1 | +# Build chat experiences with AG-UI and CopilotKit |
| 2 | + |
| 3 | +{{ community_contribution_banner }} |
| 4 | + |
| 5 | +As an agent builder, you want users to interact with your agents through a rich |
| 6 | +and responsive interface. Building UIs from scratch requires a lot of effort, |
| 7 | +especially to support streaming events and client state. That's exactly what |
| 8 | +[AG-UI](https://docs.ag-ui.com/) was designed for - rich user experiences |
| 9 | +directly connected to an agent. |
| 10 | + |
| 11 | +[AG-UI](https://github.com/ag-ui-protocol/ag-ui) provides a consistent interface |
| 12 | +to empower rich clients across technology stacks, from mobile to the web and |
| 13 | +even the command line. There are a number of different clients that support |
| 14 | +AG-UI: |
| 15 | + |
| 16 | +- [CopilotKit](https://copilotkit.ai) provides tooling and components to tightly integrate your agent with web applications |
| 17 | +- Clients for [Kotlin](https://github.com/ag-ui-protocol/ag-ui/tree/main/sdks/community/kotlin), [Java](https://github.com/ag-ui-protocol/ag-ui/tree/main/sdks/community/java), [Go](https://github.com/ag-ui-protocol/ag-ui/tree/main/sdks/community/go/example/client), and [CLI implementations](https://github.com/ag-ui-protocol/ag-ui/tree/main/apps/client-cli-example/src) in TypeScript |
| 18 | + |
| 19 | +This tutorial uses CopilotKit to create a sample app backed by a Strands agent that |
| 20 | +demonstrates some of the features supported by AG-UI. |
| 21 | + |
| 22 | +## Quickstart |
| 23 | + |
| 24 | +To get started, let's create a sample application with a Strands agent and a simple |
| 25 | +web client: |
| 26 | + |
| 27 | +``` |
| 28 | +npx copilotkit create -f aws-strands-py |
| 29 | +``` |
| 30 | + |
| 31 | +### Chat |
| 32 | + |
| 33 | +Chat is a familiar interface for exposing your agent, and AG-UI handles |
| 34 | +streaming messages between your users and agents: |
| 35 | + |
| 36 | +```jsx title="src/app/page.tsx" |
| 37 | +const labels = { |
| 38 | + title: "Popup Assistant", |
| 39 | + initial: "Hi, there! You\'re chatting with an agent. This agent comes with a few tools to get you started." |
| 40 | + } |
| 41 | +<CopilotSidebar |
| 42 | + clickOutsideToClose={false} |
| 43 | + defaultOpen={true} |
| 44 | + labels={labels} |
| 45 | +/> |
| 46 | +``` |
| 47 | + |
| 48 | +Learn more about the chat UI |
| 49 | +[in the CopilotKit docs](https://docs.copilotkit.ai/aws-strands/agentic-chat-ui). |
| 50 | + |
| 51 | +### Tool Based Generative UI (Rendering Tools) |
| 52 | + |
| 53 | +AG-UI lets you share tool information with a Generative UI so that it can be |
| 54 | +displayed to users: |
| 55 | + |
| 56 | +```jsx title="src/app/page.tsx" |
| 57 | +useCopilotAction({ |
| 58 | + name: "get_weather", |
| 59 | + description: "Get the weather for a given location.", |
| 60 | + available: "disabled", |
| 61 | + parameters: [ |
| 62 | + { name: "location", type: "string", required: true }, |
| 63 | + ], |
| 64 | + render: ({ args }) => { |
| 65 | + return <WeatherCard location={args.location} themeColor={themeColor} /> |
| 66 | + }, |
| 67 | +}); |
| 68 | +``` |
| 69 | + |
| 70 | +Learn more about the Tool-based Generative UI |
| 71 | +[in the CopilotKit docs](https://docs.copilotkit.ai/aws-strands/generative-ui/tool-based). |
| 72 | + |
| 73 | +### Shared State |
| 74 | + |
| 75 | +Strands agents are stateful, and synchronizing that state between your agents and |
| 76 | +your UIs enables powerful and fluid user experiences. State can be synchronized |
| 77 | +both ways so agents are automatically aware of changes made by your user or |
| 78 | +other parts of your application: |
| 79 | + |
| 80 | +```jsx |
| 81 | +const { state, setState } = useCoAgent<AgentState>({ |
| 82 | + name: "my_agent", |
| 83 | + initialState: { |
| 84 | + proverbs: [ |
| 85 | + "CopilotKit may be new, but its the best thing since sliced bread.", |
| 86 | + ], |
| 87 | + }, |
| 88 | +}) |
| 89 | +``` |
| 90 | + |
| 91 | +Learn more about shared state |
| 92 | +[in the CopilotKit docs](https://docs.copilotkit.ai/aws-strands/shared-state). |
| 93 | + |
| 94 | +### Try it out! |
| 95 | + |
| 96 | +``` |
| 97 | +npm install && npm run dev |
| 98 | +``` |
| 99 | + |
| 100 | +## Resources |
| 101 | + |
| 102 | +To see what other features you can build into your UI with AG-UI, refer to the CopilotKit docs: |
| 103 | + |
| 104 | +- [Agentic Generative UI](https://docs.copilotkit.ai/aws-strands/generative-ui/agentic) |
| 105 | +- [Human in the Loop](https://docs.copilotkit.ai/aws-strands/human-in-the-loop/agent) |
| 106 | +- [Frontend Actions](https://docs.copilotkit.ai/aws-strands/frontend-actions) |
| 107 | + |
| 108 | +Or try them out in the [AG-UI Dojo](https://dojo.ag-ui.com). |
0 commit comments