Python: Issue 2346: (python): Add enterprise chat agent sample with Azure Functions and Cosmos DB#4906
Open
vj-msft wants to merge 14 commits intomicrosoft:mainfrom
Open
Python: Issue 2346: (python): Add enterprise chat agent sample with Azure Functions and Cosmos DB#4906vj-msft wants to merge 14 commits intomicrosoft:mainfrom
vj-msft wants to merge 14 commits intomicrosoft:mainfrom
Conversation
- Added demo HTTP requests for the Enterprise Chat Agent API. - Developed the main function app with HTTP triggers for thread management, message handling, and health checks. - Integrated Cosmos DB for persistent storage of threads and messages. - Created tools for weather information, calculations, and knowledge base searches. - Configured infrastructure using Bicep templates for Azure resources including Function App, Cosmos DB, Application Insights, and Log Analytics. - Added example local settings for development and updated requirements for necessary packages.
…emetry instrumentation - Added observability design documentation outlining principles and framework integration. - Created route blueprints for threads, messages, and health check endpoints. - Implemented health check endpoint to verify Cosmos DB connectivity. - Developed message handling endpoints for sending and retrieving messages in conversation threads. - Established thread management endpoints for creating, retrieving, and deleting threads. - Integrated Cosmos DB storage for threads and messages with lazy initialization. - Added observability module to manage custom spans for HTTP requests, Cosmos DB operations, and validation checks. - Configured OpenTelemetry setup for tracing and metrics collection. - Updated requirements for OpenTelemetry and Azure Monitor dependencies. - Documented environment variables and Azure Functions configuration for observability.
- Added core modules for the Enterprise Chat Agent including services for Cosmos DB storage, observability, and agent functionality. - Implemented CosmosConversationStore for managing conversation thread metadata in Azure Cosmos DB. - Developed agent_service to handle chat agent creation with integrated tools for weather, calculation, and knowledge base search. - Introduced observability features using OpenTelemetry for tracking HTTP requests and Cosmos DB operations. - Created local tools for weather, calculation, and knowledge base search, enabling the agent to autonomously select tools based on user input. - Removed outdated design documentation to streamline project structure.
- Updated DESIGN.md to reflect new architecture and goals for the Enterprise Chat Agent, including enhanced agent autonomy and integration with Microsoft Docs. - Removed MCP_INTEGRATION.md and observability-design.md as their content is now integrated into DESIGN.md. - Added new API endpoint to list conversation threads with optional filters for user ID and status. - Implemented Cosmos DB query logic for listing threads in cosmos_store.py. - Enhanced observability by initializing logging levels for httpx and httpcore to reduce verbosity. - Updated routes/messages.py to utilize AgentSession for better context management during agent runs. - Added debug endpoint to list session IDs for troubleshooting. - Improved logging throughout the message handling process for better traceability.
…nd Cosmos DB formatting fix
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Python end-to-end sample that demonstrates building a backend “enterprise chat API” on Azure Functions with Cosmos DB persistence, Agent Framework tools (local + MCP), and OpenTelemetry-based observability, along with azd/Bicep deployment assets.
Changes:
- Introduces Azure Functions HTTP API routes for thread and message operations plus health checks.
- Adds an Agent Framework configuration using Azure OpenAI + CosmosHistoryProvider and local tools (weather/calculator/KB) plus MCP docs search.
- Adds infra-as-code (Bicep + azd) and supporting docs/demo assets (README, design doc, demo UI/HTTP).
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| python/samples/05-end-to-end/enterprise-chat-agent/function_app.py | Azure Functions entrypoint registering route blueprints and initializing observability |
| python/samples/05-end-to-end/enterprise-chat-agent/host.json | Functions host config (logging + OpenTelemetry mode) |
| python/samples/05-end-to-end/enterprise-chat-agent/azure.yaml | azd service definition for Function App deployment |
| python/samples/05-end-to-end/enterprise-chat-agent/requirements.txt | Sample dependency list (Agent Framework, Cosmos provider, OTEL, Azure SDK) |
| python/samples/05-end-to-end/enterprise-chat-agent/local.settings.json.example | Local configuration template for running the sample |
| python/samples/05-end-to-end/enterprise-chat-agent/prompts/system_prompt.txt | System instructions for the agent/tool usage guidance |
| python/samples/05-end-to-end/enterprise-chat-agent/routes/init.py | Blueprint exports for routes package |
| python/samples/05-end-to-end/enterprise-chat-agent/routes/threads.py | Thread CRUD endpoints + debug sessions endpoint |
| python/samples/05-end-to-end/enterprise-chat-agent/routes/messages.py | Send/retrieve message endpoints integrating agent + Cosmos history |
| python/samples/05-end-to-end/enterprise-chat-agent/routes/health.py | Health endpoint with Cosmos connectivity check |
| python/samples/05-end-to-end/enterprise-chat-agent/services/init.py | Exports service helpers (agent, cosmos store, observability spans) |
| python/samples/05-end-to-end/enterprise-chat-agent/services/agent_service.py | Agent + CosmosHistoryProvider setup, MCP tool factory |
| python/samples/05-end-to-end/enterprise-chat-agent/services/cosmos_store.py | Cosmos thread metadata store implementation |
| python/samples/05-end-to-end/enterprise-chat-agent/services/observability.py | Wrapper spans for HTTP, Cosmos, validation using framework OTEL APIs |
| python/samples/05-end-to-end/enterprise-chat-agent/tools/init.py | Aggregates local tool exports |
| python/samples/05-end-to-end/enterprise-chat-agent/tools/weather.py | Simulated weather tool |
| python/samples/05-end-to-end/enterprise-chat-agent/tools/calculator.py | AST-based “safe” calculator tool |
| python/samples/05-end-to-end/enterprise-chat-agent/tools/knowledge_base.py | Simulated knowledge base search tool |
| python/samples/05-end-to-end/enterprise-chat-agent/infra/main.parameters.json | azd parameter bindings for Bicep |
| python/samples/05-end-to-end/enterprise-chat-agent/infra/main.bicep | Top-level deployment wiring (RG, monitoring, storage, cosmos, function app) |
| python/samples/05-end-to-end/enterprise-chat-agent/infra/abbreviations.json | Resource name abbreviation config used by Bicep |
| python/samples/05-end-to-end/enterprise-chat-agent/infra/core/monitor/monitoring.bicep | Log Analytics + App Insights resources |
| python/samples/05-end-to-end/enterprise-chat-agent/infra/core/storage/storage-account.bicep | Storage account for Function App deployment assets |
| python/samples/05-end-to-end/enterprise-chat-agent/infra/core/database/cosmos-nosql.bicep | Cosmos NoSQL account + database + container provisioning |
| python/samples/05-end-to-end/enterprise-chat-agent/infra/core/host/function-app.bicep | Flex Consumption Function App + identity + role assignment + app settings |
| python/samples/05-end-to-end/enterprise-chat-agent/docs/DESIGN.md | Design/architecture write-up for the sample |
| python/samples/05-end-to-end/enterprise-chat-agent/demo.http | REST client demo script for the API |
| python/samples/05-end-to-end/enterprise-chat-agent/demo-ui.html | Simple browser UI demo for thread/message interactions |
| python/samples/05-end-to-end/enterprise-chat-agent/README.md | Setup, usage, API docs, streaming notes, and project structure |
| python/samples/05-end-to-end/enterprise-chat-agent/.gitignore | Sample-local gitignore for Functions/azd/python artifacts |
python/samples/05-end-to-end/enterprise-chat-agent/local.settings.json.example
Show resolved
Hide resolved
python/samples/05-end-to-end/enterprise-chat-agent/services/cosmos_store.py
Outdated
Show resolved
Hide resolved
python/samples/05-end-to-end/enterprise-chat-agent/infra/core/database/cosmos-nosql.bicep
Outdated
Show resolved
Hide resolved
python/samples/05-end-to-end/enterprise-chat-agent/docs/DESIGN.md
Outdated
Show resolved
Hide resolved
python/samples/05-end-to-end/enterprise-chat-agent/demo-ui.html
Outdated
Show resolved
Hide resolved
python/samples/05-end-to-end/enterprise-chat-agent/services/agent_service.py
Outdated
Show resolved
Hide resolved
python/samples/05-end-to-end/enterprise-chat-agent/infra/core/host/function-app.bicep
Outdated
Show resolved
Hide resolved
python/samples/05-end-to-end/enterprise-chat-agent/infra/core/database/cosmos-nosql.bicep
Outdated
Show resolved
Hide resolved
… into issue-2436
…ty comments in weather tool
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation and Context
The existing ChatKit sample focuses on frontend widget integration. Enterprise teams need a backend API pattern that any client (web, mobile, Teams, CLI) can consume.
This sample provides a production-ready Chat API demonstrating:
azd up)Closes the issue : #2436
Description
New sample:
python/samples/05-end-to-end/enterprise-chat-agent/API Endpoints:
POST/api/threadsGET/api/threadsDELETE/api/threads/{id}POST/api/threads/{id}/messagesGET/api/threads/{id}/messagesKey Components:
function_app.py— Azure Functions entry pointservices/agent_service.py— Agent with CosmosHistoryProviderservices/cosmos_store.py— Thread metadata storageservices/observability.py— OpenTelemetry instrumentationtools/— Weather, calculator, knowledge base toolsinfra/— Bicep infrastructure for azd deploymentDesign Decisions:
threads(metadata) +messages(CosmosHistoryProvider)Contribution Checklist