Created
December 2, 2025 19:50
-
-
Save pamelafox/281b257064c125b2707f3e2306eedfdc to your computer and use it in GitHub Desktop.
Evaluation of an agent
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
| import asyncio | |
| import json | |
| import os | |
| from azure.ai.evaluation import AzureOpenAIModelConfiguration, IntentResolutionEvaluator | |
| from azure.identity import DefaultAzureCredential, get_bearer_token_provider | |
| from dotenv import load_dotenv | |
| from agentframework_learn import run_agent | |
| # Load environment variables from a .env file | |
| load_dotenv(override=True) | |
| async def main() -> None: | |
| """Run the evaluation on a dynamically generated agent response.""" | |
| credential = DefaultAzureCredential() | |
| get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default") | |
| model_config: AzureOpenAIModelConfiguration = { | |
| "azure_endpoint": os.environ["AZURE_OPENAI_ENDPOINT"], | |
| "azure_deployment": os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"], | |
| } | |
| intent_resolution_evaluator = IntentResolutionEvaluator(model_config) | |
| # Query to send to the agent | |
| query = "How to create an Azure storage account using az cli?" | |
| # Get response dynamically from the agent | |
| print(f"Sending query to agent: {query}") | |
| response = await run_agent(query) | |
| print(f"Agent response: {response[:200]}..." if len(response) > 200 else f"Agent response: {response}") | |
| # Evaluate the query and response | |
| result = intent_resolution_evaluator( | |
| query=query, | |
| response=response, | |
| ) | |
| print(json.dumps(result, indent=4)) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment