mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
35a8565495
* Add AG-UI integration * Fix tests. PR feedback * Cleanup * PR Feedback * Improve README and getting started experience * Fix links
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
"""AG-UI server example."""
|
|
|
|
import os
|
|
|
|
from agent_framework import ChatAgent
|
|
from agent_framework.azure import AzureOpenAIChatClient
|
|
from dotenv import load_dotenv
|
|
from fastapi import FastAPI
|
|
|
|
from agent_framework_ag_ui import add_agent_framework_fastapi_endpoint
|
|
|
|
load_dotenv()
|
|
|
|
# Read required configuration
|
|
endpoint = os.environ.get("AZURE_OPENAI_ENDPOINT")
|
|
deployment_name = os.environ.get("AZURE_OPENAI_CHAT_DEPLOYMENT_NAME")
|
|
|
|
if not endpoint:
|
|
raise ValueError("AZURE_OPENAI_ENDPOINT environment variable is required")
|
|
if not deployment_name:
|
|
raise ValueError("AZURE_OPENAI_CHAT_DEPLOYMENT_NAME environment variable is required")
|
|
|
|
# Create the AI agent
|
|
agent = ChatAgent(
|
|
name="AGUIAssistant",
|
|
instructions="You are a helpful assistant.",
|
|
chat_client=AzureOpenAIChatClient(
|
|
endpoint=endpoint,
|
|
deployment_name=deployment_name,
|
|
),
|
|
)
|
|
|
|
# Create FastAPI app
|
|
app = FastAPI(title="AG-UI Server")
|
|
|
|
# Register the AG-UI endpoint
|
|
add_agent_framework_fastapi_endpoint(app, agent, "/")
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="127.0.0.1", port=5100)
|