-
Notifications
You must be signed in to change notification settings - Fork 203
auquan risk-agent 1st commit #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lindazqli
merged 14 commits into
azure-ai-foundry:main
from
anuragBhardwaj01-auquan:ab-feature-auquan-agent
May 15, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e71a793
auquan risk-agent 1st commit
anuragBhardwaj01-auquan c541ebd
changes acc to comments
anuragBhardwaj01-auquan 67735a0
change base url
anuragBhardwaj01-auquan 5d37936
move files acc to new directory structure
anuragBhardwaj01-auquan e4b0a8d
fix readme error
anuragBhardwaj01-auquan f22a5ac
remove .DS_store files
anuragBhardwaj01-auquan d9f320f
new changes
anuragBhardwaj01-auquan 5c2ccaa
add agent sample
anuragBhardwaj01-auquan 8742719
fix documentation in 3ptools
anuragBhardwaj01-auquan ddc024a
remove agent sample code
anuragBhardwaj01-auquan 3dee989
make changes acc to review
anuragBhardwaj01-auquan b39f606
fix readme for tool
anuragBhardwaj01-auquan f0323d0
add sample queries
anuragBhardwaj01-auquan 8abd956
review changes fix
anuragBhardwaj01-auquan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
samples/microsoft/python/getting-started-agents/3p-tools/auquan/README.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ## Auquan | ||
|
|
||
| **Tool Description:** | ||
| Utilize Auquan agents to perform your financial data crunching. The Auquan Risk Agent is an expert system designed to provide comprehensive risk analysis and timeline tracking for companies. It specializes in analyzing company risks across multiple dimensions including operational, financial, regulatory, and sustainability metrics. The tool processes structured risk data from Auquan's API, generates detailed timelines, and provides actionable insights through well-formatted json responses. | ||
|
|
||
| **Prerequisites** | ||
| Obtain an API key for your Auquan Risk Agent by contacting us. | ||
| You can contact us via this page : https://www.auquan.com/cta | ||
|
|
||
|
|
||
| **Setup** | ||
| 1. Go to Azure AI Foundry portal and select your AI Project. Select Management Center. | ||
| 2. Select +new connection in the settings page. | ||
| 3. Select custom keys in other resource types. | ||
| 4. Enter the following information to create a connection to store your AuquanRiskAnalyzer key: | ||
| 5. Set Custom keys to "x-api-key", with the value being your AuquanRiskAnalyzer API key. | ||
| 6. Make sure is secret is checked. | ||
| 7. Set the connection name to your connection name. You use this connection name in your sample code or Foundry Portal later. | ||
| 8. For the Access setting, you can choose either this project only or shared to all projects. Just make sure in your code, the connection string of the project you entered has access to this connection. | ||
|
|
||
| **Sample Queries** | ||
|
|
||
| - "Do a risk analysis for Darktrace" | ||
| - "What are the critical risks identified for Openai" | ||
| - "Generate a sustainability analysis for ClimatePartner" | ||
| - "What is the overall risk range of Zoom?" | ||
| - "What are the recent themes around Coursera and what are their impacts?" | ||
| - "What are the recent risks for Autodesk ?" | ||
|
|
||
| **Note** | ||
| If you encounter a "rate limit exceeded" error, navigate to the "Models + Endpoints" tab in the Foundry Portal and increase the TPM (tokens per minute) limit for your model. We recommend setting it to around 100,000 to start with. | ||
|
|
||
|
|
||
| **Customer Support Contact** | ||
| [email protected] |
153 changes: 153 additions & 0 deletions
153
samples/microsoft/python/getting-started-agents/3p-tools/auquan/auquan.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| { | ||
| "openapi": "3.0.0", | ||
| "info": { | ||
| "title": "Auquan Risk Analyzer API", | ||
| "version": "1.0.0", | ||
| "description": "API for company risk analysis and query processing" | ||
| }, | ||
| "servers": [ | ||
| { | ||
| "url": "https://agents.auquan.com", | ||
| "description": "Auquan Server" | ||
| } | ||
| ], | ||
| "components": { | ||
| "securitySchemes": { | ||
| "apiKeyHeader": { | ||
| "type": "apiKey", | ||
| "name": "x-api-key", | ||
| "in": "header", | ||
| "description": "API key for authentication" | ||
| } | ||
| } | ||
| }, | ||
| "security": [ | ||
| { | ||
| "apiKeyHeader": [] | ||
| } | ||
| ], | ||
| "paths": { | ||
| "/api/analyze-query": { | ||
| "post": { | ||
| "operationId": "analyze_query", | ||
| "tags": ["Azure Agent"], | ||
| "summary": "Analyze a user's natural language query and return risk analysis", | ||
| "description": "This endpoint requires a valid API key in the x-api-key header. The API key must be included in all requests.", | ||
| "security": [ | ||
| { | ||
| "apiKeyHeader": [] | ||
| } | ||
| ], | ||
| "requestBody": { | ||
| "required": true, | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "query": { | ||
| "type": "string", | ||
| "description": "The natural language query about company risks", | ||
| "example": "do a risk analysis for ClimatePartner" | ||
| } | ||
| }, | ||
| "required": ["query"] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "responses": { | ||
| "200": { | ||
| "description": "Successful response", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "status": { | ||
| "type": "string", | ||
| "enum": ["success"] | ||
| }, | ||
| "data": { | ||
| "type": "object", | ||
| "properties": { | ||
| "company_name": { | ||
| "type": "string" | ||
| }, | ||
| "basic_info": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| }, | ||
| "description": { | ||
| "type": "string" | ||
| }, | ||
| "summary": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| }, | ||
| "risk_analysis": { | ||
| "type": "object", | ||
| "properties": { | ||
| "auquan_risks": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object" | ||
| } | ||
| }, | ||
| "sasb_risks": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object" | ||
| } | ||
| }, | ||
| "ungc_risks": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object" | ||
| } | ||
| }, | ||
| "sdg_risks": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object" | ||
| } | ||
| }, | ||
| "recent_themes": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "401": { | ||
| "description": "Unauthorized - Invalid or missing API key", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "detail": { | ||
| "type": "string", | ||
| "example": "Invalid API key" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
135 changes: 135 additions & 0 deletions
135
samples/microsoft/python/getting-started-agents/3p-tools/auquan/auquan_risk_sdk.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # pylint: disable=line-too-long,useless-suppression | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| """ | ||
| DESCRIPTION: | ||
| This sample demonstrates how to use agent operations with the | ||
| OpenAPI tool from the Azure Agents service using a synchronous client. | ||
| To learn more about OpenAPI specs, visit https://learn.microsoft.com/openapi | ||
|
|
||
| USAGE: | ||
| python openapi.py | ||
|
|
||
| Before running the sample: | ||
|
|
||
| pip install azure-ai-agents azure-identity jsonref | ||
|
|
||
| Set these environment variables with your own values: | ||
| 1) PROJECT_ENDPOINT - the Azure AI Agents endpoint. | ||
| 2) MODEL - The deployment name of the AI model, as found under the "Name" column in | ||
| the "Models + endpoints" tab in your Azure AI Foundry project. | ||
| """ | ||
| # <initialization> | ||
| # Import necessary libraries | ||
| import os | ||
| import jsonref | ||
| from azure.ai.projects import AIProjectClient | ||
| from azure.identity import DefaultAzureCredential | ||
| from azure.ai.agents.models import OpenApiTool, OpenApiConnectionAuthDetails, OpenApiConnectionSecurityScheme | ||
|
|
||
| # endpoint should be in the format "https://<your-ai-services-resource-name>.services.ai.azure.com/api/projects/<your-project-name>" | ||
| endpoint = os.environ["PROJECT_ENDPOINT"] | ||
| model = os.environ["MODEL"] | ||
| # connection id should be in the format "/subscriptions/<sub-id>/resourceGroups/<your-rg-name>/providers/Microsoft.CognitiveServices/accounts/<your-ai-services-name>/projects/<your-project-name>/connections/<your-connection-name>" | ||
| conn_id = os.environ["CONNECTION_ID"] | ||
|
|
||
| # Initialize the project client using the endpoint and default credentials | ||
| with AIProjectClient( | ||
| endpoint=endpoint, | ||
| credential=DefaultAzureCredential(exclude_interactive_browser_credential=False), | ||
| ) as project_client: | ||
| # </initialization> | ||
|
|
||
| # Load the OpenAPI specification for the service from a local JSON file using jsonref to handle references | ||
| with open("./auquan.json", "r") as f: | ||
| openapi_spec = jsonref.loads(f.read()) | ||
|
|
||
| # Create Auth object for the OpenApiTool (note that connection or managed identity auth setup requires additional setup in Azure) | ||
| auth = OpenApiConnectionAuthDetails(security_scheme=OpenApiConnectionSecurityScheme(connection_id=conn_id)) | ||
|
|
||
| # Initialize the main OpenAPI tool definition for Auquan Risk Analyzer | ||
| openapi_tool = OpenApiTool( | ||
| name="auquan risk analyser tool", | ||
| spec=openapi_spec, | ||
| description="retrieve risk analysis for a given company", | ||
| auth=auth | ||
| ) | ||
|
|
||
| # <agent_creation> | ||
| # --- Agent Creation --- | ||
| # Create an agent configured with the combined OpenAPI tool definitions | ||
| agent = project_client.agents.create_agent( | ||
| model=model, # Specify the model deployment | ||
| name="auquan-risk-analyser-agent", # Give the agent a name | ||
| instructions="You are a helpful research agent that conducts risk analysis on companies using data from Auquan.", # Define agent's role | ||
| tools=openapi_tool.definitions, # Provide the list of tool definitions | ||
| ) | ||
| print(f"Created agent, ID: {agent.id}") | ||
| # </agent_creation> | ||
|
|
||
| # <thread_management> | ||
| # --- Thread Management --- | ||
| # Create a new conversation thread for the interaction | ||
| thread = project_client.agents.threads.create() | ||
| print(f"Created thread, ID: {thread.id}") | ||
|
|
||
| # Create the initial user message in the thread | ||
| message = project_client.agents.messages.create( | ||
| thread_id=thread.id, | ||
| role="user", | ||
| # give an example of a user message that the agent can respond to | ||
| content="Send me the risk analysis on Darktrace", | ||
| ) | ||
| print(f"Created message, ID: {message.id}") | ||
| # </thread_management> | ||
|
|
||
| # <message_processing> | ||
| # --- Message Processing (Run Creation and Auto-processing) --- | ||
| # Create and automatically process the run, handling tool calls internally | ||
| # Note: This differs from the function_tool example where tool calls are handled manually | ||
| run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id) | ||
| print(f"Run finished with status: {run.status}") | ||
| # </message_processing> | ||
|
|
||
| # <tool_execution_loop> # Note: This section now processes completed steps, as create_and_process_run handles execution | ||
| # --- Post-Run Step Analysis --- | ||
| if run.status == "failed": | ||
| print(f"Run failed: {run.last_error}") | ||
|
|
||
| # Retrieve the steps taken during the run for analysis | ||
| run_steps = project_client.agents.run_steps.list(thread_id=thread.id, run_id=run.id) | ||
|
|
||
| # Loop through each step to display information | ||
| for step in run_steps: | ||
| print(f"Step {step['id']} status: {step['status']}") | ||
|
|
||
| # Check if there are tool calls recorded in the step details | ||
| step_details = step.get("step_details", {}) | ||
| tool_calls = step_details.get("tool_calls", []) | ||
|
|
||
| if tool_calls: | ||
| print(" Tool calls:") | ||
| for call in tool_calls: | ||
| print(f" Tool Call ID: {call.get('id')}") | ||
| print(f" Type: {call.get('type')}") | ||
|
|
||
| function_details = call.get("function", {}) | ||
| if function_details: | ||
| print(f" Function name: {function_details.get('name')}") | ||
| print() # Add an extra newline between steps for readability | ||
| # </tool_execution_loop> | ||
|
|
||
| # <cleanup> | ||
| # --- Cleanup --- | ||
| # Delete the agent resource to clean up | ||
| project_client.agents.delete_agent(agent.id) | ||
| print("Deleted agent") | ||
|
|
||
| # Fetch and log all messages exchanged during the conversation thread | ||
| messages = project_client.agents.messages.list(thread_id=thread.id) | ||
| for message in messages: | ||
| print(f"Message ID: {message.id}, Role: {message.role}, Content: {message.content}") | ||
| # </cleanup> | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.