Prerequisites
Make sure to have the following installed:Running Eliza via Docker
Let’s run Eliza in a Docker container and connect to her viatelnet.
quit to exit Telnet. Congratulations! You’ve just brought Eliza to life.
Now let’s connect her to the Agent User Interaction Protocol.
Bridge Eliza with AG-UI
Now that we have our Eliza server running, let’s show how AG-UI can connect to any protocol—in this case, the somewhat arcane Telnet protocol.Project Setup
Let’s create a new project for our AG-UI bridge:AG-UI Recap
The Agent User Interaction Protocol is a framework that lets you connect agents to clients in a structured, event-driven way. Agents implement theAbstractAgent class from @ag-ui/client and emit events for each piece of
content, progress, etc.
ElizaAgent
We’ll create a special agent class,ElizaAgent, which:
- Launches a Telnet client to connect to our running Eliza server on localhost:2323.
- Sends the user’s last message to Eliza.
- Waits for the response, then emits AG-UI events to deliver that text back.
src/eliza-agent.ts:
Explanation
- Connection We create a TelnetClient and connect to our Eliza Telnet server.
- User Message We find the last user message from the AG-UI input. If none exists, we default to “Hello, Eliza”.
-
Emitting Events
RUN_STARTEDmeans the agent started processing the request.TEXT_MESSAGE_START/TEXT_MESSAGE_CONTENT/TEXT_MESSAGE_ENDtogether send the agent’s textual response to the AG-UI pipeline.RUN_FINISHEDmeans this run is over.
-
Round-Trip
- Write the user message to Eliza over Telnet.
- Listen for the response from Eliza.
- Emit that response as AG-UI events.
Putting It All Together
Create a main entry point filesrc/index.ts that sets up our AG-UI agent:
Bridging AG-UI to Any Protocol
This example demonstrates how to bridge AG-UI with an existing protocol. The key components are:- AG-UI Agent Implementation: Create a class that extends
AbstractAgentand implements therunmethod. - Implement
run(): Set up an agent or connect to an existing protocol. - Manage agent input: Send the right input to the agent (in our case, it’s the user’s last message).
- Send events: Handle the agent’s response and emit AG-UI events.
- HTTP/REST APIs
- WebSockets
- MQTT for IoT devices
- any other protocol