Skip to main content
In this article, we explore the inner workings of the application and demonstrate how containerized services, API endpoints, agent prompting, and evaluation metrics combine to create a production-like deployment. Learn how to test endpoints, configure dynamic agents, and integrate AI search with Cosmos DB.

Application Overview and Testing

Begin by identifying the running container’s URL within your resource group. Clicking the URL triggers the GET method defined in the Python source code, immediately returning a simple JSON message:
You can also use Postman or similar API testing tools to send POST requests to test the endpoints. For instance, a sample POST request might look like this:
The image shows a Postman interface with a POST request being sent. It includes query parameters like "question," "customer_id," and "chat_history," and the request is in progress with "Sending request..." displayed.
Both the GET and POST endpoints are operational. A quick examination of the main application file (commonly named main.py) reveals the endpoints for processing incoming queries.

GET and POST Endpoints

The GET endpoint is set up as follows:
The POST endpoint, designed to create responses based on incoming queries, is implemented as:
Within the POST handler, a helper function named get_response processes the query. An excerpt from this function is provided below:
The function utilizes a Cosmos DB client to retrieve customer details through a helper function, as shown below:
After processing the request and invoking Promptly’s runtime (via the chat.prompty file), the application returns the response to the client.

Agent Configuration and Dynamic Prompting

The application supports dynamic agent behavior through YAML-based configuration files. For example, you can configure an agent to respond exclusively in Spanish. Below is a sample agent configuration:
After modifying the agent configuration, you can post provision the changes. This process updates the container registry and redeploys the new version of the application. For example, the YAML configuration sent during post provision looks like this:
When you click “post provision,” it may take a few minutes to update the application. During this period, outputs confirm that the hooks have executed successfully:
Once complete, sending requests (for example via Postman) triggers the chatbot to answer queries. Here’s an example JSON response when inquiring about products:
The sample response is in Spanish due to the agent configuration. To respond in English, simply update the system prompt accordingly.

Integrating AI Search and Cosmos DB

A core component of this application is its integration with AI search. The Azure-deployed search service offers features such as vector search, semantic ranking, and hybrid search capabilities, enabling efficient querying of product documents. For example, the Azure portal displays the AI Search service, offering options to connect, explore, and monitor data:
The image shows a Microsoft Azure portal interface for managing an AI Search service, displaying options for connecting, exploring, and monitoring data.
Similarly, Cosmos DB resources and document collections—such as customer data and product catalogs—are visible in the Azure portal:
The image shows a Microsoft Azure portal interface displaying a resource group named "rg-genaiops" with a list of resources, including an Azure Cosmos DB account and a container registry, located in France Central.
and
The image shows the Azure Cosmos DB Data Explorer interface, featuring options for launching a quick start, creating a new container, and connecting to the database.
These resources ensure that customer details, orders, and product information are securely stored and readily accessible.

Managing Customer Data

Customer information can be easily added or updated by modifying source JSON files. For example, to add or update a customer record, you might use the following JSON:
After updating the file, running the postprovision hooks will update the application and persist these modifications in Cosmos DB. A sample console output confirming the hook execution is shown below:
When you query the application—such as asking, “what is product id 14”—the chatbot leverages both customer and product context to generate a relevant response:
The chatbot also cross-references previous orders to provide personalized suggestions.

Evaluation Metrics and Postprovision Hooks

Evaluating the quality of model responses is critical for production deployments. Since traditional metrics like accuracy or F1 score may not apply to LLM outputs, alternative approaches such as arena scoring, MMLU benchmarks, ROUGE, and BLEU metrics are employed. Often, another LLM (e.g., GPT-4) is used to assess relevance, groundedness, coherence, and fluency. Below is a sample YAML configuration for evaluation:
The evaluation system assigns metric ratings—for example, rating relevance on a five-star scale based on how well the answer addresses the core aspects of the question. Example task inputs and outputs illustrate this process:
The evaluation code in Python may include a main function that loads test data, generates responses, evaluates outputs, and summarizes the results:
Console logs confirm that the hooks have run successfully:

Final Thoughts

This article has shown how to build a production-ready application that integrates containerized services, dynamic agent prompting, and advanced evaluation mechanisms. By leveraging Cosmos DB, Azure AI Search, and a flexible LLM-powered agent configuration, the system delivers relevant and personalized responses. Experiment with the provided code snippets and configurations to adjust agent behavior, update prompt definitions, or extend evaluation methods. Thank you for reading and happy coding!

Watch Video