Agent Framework AG-UI Integration

1.0.0b260409 · active · verified Wed Apr 15

This library provides integration for the Agent Framework with the AG-UI protocol, enabling agents to communicate with AG-UI compliant frontends. It's currently in beta (1.0.0b260409) and offers components to bridge `agent-framework` agents to the AG-UI ecosystem. The project aims to facilitate the development of interactive AI agents with standardized UI interfaces.

Warnings

Install

Imports

Quickstart

Sets up an `AgUiServer` to expose a basic `agent-framework` agent via the AG-UI WebSocket protocol. This allows AG-UI compatible frontends to connect and interact with the agent. The example includes a simple `agent-framework` agent that replies to received messages.

import asyncio
from agent_framework.agent import Agent
from agent_framework.storage import InMemoryStorage
from agent_framework_ag_ui.server import AgUiServer

class MySimpleAgent(Agent):
    def __init__(self, name, storage):
        super().__init__(name, storage)

    async def handle_message(self, message):
        print(f"MySimpleAgent received message from UI: {message.content}")
        # Example: Reply to the UI
        await self.send_message(message.create_reply("Acknowledged from agent!"))

async def main():
    # Setup core agent-framework components
    storage = InMemoryStorage()
    agent = MySimpleAgent("MyTestAgent", storage)

    # Initialize the AG-UI server
    ag_ui_server = AgUiServer(host="127.0.0.1", port=8000)

    # Register the core agent with the AG-UI server to expose it to the UI
    await ag_ui_server.register_agent(agent)

    print(f"AG-UI Server starting on ws://127.0.0.1:8000. Connect a UI to interact.")
    print("Press Ctrl+C to stop.")
    await ag_ui_server.run() # This will block and run the server

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nServer stopped.")

view raw JSON →