Agent Framework AG-UI Integration
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
- breaking This library is currently in beta. APIs and internal implementations are subject to change without strict backward compatibility guarantees. The core `agent-framework` it depends on is also under active development.
- gotcha This library is an *integration* for `agent-framework`. It does not provide the core agent capabilities itself. Users must understand and implement `agent-framework` agents to effectively use this integration.
- gotcha The `agent-framework` ecosystem, including `agent-framework-ag-ui`, is entirely asynchronous. All interactions and server operations are `async`/`await` based, requiring an `asyncio` event loop.
- gotcha This library implements the AG-UI protocol. Effective use requires understanding the protocol's message types and interaction patterns for building compatible UIs or connecting to existing AG-UI frontends.
Install
-
pip install agent-framework-ag-ui
Imports
- AgUiServer
from agent_framework_ag_ui.server import AgUiServer
- AgUiAgent
from agent_framework_ag_ui.agent import AgUiAgent
Quickstart
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.")