Skip to content

Commit e883c5b

Browse files
committed
Add Azure AI Foundry
1 parent 20f0826 commit e883c5b

File tree

8 files changed

+1697
-0
lines changed

8 files changed

+1697
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Azure AI Foundry Configuration
2+
# Copy this file to .env and fill in your actual values
3+
4+
# Required: Azure AI Foundry Project Endpoint
5+
# Example: https://your-project.cognitiveservices.azure.com/
6+
AZURE_AI_FOUNDRY_PROJECT_ENDPOINT=https://ai-kinfey-agent-resource.services.ai.azure.com/api/projects/ai-kinfey-agent
7+
8+
# Required: Azure AI Agent Model Deployment Name
9+
# Example: gpt-4o, gpt-35-turbo, etc.
10+
AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME=gpt-4.1-nano
11+
12+
# Optional: Azure credentials (if not using DefaultAzureCredential)
13+
# AZURE_CLIENT_ID=
14+
# AZURE_CLIENT_SECRET=
15+
# AZURE_TENANT_ID=
16+
17+
# A2A Server Configuration
18+
A2A_HOST=localhost
19+
A2A_PORT=10007
20+
21+
# Logging Level (DEBUG, INFO, WARNING, ERROR)
22+
LOG_LEVEL=INFO
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# AI Foundry A2A Demo
2+
3+
A demonstration project showcasing the integration of Azure AI Foundry with the Agent-to-Agent (A2A) framework. This project implements an intelligent calendar management agent with the following capabilities:
4+
5+
## Features
6+
7+
- 🤖 **AI Foundry Integration**: Build intelligent agents using Azure AI Foundry
8+
- 📅 **Calendar Management**: Check schedule availability, get upcoming events
9+
- 🔄 **A2A Framework**: Support agent-to-agent communication and collaboration
10+
- 💬 **Conversation Capabilities**: Natural language processing and multi-turn conversations
11+
- 🛠️ **Tool Integration**: Simulated calendar API tool integration
12+
13+
## Project Structure
14+
15+
```
16+
├── foundry_agent.py # AI Foundry calendar agent implementation
17+
├── foundry_agent_executor.py # A2A framework executor
18+
├── demo.ipynb # Interactive demonstration notebook
19+
├── __main__.py # Main application
20+
├── aifoundry_agent.py # Base AI Foundry agent
21+
├── pyproject.toml # Project dependencies configuration
22+
└── .env.template # Environment variables template
23+
```
24+
25+
## Quick Start
26+
27+
### 1. Environment Setup
28+
29+
```bash
30+
# Clone the project
31+
cd aifoundry_a2a_demo
32+
33+
# Copy environment variables template
34+
cp .env.template .env
35+
36+
# Edit the .env file and fill in your Azure configuration
37+
```
38+
39+
### 2. Install Dependencies
40+
41+
```bash
42+
# Using uv (recommended)
43+
uv sync
44+
45+
# Or using pip
46+
pip install -e .
47+
```
48+
49+
### 3. Configure Azure AI Foundry
50+
51+
Set the following required environment variables in the `.env` file:
52+
53+
```env
54+
AZURE_AI_FOUNDRY_PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com/
55+
AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME=gpt-4o
56+
```
57+
58+
### 4. Run the Demo
59+
60+
Open terminal
61+
62+
```bash
63+
# Start Your Azure AI Foundry Agent
64+
uv run .
65+
```
66+
67+
Open another tag in terminal
68+
69+
```bash
70+
# Test
71+
uv run test_client.py
72+
```
73+
74+
75+
## Agent Capabilities
76+
77+
### Calendar Management Skills
78+
79+
1. **Check Availability** (`check_availability`)
80+
- Check schedule arrangements for specific time periods
81+
- Example: "Am I free tomorrow from 2 PM to 3 PM?"
82+
83+
2. **Get Upcoming Events** (`get_upcoming_events`)
84+
- Get future calendar events
85+
- Example: "What meetings do I have today?"
86+
87+
3. **Calendar Management** (`calendar_management`)
88+
- General calendar management and scheduling assistant
89+
- Example: "Help me optimize tomorrow's schedule"
90+
91+
### Conversation Examples
92+
93+
```
94+
User: Hello, can you help me manage my calendar?
95+
Agent: Of course! I'm the AI Foundry calendar agent, and I can help you check schedule availability, view upcoming events, and optimize your schedule. What do you need help with?
96+
97+
User: Am I free tomorrow from 2 PM to 3 PM?
98+
Agent: Let me check your availability for tomorrow from 2 PM to 3 PM...
99+
```
100+
101+
## Technical Architecture
102+
103+
### Core Components
104+
105+
1. **FoundryCalendarAgent**:
106+
- Core implementation of Azure AI Foundry agent
107+
- Handles conversation logic and tool calls
108+
109+
2. **FoundryAgentExecutor**:
110+
- A2A framework executor
111+
- Handles request routing and state management
112+
113+
3. **A2A Integration**:
114+
- Agent card definitions
115+
- Skills and capabilities declarations
116+
- Message transformation and processing
117+
118+
### Key Features
119+
120+
- **Asynchronous Processing**: Full support for Python asynchronous programming
121+
- **Error Handling**: Complete exception handling and logging
122+
- **State Management**: Session and thread state management
123+
- **Extensibility**: Easy to add new tools and skills
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import asyncio
2+
import logging
3+
import os
4+
5+
import click
6+
import uvicorn
7+
8+
from foundry_agent_executor import create_foundry_agent_executor
9+
from dotenv import load_dotenv
10+
from starlette.applications import Starlette
11+
from starlette.requests import Request
12+
from starlette.responses import PlainTextResponse
13+
from starlette.routing import Route
14+
15+
from a2a.server.apps import A2AStarletteApplication
16+
from a2a.server.request_handlers import DefaultRequestHandler
17+
from a2a.server.tasks import InMemoryTaskStore
18+
from a2a.types import AgentCapabilities, AgentCard, AgentSkill
19+
20+
21+
load_dotenv()
22+
23+
logging.basicConfig(level=logging.INFO)
24+
logger = logging.getLogger(__name__)
25+
26+
27+
@click.command()
28+
@click.option('--host', 'host', default='localhost')
29+
@click.option('--port', 'port', default=10007)
30+
def main(host: str, port: int):
31+
"""
32+
Run the AI Foundry A2A demo server.
33+
"""
34+
# Verify required environment variables
35+
required_env_vars = [
36+
'AZURE_AI_FOUNDRY_PROJECT_ENDPOINT',
37+
'AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME'
38+
]
39+
40+
missing_vars = [var for var in required_env_vars if not os.getenv(var)]
41+
if missing_vars:
42+
raise ValueError(
43+
f"Missing required environment variables: {', '.join(missing_vars)}"
44+
)
45+
46+
# Define agent skills
47+
skills = [
48+
AgentSkill(
49+
id='check_availability',
50+
name='Check Calendar Availability',
51+
description="Check if a user is available at a specific time using their calendar",
52+
tags=['calendar', 'scheduling'],
53+
examples=[
54+
'Am I free from 10am to 11am tomorrow?',
55+
'Check my availability for next Tuesday afternoon',
56+
'Do I have any conflicts on Friday morning?'
57+
],
58+
),
59+
AgentSkill(
60+
id='get_upcoming_events',
61+
name='Get Upcoming Events',
62+
description="Retrieve upcoming calendar events for the user",
63+
tags=['calendar', 'events'],
64+
examples=[
65+
'What meetings do I have today?',
66+
'Show me my schedule for this week',
67+
'What\'s coming up in the next few hours?'
68+
],
69+
),
70+
AgentSkill(
71+
id='calendar_management',
72+
name='Calendar Management',
73+
description="General calendar management and scheduling assistance",
74+
tags=['calendar', 'productivity'],
75+
examples=[
76+
'Help me manage my calendar',
77+
'When is the best time for a meeting?',
78+
'Optimize my schedule for tomorrow'
79+
],
80+
)
81+
]
82+
83+
# Create agent card
84+
agent_card = AgentCard(
85+
name='AI Foundry Calendar Agent',
86+
description="An intelligent calendar management agent powered by Azure AI Foundry. "
87+
"I can help you check availability, manage events, and optimize your schedule.",
88+
url=f'http://{host}:{port}/',
89+
version='1.0.0',
90+
defaultInputModes=['text'],
91+
defaultOutputModes=['text'],
92+
capabilities=AgentCapabilities(streaming=True),
93+
skills=skills,
94+
)
95+
96+
# Create agent executor
97+
agent_executor = create_foundry_agent_executor(agent_card)
98+
99+
# Create request handler
100+
request_handler = DefaultRequestHandler(
101+
agent_executor=agent_executor,
102+
task_store=InMemoryTaskStore()
103+
)
104+
105+
# Create A2A application
106+
a2a_app = A2AStarletteApplication(
107+
agent_card=agent_card,
108+
http_handler=request_handler
109+
)
110+
111+
# Get routes
112+
routes = a2a_app.routes()
113+
114+
# Add health check endpoint
115+
async def health_check(request: Request) -> PlainTextResponse:
116+
return PlainTextResponse('AI Foundry Calendar Agent is running!')
117+
118+
routes.append(
119+
Route(
120+
path='/health',
121+
methods=['GET'],
122+
endpoint=health_check
123+
)
124+
)
125+
126+
# Create Starlette app
127+
app = Starlette(routes=routes)
128+
129+
# Log startup information
130+
logger.info(f"Starting AI Foundry Calendar Agent on {host}:{port}")
131+
logger.info(f"Agent card: {agent_card.name}")
132+
logger.info(f"Skills: {[skill.name for skill in skills]}")
133+
logger.info(f"Health check available at: http://{host}:{port}/health")
134+
135+
# Run the server
136+
uvicorn.run(app, host=host, port=port)
137+
138+
139+
if __name__ == '__main__':
140+
main()

0 commit comments

Comments
 (0)