-
Notifications
You must be signed in to change notification settings - Fork 876
Add Microsoft Agent Framework Python integration support #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
moonbox3
wants to merge
2
commits into
ag-ui-protocol:main
Choose a base branch
from
moonbox3:maf-python-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,738
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
integrations/microsoft-agent-framework/python/examples/.env.example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Environment variables for Microsoft Agent Framework examples | ||
|
|
||
| # Azure OpenAI Configuration | ||
| AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/ | ||
| AZURE_OPENAI_API_KEY=your_azure_openai_api_key_here | ||
| AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=your_deployment_name | ||
|
|
||
| # OpenAI Configuration (alternative to Azure OpenAI) | ||
| # OPENAI_API_KEY=your_openai_api_key_here | ||
| # OPENAI_CHAT_MODEL_ID=your_chat_model_id_here | ||
|
|
||
| # Server Configuration | ||
| PORT=8888 |
48 changes: 48 additions & 0 deletions
48
integrations/microsoft-agent-framework/python/examples/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
|
|
||
| # Virtual environments | ||
| venv/ | ||
| ENV/ | ||
| env/ | ||
| .venv | ||
|
|
||
| # Poetry | ||
| poetry.lock | ||
|
|
||
| # Environment variables | ||
| .env | ||
| .env.local | ||
|
|
||
| # IDEs | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Logs | ||
| *.log |
119 changes: 119 additions & 0 deletions
119
integrations/microsoft-agent-framework/python/examples/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Microsoft Agent Framework AG-UI Integration | ||
|
|
||
| This directory contains examples for using the Microsoft Agent Framework with the AG-UI protocol in the Dojo application. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.10 or higher | ||
| - [uv](https://docs.astral.sh/uv/) for dependency management | ||
| - An OpenAI API key or Azure OpenAI endpoint | ||
|
|
||
| ## Installation | ||
|
|
||
| 1. Install dependencies: | ||
|
|
||
| ```bash | ||
| cd integrations/microsoft-agent-framework/python/examples | ||
| uv sync | ||
| ``` | ||
|
|
||
| 2. Create a `.env` file based on `.env.example`: | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| 3. Add your API credentials to `.env`: | ||
|
|
||
| ```bash | ||
| # For OpenAI | ||
| OPENAI_API_KEY=your_api_key_here | ||
| OPENAI_CHAT_MODEL_ID=your_model_here | ||
|
|
||
| # Or for Azure OpenAI | ||
| AZURE_OPENAI_ENDPOINT=your_endpoint_here | ||
| AZURE_OPENAI_API_KEY=your_api_key_here | ||
| AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=your_deployment_here | ||
| ``` | ||
|
|
||
| ## Running the Examples | ||
|
|
||
| ### 1. Start the Backend Server | ||
|
|
||
| In the examples directory, start the Dojo backend server: | ||
|
|
||
| ```bash | ||
| cd integrations/microsoft-agent-framework/python/examples | ||
| uv run dev | ||
| ``` | ||
|
|
||
| The server will start on `http://localhost:8888` by default. | ||
|
|
||
| ### 2. Start the Dojo Frontend | ||
|
|
||
| In a separate terminal, start the Dojo web application: | ||
|
|
||
| ```bash | ||
| cd apps/dojo | ||
| pnpm dev | ||
| ``` | ||
|
|
||
| The Dojo frontend will be available at `http://localhost:3000`. | ||
|
|
||
| ### 3. Connect to Your Agent | ||
|
|
||
| 1. Open `http://localhost:3000` in your browser | ||
| 2. Configure the server URL to `http://localhost:8888` | ||
| 3. Select one "Microsoft Agent Framework (Python)" from the dropdown | ||
| 4. Start exploring the samples | ||
|
|
||
| ## Available Endpoints | ||
|
|
||
| The server exposes the following example agents demonstrating all 7 AG-UI features: | ||
|
|
||
| - `/agentic_chat` - Basic conversational agent with tool calling (Feature 1: Agentic Chat) | ||
| - `/backend_tool_rendering` - Agent demonstrating backend tool rendering (Feature 2: Backend Tool Rendering) | ||
| - `/human_in_the_loop` - Agent with human-in-the-loop workflows (Feature 3: Human in the Loop) | ||
| - `/agentic_generative_ui` - Agent that breaks down tasks into steps with streaming updates (Feature 4: Agentic Generative UI) | ||
| - `/tool_based_generative_ui` - Agent that generates custom UI components (Feature 5: Tool-based Generative UI) | ||
| - `/shared_state` - Agent with bidirectional state synchronization (Feature 6: Shared State) | ||
| - `/predictive_state_updates` - Agent with predictive state updates during tool execution (Feature 7: Predictive State Updates) | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| examples/ | ||
| ├── agents/ | ||
| │ ├── agentic_chat/ # Feature 1: Basic chat agent | ||
| │ ├── backend_tool_rendering/ # Feature 2: Backend tool rendering | ||
| │ ├── human_in_the_loop/ # Feature 3: Human-in-the-loop | ||
| │ ├── agentic_generative_ui/ # Feature 4: Streaming state updates | ||
| │ ├── tool_based_generative_ui/ # Feature 5: Custom UI components | ||
| │ ├── shared_state/ # Feature 6: Bidirectional state sync | ||
| │ ├── predictive_state_updates/ # Feature 7: Predictive state updates | ||
| │ └── dojo.py # FastAPI application setup | ||
| ├── pyproject.toml # Dependencies and scripts | ||
| ├── .env.example # Environment variable template | ||
| └── README.md # This file | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| To add a new example agent: | ||
|
|
||
| 1. Create a new directory under `agents/` | ||
| 2. Add an `agent.py` file with your agent implementation | ||
| 3. Import and register it in `agents/dojo.py` | ||
|
|
||
| ## Dependencies | ||
|
|
||
| This integration uses: | ||
|
|
||
| - `agent-framework-ag-ui` - Microsoft Agent Framework AG-UI adapter | ||
| - `fastapi` - Web framework for the server | ||
| - `uvicorn` - ASGI server | ||
| - `python-dotenv` - Environment variable management | ||
|
|
||
| ## License | ||
|
|
||
| MIT |
1 change: 1 addition & 0 deletions
1
integrations/microsoft-agent-framework/python/examples/agents/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Agent package.""" |
71 changes: 71 additions & 0 deletions
71
integrations/microsoft-agent-framework/python/examples/agents/dojo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """Microsoft Agent Framework Python Dojo Example Server. | ||
|
|
||
| This provides a FastAPI application that demonstrates how to use the | ||
| Microsoft Agent Framework with the AG-UI protocol. It includes examples for | ||
| each of the AG-UI dojo features: | ||
| - Agentic Chat | ||
| - Human in the Loop | ||
| - Backend Tool Rendering | ||
| - Agentic Generative UI | ||
| - Tool-based Generative UI | ||
| - Shared State | ||
| - Predictive State Updates | ||
|
|
||
| All agent implementations are from the agent-framework-ag-ui package examples. | ||
| Reference: https://github.com/microsoft/agent-framework/tree/main/python/packages/ag-ui/examples/agents | ||
| """ | ||
|
|
||
| import os | ||
| import uvicorn | ||
| from fastapi import FastAPI | ||
| from dotenv import load_dotenv | ||
|
|
||
| from agent_framework_ag_ui import add_agent_framework_fastapi_endpoint | ||
| from agent_framework_ag_ui_examples.agents import ( | ||
| simple_agent, | ||
| weather_agent, | ||
| human_in_the_loop_agent, | ||
| task_steps_agent_wrapped, | ||
| ui_generator_agent, | ||
| recipe_agent, | ||
| document_writer_agent, | ||
| ) | ||
|
|
||
| load_dotenv() | ||
|
|
||
| app = FastAPI(title="Microsoft Agent Framework Python Dojo") | ||
|
|
||
| # Agentic Chat - simple_agent | ||
| add_agent_framework_fastapi_endpoint(app, simple_agent, "/agentic_chat") | ||
|
|
||
| # Backend Tool Rendering - weather_agent | ||
| add_agent_framework_fastapi_endpoint(app, weather_agent, "/backend_tool_rendering") | ||
|
|
||
| # Human in the Loop - human_in_the_loop_agent with state configuration | ||
| add_agent_framework_fastapi_endpoint( | ||
| app, | ||
| human_in_the_loop_agent, | ||
| "/human_in_the_loop", | ||
| ) | ||
|
|
||
| # Agentic Generative UI - task_steps_agent_wrapped | ||
| add_agent_framework_fastapi_endpoint(app, task_steps_agent_wrapped, "/agentic_generative_ui") | ||
|
|
||
| # Tool-based Generative UI - ui_generator_agent | ||
| add_agent_framework_fastapi_endpoint(app, ui_generator_agent, "/tool_based_generative_ui") | ||
|
|
||
| # Shared State - recipe_agent | ||
| add_agent_framework_fastapi_endpoint(app, recipe_agent, "/shared_state") | ||
|
|
||
| # Predictive State Updates - document_writer_agent | ||
| add_agent_framework_fastapi_endpoint(app, document_writer_agent, "/predictive_state_updates") | ||
|
|
||
|
|
||
| def main(): | ||
| """Main function to start the FastAPI server.""" | ||
| port = int(os.getenv("PORT", "8888")) | ||
| uvicorn.run(app, host="0.0.0.0", port=port) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
25 changes: 25 additions & 0 deletions
25
integrations/microsoft-agent-framework/python/examples/pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| [project] | ||
| name = "microsoft-agent-framework-dojo" | ||
| version = "0.1.0" | ||
| description = "Microsoft Agent Framework Python examples for AG-UI Dojo" | ||
| authors = [{ name = "Microsoft Agent Framework Team" }] | ||
| readme = "README.md" | ||
| requires-python = ">=3.10" | ||
| dependencies = [ | ||
| "agent-framework-ag-ui>=1.0.0b251106.post1", | ||
| "agent-framework-core>=1.0.0b251105", | ||
| "python-dotenv>=1.0.0", | ||
| ] | ||
|
|
||
| [tool.hatch.metadata] | ||
| allow-direct-references = true | ||
|
|
||
| [project.scripts] | ||
| dev = "agents.dojo:main" | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["agents"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was auto-generated when I started the Dojo frontend. Should I keep or revert?