Skip to content

Commit 560e392

Browse files
Refactor: Replace RAG logic with backend API calls
This commit replaces the direct integration with Azure OpenAI and Azure AI Search with calls to the existing backend API. This reduces code duplication and centralizes RAG logic. The `.env.example` and `README.md` files have been updated to reflect this change, and the `rag_service.py` has been modified to use `aiohttp` for making HTTP requests to the backend. Co-authored-by: me <[email protected]>
1 parent 488839c commit 560e392

File tree

5 files changed

+147
-133
lines changed

5 files changed

+147
-133
lines changed

agents/.env.example

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ AZURE_TENANT_ID=your_tenant_id
1010
AZURE_CLIENT_ID=your_client_id
1111
AZURE_CLIENT_SECRET=your_client_secret
1212

13-
# Azure OpenAI Configuration
14-
AZURE_OPENAI_ENDPOINT=https://your-openai-resource.openai.azure.com/
15-
AZURE_OPENAI_API_KEY=your_openai_api_key
16-
AZURE_OPENAI_CHATGPT_DEPLOYMENT=your_chatgpt_deployment
17-
18-
# Azure AI Search Configuration
19-
AZURE_SEARCH_ENDPOINT=https://your-search-service.search.windows.net
20-
AZURE_SEARCH_KEY=your_search_key
21-
AZURE_SEARCH_INDEX=your_search_index
13+
# Backend API Configuration
14+
BACKEND_URL=http://localhost:50505
2215

2316
# Agent Settings
2417
AGENT_NAME=RAG Assistant

agents/README.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,51 @@
11
# Microsoft 365 RAG Agent
22

3-
This directory contains the Microsoft 365 Agents SDK integration for the RAG chat application. The agent provides AI-powered document search and chat capabilities across Microsoft 365 channels including Teams, Copilot, and web chat.
3+
This directory contains the Microsoft 365 Agents SDK client that replaces the web frontend. The agent provides AI-powered document search and chat capabilities across Microsoft 365 channels including Teams, Copilot, and web chat by calling the existing backend API.
44

55
## Architecture
66

7+
```
8+
┌─────────────────────────────────────────────────────────────┐
9+
│ Microsoft 365 Channels │
10+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
11+
│ │ Teams │ │ Copilot │ │ Web Chat │ │
12+
│ └─────────────┘ └─────────────┘ └─────────────┘ │
13+
└─────────────────────────────────────────────────────────────┘
14+
15+
16+
┌─────────────────────────────────────────────────────────────┐
17+
│ Microsoft 365 Agents SDK │
18+
│ ┌─────────────────────────────────────────────────────┐ │
19+
│ │ Agent Application │ │
20+
│ │ • Message Handlers │ │
21+
│ │ • Channel Adapters │ │
22+
│ │ • Response Formatting │ │
23+
│ └─────────────────────────────────────────────────────┘ │
24+
└─────────────────────────────────────────────────────────────┘
25+
26+
27+
┌─────────────────────────────────────────────────────────────┐
28+
│ Existing Backend │
29+
│ ┌─────────────────────────────────────────────────────┐ │
30+
│ │ Quart API Server │ │
31+
│ │ • /chat endpoint │ │
32+
│ │ • /ask endpoint │ │
33+
│ │ • RAG Approaches │ │
34+
│ │ • Azure Services │ │
35+
│ └─────────────────────────────────────────────────────┘ │
36+
└─────────────────────────────────────────────────────────────┘
37+
```
38+
39+
## Project Structure
40+
741
```
842
agents/
943
├── main.py # Main entry point
1044
├── agent_app.py # Core agent application
1145
├── config/
1246
│ └── agent_config.py # Configuration management
1347
├── services/
14-
│ ├── rag_service.py # RAG service integration
48+
│ ├── rag_service.py # Backend API client
1549
│ └── auth_service.py # Authentication service
1650
├── handlers/
1751
│ ├── message_handler.py # General message handler
@@ -24,11 +58,12 @@ agents/
2458
## Features
2559

2660
- **Multi-Channel Support**: Works with Teams, Copilot, and web chat
27-
- **RAG Integration**: Leverages existing RAG capabilities
61+
- **Backend Integration**: Calls existing RAG backend API
2862
- **Authentication**: Microsoft 365 authentication and authorization
2963
- **Rich Responses**: Adaptive cards, citations, and interactive elements
3064
- **Conversation State**: Maintains context across conversations
3165
- **Error Handling**: Robust error handling and logging
66+
- **No Duplication**: Reuses existing backend logic and services
3267

3368
## Setup
3469

@@ -50,8 +85,7 @@ cp .env.example .env
5085

5186
- **Bot Framework**: App ID and password from Azure Bot Service
5287
- **Microsoft 365**: Tenant ID, client ID, and client secret
53-
- **Azure OpenAI**: Endpoint, API key, and deployment name
54-
- **Azure AI Search**: Endpoint, key, and index name
88+
- **Backend API**: URL of the existing RAG backend (e.g., http://localhost:50505)
5589

5690
### 4. Run the Agent
5791

@@ -70,12 +104,7 @@ python main.py
70104
| `AZURE_TENANT_ID` | Microsoft 365 tenant ID | Yes |
71105
| `AZURE_CLIENT_ID` | Microsoft 365 client ID | Yes |
72106
| `AZURE_CLIENT_SECRET` | Microsoft 365 client secret | Yes |
73-
| `AZURE_OPENAI_ENDPOINT` | Azure OpenAI endpoint | Yes |
74-
| `AZURE_OPENAI_API_KEY` | Azure OpenAI API key | Yes |
75-
| `AZURE_OPENAI_CHATGPT_DEPLOYMENT` | ChatGPT deployment name | Yes |
76-
| `AZURE_SEARCH_ENDPOINT` | Azure AI Search endpoint | Yes |
77-
| `AZURE_SEARCH_KEY` | Azure AI Search key | Yes |
78-
| `AZURE_SEARCH_INDEX` | Search index name | Yes |
107+
| `BACKEND_URL` | URL of the existing RAG backend | Yes |
79108

80109
### Agent Settings
81110

@@ -116,19 +145,19 @@ python main.py
116145
3. Configure Teams channel
117146
4. Test in Teams
118147

119-
## Integration with Main App
148+
## Integration with Backend
120149

121-
The agent integrates with the existing RAG application by:
150+
The agent integrates with the existing RAG backend by:
122151

123-
1. **Shared Services**: Uses the same Azure OpenAI and Search services
124-
2. **Authentication**: Leverages existing authentication system
125-
3. **RAG Logic**: Integrates with existing RAG approaches
126-
4. **Configuration**: Shares configuration with main application
152+
1. **API Calls**: Calls existing `/chat` and `/chat/stream` endpoints
153+
2. **No Duplication**: Reuses all existing RAG logic and services
154+
3. **Authentication**: Passes through user context to backend
155+
4. **Response Formatting**: Adapts backend responses for Microsoft 365 channels
127156

128157
## Next Steps
129158

130-
1. **Phase 2**: Integrate with existing RAG approaches
131-
2. **Phase 3**: Add Teams-specific features
159+
1. **Phase 2**: Test backend integration and response formatting
160+
2. **Phase 3**: Add Teams-specific features (adaptive cards, file handling)
132161
3. **Phase 4**: Implement Copilot integration
133162
4. **Phase 5**: Add advanced features and monitoring
134163

agents/config/agent_config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class AgentConfig:
2121
client_id: str
2222
client_secret: str
2323

24+
# Backend API Configuration
25+
backend_url: str
26+
2427
# Azure Services (reuse from existing app)
2528
azure_openai_endpoint: str
2629
azure_openai_api_key: str
@@ -53,6 +56,9 @@ def from_environment(cls) -> "AgentConfig":
5356
client_id=os.getenv("AZURE_CLIENT_ID", ""),
5457
client_secret=os.getenv("AZURE_CLIENT_SECRET", ""),
5558

59+
# Backend API
60+
backend_url=os.getenv("BACKEND_URL", "http://localhost:50505"),
61+
5662
# Azure Services
5763
azure_openai_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT", ""),
5864
azure_openai_api_key=os.getenv("AZURE_OPENAI_API_KEY", ""),
@@ -77,8 +83,7 @@ def validate(self) -> None:
7783
"""Validate configuration."""
7884
required_fields = [
7985
"app_id", "app_password", "tenant_id", "client_id", "client_secret",
80-
"azure_openai_endpoint", "azure_openai_api_key", "azure_openai_deployment",
81-
"azure_search_endpoint", "azure_search_key", "azure_search_index"
86+
"backend_url"
8287
]
8388

8489
missing_fields = []

agents/requirements.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ botbuilder-adapter-azure>=4.15.0
99
quart>=0.18.0
1010
quart-cors>=0.7.0
1111

12-
# Azure services (reuse from main app)
13-
azure-identity>=1.17.0
14-
azure-search-documents>=11.7.0
15-
openai>=1.3.7
12+
# HTTP client for calling backend
13+
aiohttp>=3.8.0
1614

1715
# Authentication
1816
msal>=1.24.0

0 commit comments

Comments
 (0)