|
| 1 | +# Microsoft 365 RAG Agent |
| 2 | + |
| 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. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 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 | + |
| 41 | +``` |
| 42 | +agents/ |
| 43 | +├── main.py # Main entry point |
| 44 | +├── agent_app.py # Core agent application |
| 45 | +├── config/ |
| 46 | +│ └── agent_config.py # Configuration management |
| 47 | +├── services/ |
| 48 | +│ ├── rag_service.py # Backend API client |
| 49 | +│ └── auth_service.py # Authentication service |
| 50 | +├── handlers/ |
| 51 | +│ ├── message_handler.py # General message handler |
| 52 | +│ └── teams_handler.py # Teams-specific handler |
| 53 | +├── adapters/ |
| 54 | +│ └── response_adapter.py # Channel-specific response formatting |
| 55 | +└── requirements.txt # Python dependencies |
| 56 | +``` |
| 57 | + |
| 58 | +## Features |
| 59 | + |
| 60 | +- **Multi-Channel Support**: Works with Teams, Copilot, and web chat |
| 61 | +- **Backend Integration**: Calls existing RAG backend API |
| 62 | +- **Authentication**: Microsoft 365 authentication and authorization |
| 63 | +- **Rich Responses**: Adaptive cards, citations, and interactive elements |
| 64 | +- **Conversation State**: Maintains context across conversations |
| 65 | +- **Error Handling**: Robust error handling and logging |
| 66 | +- **No Duplication**: Reuses existing backend logic and services |
| 67 | + |
| 68 | +## Setup |
| 69 | + |
| 70 | +### 1. Install Dependencies |
| 71 | + |
| 72 | +```bash |
| 73 | +cd agents |
| 74 | +pip install -r requirements.txt |
| 75 | +``` |
| 76 | + |
| 77 | +### 2. Configure Environment |
| 78 | + |
| 79 | +```bash |
| 80 | +cp .env.example .env |
| 81 | +# Edit .env with your configuration values |
| 82 | +``` |
| 83 | + |
| 84 | +### 3. Required Configuration |
| 85 | + |
| 86 | +- **Bot Framework**: App ID and password from Azure Bot Service |
| 87 | +- **Microsoft 365**: Tenant ID, client ID, and client secret |
| 88 | +- **Backend API**: URL of the existing RAG backend (e.g., http://localhost:50505) |
| 89 | + |
| 90 | +### 4. Run the Agent |
| 91 | + |
| 92 | +```bash |
| 93 | +python main.py |
| 94 | +``` |
| 95 | + |
| 96 | +## Configuration |
| 97 | + |
| 98 | +### Environment Variables |
| 99 | + |
| 100 | +| Variable | Description | Required | |
| 101 | +|----------|-------------|----------| |
| 102 | +| `MICROSOFT_APP_ID` | Bot Framework app ID | Yes | |
| 103 | +| `MICROSOFT_APP_PASSWORD` | Bot Framework app password | Yes | |
| 104 | +| `AZURE_TENANT_ID` | Microsoft 365 tenant ID | Yes | |
| 105 | +| `AZURE_CLIENT_ID` | Microsoft 365 client ID | Yes | |
| 106 | +| `AZURE_CLIENT_SECRET` | Microsoft 365 client secret | Yes | |
| 107 | +| `BACKEND_URL` | URL of the existing RAG backend | Yes | |
| 108 | + |
| 109 | +### Agent Settings |
| 110 | + |
| 111 | +| Variable | Description | Default | |
| 112 | +|----------|-------------|---------| |
| 113 | +| `AGENT_NAME` | Display name for the agent | "RAG Assistant" | |
| 114 | +| `AGENT_DESCRIPTION` | Agent description | "AI-powered document search and chat assistant" | |
| 115 | +| `MAX_CONVERSATION_TURNS` | Maximum conversation turns | 20 | |
| 116 | +| `ENABLE_TYPING_INDICATOR` | Enable typing indicators | true | |
| 117 | +| `ENABLE_TEAMS` | Enable Teams channel | true | |
| 118 | +| `ENABLE_COPILOT` | Enable Copilot channel | true | |
| 119 | +| `ENABLE_WEB_CHAT` | Enable web chat channel | true | |
| 120 | + |
| 121 | +## API Endpoints |
| 122 | + |
| 123 | +### Health Check |
| 124 | +- **GET** `/` - Basic health check |
| 125 | +- **GET** `/api/health` - Detailed health check |
| 126 | + |
| 127 | +### Bot Framework |
| 128 | +- **POST** `/api/messages` - Main Bot Framework endpoint |
| 129 | + |
| 130 | +### Configuration |
| 131 | +- **GET** `/api/config` - Get agent configuration (non-sensitive) |
| 132 | + |
| 133 | +## Development |
| 134 | + |
| 135 | +### Running Locally |
| 136 | + |
| 137 | +1. Set up your environment variables |
| 138 | +2. Run the agent: `python main.py` |
| 139 | +3. Use Bot Framework Emulator to test locally |
| 140 | + |
| 141 | +### Testing with Teams |
| 142 | + |
| 143 | +1. Deploy to Azure |
| 144 | +2. Register with Azure Bot Service |
| 145 | +3. Configure Teams channel |
| 146 | +4. Test in Teams |
| 147 | + |
| 148 | +## Integration with Backend |
| 149 | + |
| 150 | +The agent integrates with the existing RAG backend by: |
| 151 | + |
| 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 |
| 156 | + |
| 157 | +## Next Steps |
| 158 | + |
| 159 | +1. **Phase 2**: Test backend integration and response formatting |
| 160 | +2. **Phase 3**: Add Teams-specific features (adaptive cards, file handling) |
| 161 | +3. **Phase 4**: Implement Copilot integration |
| 162 | +4. **Phase 5**: Add advanced features and monitoring |
| 163 | + |
| 164 | +## Troubleshooting |
| 165 | + |
| 166 | +### Common Issues |
| 167 | + |
| 168 | +1. **Authentication Errors**: Check Microsoft 365 app registration |
| 169 | +2. **Bot Framework Errors**: Verify app ID and password |
| 170 | +3. **Azure Service Errors**: Check service endpoints and keys |
| 171 | +4. **Channel Errors**: Verify channel configuration |
| 172 | + |
| 173 | +### Logs |
| 174 | + |
| 175 | +The agent logs to stdout with structured logging. Check logs for: |
| 176 | +- Authentication issues |
| 177 | +- Service connection problems |
| 178 | +- Message processing errors |
| 179 | +- Channel-specific issues |
| 180 | + |
| 181 | +## Support |
| 182 | + |
| 183 | +For issues and questions: |
| 184 | +1. Check the logs for error details |
| 185 | +2. Verify configuration values |
| 186 | +3. Test with Bot Framework Emulator |
| 187 | +4. Check Azure service status |
0 commit comments