|
| 1 | +# Microsoft 365 RAG Agent |
| 2 | + |
| 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. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +``` |
| 8 | +agents/ |
| 9 | +├── main.py # Main entry point |
| 10 | +├── agent_app.py # Core agent application |
| 11 | +├── config/ |
| 12 | +│ └── agent_config.py # Configuration management |
| 13 | +├── services/ |
| 14 | +│ ├── rag_service.py # RAG service integration |
| 15 | +│ └── auth_service.py # Authentication service |
| 16 | +├── handlers/ |
| 17 | +│ ├── message_handler.py # General message handler |
| 18 | +│ └── teams_handler.py # Teams-specific handler |
| 19 | +├── adapters/ |
| 20 | +│ └── response_adapter.py # Channel-specific response formatting |
| 21 | +└── requirements.txt # Python dependencies |
| 22 | +``` |
| 23 | + |
| 24 | +## Features |
| 25 | + |
| 26 | +- **Multi-Channel Support**: Works with Teams, Copilot, and web chat |
| 27 | +- **RAG Integration**: Leverages existing RAG capabilities |
| 28 | +- **Authentication**: Microsoft 365 authentication and authorization |
| 29 | +- **Rich Responses**: Adaptive cards, citations, and interactive elements |
| 30 | +- **Conversation State**: Maintains context across conversations |
| 31 | +- **Error Handling**: Robust error handling and logging |
| 32 | + |
| 33 | +## Setup |
| 34 | + |
| 35 | +### 1. Install Dependencies |
| 36 | + |
| 37 | +```bash |
| 38 | +cd agents |
| 39 | +pip install -r requirements.txt |
| 40 | +``` |
| 41 | + |
| 42 | +### 2. Configure Environment |
| 43 | + |
| 44 | +```bash |
| 45 | +cp .env.example .env |
| 46 | +# Edit .env with your configuration values |
| 47 | +``` |
| 48 | + |
| 49 | +### 3. Required Configuration |
| 50 | + |
| 51 | +- **Bot Framework**: App ID and password from Azure Bot Service |
| 52 | +- **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 |
| 55 | + |
| 56 | +### 4. Run the Agent |
| 57 | + |
| 58 | +```bash |
| 59 | +python main.py |
| 60 | +``` |
| 61 | + |
| 62 | +## Configuration |
| 63 | + |
| 64 | +### Environment Variables |
| 65 | + |
| 66 | +| Variable | Description | Required | |
| 67 | +|----------|-------------|----------| |
| 68 | +| `MICROSOFT_APP_ID` | Bot Framework app ID | Yes | |
| 69 | +| `MICROSOFT_APP_PASSWORD` | Bot Framework app password | Yes | |
| 70 | +| `AZURE_TENANT_ID` | Microsoft 365 tenant ID | Yes | |
| 71 | +| `AZURE_CLIENT_ID` | Microsoft 365 client ID | Yes | |
| 72 | +| `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 | |
| 79 | + |
| 80 | +### Agent Settings |
| 81 | + |
| 82 | +| Variable | Description | Default | |
| 83 | +|----------|-------------|---------| |
| 84 | +| `AGENT_NAME` | Display name for the agent | "RAG Assistant" | |
| 85 | +| `AGENT_DESCRIPTION` | Agent description | "AI-powered document search and chat assistant" | |
| 86 | +| `MAX_CONVERSATION_TURNS` | Maximum conversation turns | 20 | |
| 87 | +| `ENABLE_TYPING_INDICATOR` | Enable typing indicators | true | |
| 88 | +| `ENABLE_TEAMS` | Enable Teams channel | true | |
| 89 | +| `ENABLE_COPILOT` | Enable Copilot channel | true | |
| 90 | +| `ENABLE_WEB_CHAT` | Enable web chat channel | true | |
| 91 | + |
| 92 | +## API Endpoints |
| 93 | + |
| 94 | +### Health Check |
| 95 | +- **GET** `/` - Basic health check |
| 96 | +- **GET** `/api/health` - Detailed health check |
| 97 | + |
| 98 | +### Bot Framework |
| 99 | +- **POST** `/api/messages` - Main Bot Framework endpoint |
| 100 | + |
| 101 | +### Configuration |
| 102 | +- **GET** `/api/config` - Get agent configuration (non-sensitive) |
| 103 | + |
| 104 | +## Development |
| 105 | + |
| 106 | +### Running Locally |
| 107 | + |
| 108 | +1. Set up your environment variables |
| 109 | +2. Run the agent: `python main.py` |
| 110 | +3. Use Bot Framework Emulator to test locally |
| 111 | + |
| 112 | +### Testing with Teams |
| 113 | + |
| 114 | +1. Deploy to Azure |
| 115 | +2. Register with Azure Bot Service |
| 116 | +3. Configure Teams channel |
| 117 | +4. Test in Teams |
| 118 | + |
| 119 | +## Integration with Main App |
| 120 | + |
| 121 | +The agent integrates with the existing RAG application by: |
| 122 | + |
| 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 |
| 127 | + |
| 128 | +## Next Steps |
| 129 | + |
| 130 | +1. **Phase 2**: Integrate with existing RAG approaches |
| 131 | +2. **Phase 3**: Add Teams-specific features |
| 132 | +3. **Phase 4**: Implement Copilot integration |
| 133 | +4. **Phase 5**: Add advanced features and monitoring |
| 134 | + |
| 135 | +## Troubleshooting |
| 136 | + |
| 137 | +### Common Issues |
| 138 | + |
| 139 | +1. **Authentication Errors**: Check Microsoft 365 app registration |
| 140 | +2. **Bot Framework Errors**: Verify app ID and password |
| 141 | +3. **Azure Service Errors**: Check service endpoints and keys |
| 142 | +4. **Channel Errors**: Verify channel configuration |
| 143 | + |
| 144 | +### Logs |
| 145 | + |
| 146 | +The agent logs to stdout with structured logging. Check logs for: |
| 147 | +- Authentication issues |
| 148 | +- Service connection problems |
| 149 | +- Message processing errors |
| 150 | +- Channel-specific issues |
| 151 | + |
| 152 | +## Support |
| 153 | + |
| 154 | +For issues and questions: |
| 155 | +1. Check the logs for error details |
| 156 | +2. Verify configuration values |
| 157 | +3. Test with Bot Framework Emulator |
| 158 | +4. Check Azure service status |
0 commit comments