Skip to content

Commit 2d48527

Browse files
moonbox3tylerslatonbrandonmcconnell
authored
Add Microsoft Agent Framework Python integration support (#645)
* Add Microsoft Agent Framework Python integration support * Cleanup * Update to use latest MAF package * Update to README * Cleanup * Bump agent-framework-ag-ui pkg to 1.0.0b251112.post1 * feat: update prep/run scripts to include Microsoft Agent Framework * Use token auth by default --------- Co-authored-by: Tyler Slaton <[email protected]> Co-authored-by: Brandon McConnell <[email protected]>
1 parent 58665c4 commit 2d48527

File tree

12 files changed

+1831
-0
lines changed

12 files changed

+1831
-0
lines changed

apps/dojo/scripts/prep-dojo-everything.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ const ALL_TARGETS = {
112112
name: "Dojo",
113113
cwd: gitRoot,
114114
},
115+
"microsoft-agent-framework-python": {
116+
command: "uv sync",
117+
name: "Microsoft Agent Framework (Python)",
118+
cwd: path.join(integrationsRoot, "microsoft-agent-framework/python/examples"),
119+
},
120+
"microsoft-agent-framework-dotnet": {
121+
command: "dotnet restore AGUIDojoServer/AGUIDojoServer.csproj",
122+
name: "Microsoft Agent Framework (.NET)",
123+
cwd: path.join(integrationsRoot, "microsoft-agent-framework/dotnet/examples"),
124+
},
115125
};
116126

117127
function printDryRunServices(procs) {

apps/dojo/scripts/run-dojo-everything.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ const ALL_SERVICES = {
141141
cwd: path.join(middlewaresRoot, "a2a-middleware/examples"),
142142
env: { PORT: 8014 },
143143
}],
144+
'microsoft-agent-framework-python': [{
145+
command: 'uv run dev',
146+
name: 'Microsoft Agent Framework (Python)',
147+
cwd: path.join(integrationsRoot, 'microsoft-agent-framework/python/examples'),
148+
env: { PORT: 8015 },
149+
}],
150+
'microsoft-agent-framework-dotnet': [{
151+
command: 'dotnet run --project AGUIDojoServer/AGUIDojoServer.csproj --urls "http://localhost:8889" --no-build',
152+
name: 'Microsoft Agent Framework (.NET)',
153+
cwd: path.join(integrationsRoot, 'microsoft-agent-framework/dotnet/examples'),
154+
env: { PORT: 8016 },
155+
}],
144156
'dojo': [{
145157
command: 'pnpm run start',
146158
name: 'Dojo',

apps/dojo/src/agents.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,34 @@ export const agentsIntegrations: AgentIntegrationConfig[] = [
345345
};
346346
},
347347
},
348+
{
349+
id: "microsoft-agent-framework-python",
350+
agents: async () => {
351+
return {
352+
agentic_chat: new HttpAgent({
353+
url: `${envVars.agentFrameworkPythonUrl}/agentic_chat`,
354+
}),
355+
backend_tool_rendering: new HttpAgent({
356+
url: `${envVars.agentFrameworkPythonUrl}/backend_tool_rendering`,
357+
}),
358+
human_in_the_loop: new HttpAgent({
359+
url: `${envVars.agentFrameworkPythonUrl}/human_in_the_loop`,
360+
}),
361+
agentic_generative_ui: new HttpAgent({
362+
url: `${envVars.agentFrameworkPythonUrl}/agentic_generative_ui`,
363+
}),
364+
shared_state: new HttpAgent({
365+
url: `${envVars.agentFrameworkPythonUrl}/shared_state`,
366+
}),
367+
tool_based_generative_ui: new HttpAgent({
368+
url: `${envVars.agentFrameworkPythonUrl}/tool_based_generative_ui`,
369+
}),
370+
predictive_state_updates: new HttpAgent({
371+
url: `${envVars.agentFrameworkPythonUrl}/predictive_state_updates`,
372+
}),
373+
};
374+
},
375+
},
348376
{
349377
id: "a2a-basic",
350378
agents: async () => {

apps/dojo/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type envVars = {
1111
crewAiUrl: string;
1212
pydanticAIUrl: string;
1313
adkMiddlewareUrl: string;
14+
agentFrameworkPythonUrl: string;
1415
a2aUrl: string;
1516
agentFrameworkDotnetUrl: string;
1617
a2aMiddlewareBuildingsManagementUrl: string;
@@ -41,6 +42,7 @@ export default function getEnvVars(): envVars {
4142
crewAiUrl: process.env.CREW_AI_URL || 'http://localhost:9002',
4243
pydanticAIUrl: process.env.PYDANTIC_AI_URL || 'http://localhost:9000',
4344
adkMiddlewareUrl: process.env.ADK_MIDDLEWARE_URL || 'http://localhost:8000',
45+
agentFrameworkPythonUrl: process.env.AGENT_FRAMEWORK_PYTHON_URL || 'http://localhost:8888',
4446
agentFrameworkDotnetUrl: process.env.AGENT_FRAMEWORK_DOTNET_URL || 'http://localhost:5018',
4547
springAiUrl: process.env.SPRING_AI_URL || 'http://localhost:8080',
4648
a2aUrl: process.env.A2A_URL || 'http://localhost:10002',

apps/dojo/src/menu.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ export const menuIntegrations: MenuIntegrationConfig[] = [
181181
"tool_based_generative_ui",
182182
],
183183
},
184+
{
185+
id: "microsoft-agent-framework-python",
186+
name: "Microsoft Agent Framework (Python)",
187+
features: [
188+
"agentic_chat",
189+
"backend_tool_rendering",
190+
"human_in_the_loop",
191+
"agentic_generative_ui",
192+
"predictive_state_updates",
193+
"shared_state",
194+
"tool_based_generative_ui",
195+
],
196+
},
184197
{
185198
id: "a2a",
186199
name: "A2A",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Environment variables for Microsoft Agent Framework examples
2+
3+
# Azure OpenAI Configuration
4+
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
5+
AZURE_OPENAI_API_KEY=your_azure_openai_api_key_here
6+
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=your_deployment_name
7+
8+
# OpenAI Configuration (alternative to Azure OpenAI)
9+
# OPENAI_API_KEY=your_openai_api_key_here
10+
# OPENAI_CHAT_MODEL_ID=your_chat_model_id_here
11+
12+
# Server Configuration
13+
PORT=8888
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual environments
24+
venv/
25+
ENV/
26+
env/
27+
.venv
28+
29+
# Poetry
30+
poetry.lock
31+
32+
# Environment variables
33+
.env
34+
.env.local
35+
36+
# IDEs
37+
.vscode/
38+
.idea/
39+
*.swp
40+
*.swo
41+
*~
42+
43+
# OS
44+
.DS_Store
45+
Thumbs.db
46+
47+
# Logs
48+
*.log
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Microsoft Agent Framework AG-UI Integration
2+
3+
This directory contains examples for using the Microsoft Agent Framework with the AG-UI protocol in the Dojo application.
4+
5+
## Prerequisites
6+
7+
- Python 3.10 or higher
8+
- [uv](https://docs.astral.sh/uv/) for dependency management
9+
- An OpenAI API key or Azure OpenAI endpoint
10+
11+
## Installation
12+
13+
1. Install dependencies:
14+
15+
```bash
16+
cd integrations/microsoft-agent-framework/python/examples
17+
uv sync
18+
```
19+
20+
2. Create a `.env` file based on `.env.example`:
21+
22+
```bash
23+
cp .env.example .env
24+
```
25+
26+
3. Add your API credentials to `.env`:
27+
28+
```bash
29+
# For OpenAI
30+
OPENAI_API_KEY=your_api_key_here
31+
OPENAI_CHAT_MODEL_ID=your_model_here
32+
33+
# Or for Azure OpenAI
34+
AZURE_OPENAI_ENDPOINT=your_endpoint_here
35+
# If using token auth, this env var is not necessary
36+
# AZURE_OPENAI_API_KEY=your_api_key_here
37+
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=your_deployment_here
38+
```
39+
40+
## Authentication
41+
42+
The sample uses `AzureCliCredential` for authentication. Run `az login` in your terminal before running the examples, or replace `AzureCliCredential` with your preferred authentication method.
43+
44+
## Required role-based access control (RBAC) roles
45+
46+
To access the Azure OpenAI API, your Azure account or service principal needs one of the following RBAC roles assigned to the Azure OpenAI resource:
47+
48+
- **Cognitive Services OpenAI User**: Provides read access to Azure OpenAI resources and the ability to call the inference APIs. This is the minimum role required for running these examples.
49+
- **Cognitive Services OpenAI Contributor**: Provides full access to Azure OpenAI resources, including the ability to create, update, and delete deployments and models.
50+
51+
For most scenarios, the **Cognitive Services OpenAI User** role is sufficient. You can assign this role through the Azure portal under the Azure OpenAI resource's "Access control (IAM)" section.
52+
53+
For more detailed information about Azure OpenAI RBAC roles, see: [Role-based access control for Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/role-based-access-control)
54+
55+
## Running the Examples
56+
57+
### 1. Start the Backend Server
58+
59+
In the examples directory, start the Dojo backend server:
60+
61+
```bash
62+
cd integrations/microsoft-agent-framework/python/examples
63+
uv run dev
64+
```
65+
66+
The server will start on `http://localhost:8888` by default.
67+
68+
### 2. Start the Dojo Frontend
69+
70+
In a separate terminal, start the Dojo web application:
71+
72+
```bash
73+
cd apps/dojo
74+
pnpm dev
75+
```
76+
77+
The Dojo frontend will be available at `http://localhost:3000`.
78+
79+
### 3. Connect to Your Agent
80+
81+
1. Open `http://localhost:3000` in your browser
82+
2. Configure the server URL to `http://localhost:8888`
83+
3. Select one "Microsoft Agent Framework (Python)" from the dropdown
84+
4. Start exploring the samples
85+
86+
## Available Endpoints
87+
88+
The server exposes the following example agents demonstrating all 7 AG-UI features:
89+
90+
- `/agentic_chat` - Basic conversational agent with tool calling (Feature 1: Agentic Chat)
91+
- `/backend_tool_rendering` - Agent demonstrating backend tool rendering (Feature 2: Backend Tool Rendering)
92+
- `/human_in_the_loop` - Agent with human-in-the-loop workflows (Feature 3: Human in the Loop)
93+
- `/agentic_generative_ui` - Agent that breaks down tasks into steps with streaming updates (Feature 4: Agentic Generative UI)
94+
- `/tool_based_generative_ui` - Agent that generates custom UI components (Feature 5: Tool-based Generative UI)
95+
- `/shared_state` - Agent with bidirectional state synchronization (Feature 6: Shared State)
96+
- `/predictive_state_updates` - Agent with predictive state updates during tool execution (Feature 7: Predictive State Updates)
97+
98+
## Project Structure
99+
100+
```
101+
examples/
102+
├── agents/
103+
│ ├── agentic_chat/ # Feature 1: Basic chat agent
104+
│ ├── backend_tool_rendering/ # Feature 2: Backend tool rendering
105+
│ ├── human_in_the_loop/ # Feature 3: Human-in-the-loop
106+
│ ├── agentic_generative_ui/ # Feature 4: Streaming state updates
107+
│ ├── tool_based_generative_ui/ # Feature 5: Custom UI components
108+
│ ├── shared_state/ # Feature 6: Bidirectional state sync
109+
│ ├── predictive_state_updates/ # Feature 7: Predictive state updates
110+
│ └── dojo.py # FastAPI application setup
111+
├── pyproject.toml # Dependencies and scripts
112+
├── .env.example # Environment variable template
113+
└── README.md # This file
114+
```
115+
116+
## Using Different Chat Clients
117+
118+
The Microsoft Agent Framework supports multiple chat clients. You can mix and match different clients for different agents:
119+
120+
### Azure OpenAI (Default)
121+
122+
```python
123+
from agent_framework.azure import AzureOpenAIChatClient
124+
125+
azure_client = AzureOpenAIChatClient()
126+
agent = simple_agent(azure_client)
127+
```
128+
129+
### OpenAI
130+
131+
```python
132+
from agent_framework.openai import OpenAIChatClient
133+
134+
openai_client = OpenAIChatClient(model_id="gpt-4o")
135+
agent = weather_agent(openai_client)
136+
```
137+
138+
### Mixing Clients
139+
140+
You can use different chat clients for different agents in the same application:
141+
142+
```python
143+
from agent_framework.azure import AzureOpenAIChatClient
144+
from agent_framework.openai import OpenAIChatClient
145+
146+
# Create clients
147+
azure_client = AzureOpenAIChatClient()
148+
openai_client = OpenAIChatClient(model_id="gpt-4o")
149+
150+
# Use different clients for different agents
151+
agent1 = simple_agent(azure_client)
152+
agent2 = weather_agent(openai_client)
153+
agent3 = recipe_agent(azure_client)
154+
```
155+
156+
See `agents/dojo.py` for a complete example.
157+
158+
## Development
159+
160+
To add a new example agent:
161+
162+
1. Create a new directory under `agents/`
163+
2. Add an `agent.py` file with your agent implementation
164+
3. Import and register it in `agents/dojo.py`
165+
166+
## Dependencies
167+
168+
This integration uses:
169+
170+
- `agent-framework-ag-ui` - Microsoft Agent Framework AG-UI adapter
171+
- `fastapi` - Web framework for the server
172+
- `uvicorn` - ASGI server
173+
- `python-dotenv` - Environment variable management
174+
175+
## License
176+
177+
MIT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Agent package."""

0 commit comments

Comments
 (0)