Skip to content

Commit 356ef60

Browse files
authored
Merge pull request #4726 from aahill/release-build-agents-2
Release build agents 2
2 parents 7b480f0 + 1c72e31 commit 356ef60

11 files changed

+76
-112
lines changed

articles/ai-services/agents/concepts/tracing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ Tracing solves this by allowing you to clearly see the inputs and outputs of eac
2626
The Agents playground in the Azure AI Foundry portal lets you trace threads and runs that your agents produce. To open a trace, select **Thread info** in an active thread. You can also optionally select **Metrics** to enable automatic evaluations of the model's performance across several dimensions of **AI quality** and **Risk and safety**.
2727

2828
> [!NOTE]
29-
> * Evaluations are available for 24 hours after they're generated.
29+
> Evaluation results are available for 24 hours before expiring. To get evaluation results, select your desired metrics and chat with your agent.
3030
> * Evaluations are not available in the following regions.
31-
> * australiaeast
32-
> * japaneast
33-
> * southindia
34-
> * uksouth
31+
> * `australiaeast`
32+
> * `japaneast`
33+
> * `southindia`
34+
> * `uksouth`
3535
3636
:::image type="content" source="../media/ai-foundry-tracing.png" alt-text="A screenshot of the agent playground in the Azure AI Foundry portal." lightbox="../media/ai-foundry-tracing.png":::
3737

articles/ai-services/agents/how-to/virtual-networks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Use the following code to create and run an agent. To run this code, you need to
186186

187187
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
188188

189-
[!INCLUDE [connection-string-portal](../includes/connection-string-portal.md)]
189+
[!INCLUDE [connection-string-portal](../includes/endpoint-string-portal.md)]
190190

191191
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
192192

articles/ai-services/agents/includes/connection-string-portal.md

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
manager: nitinme
3+
author: aahill
4+
ms.author: aahi
5+
ms.service: azure-ai-agent-service
6+
ms.topic: include
7+
ms.date: 12/11/2024
8+
---
9+
10+
> [!TIP]
11+
> You can also find your connection string in the **overview** for your project in the [Azure AI Foundry portal](https://ai.azure.com/), under **Libraries** > **Azure AI Foundry**.
12+
> :::image type="content" source="../media/quickstart/portal-endpoint-string.png" alt-text="A screenshot showing the connection string in the Azure AI Foundry portal." lightbox="../media/quickstart/portal-endpoint-string.png":::

articles/ai-services/agents/includes/quickstart-csharp.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,17 @@ Next, to authenticate your API requests and run the program, use the [az login](
5757
az login
5858
```
5959

60-
Use the following code to create and run an agent. To run this code, you will need to create a connection string using information from your project. This string is in the format:
60+
Use the following code to create and run an agent. To run this code, you will need to get the endpoint for your project. This string is in the format:
6161

62-
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
62+
`https://<AIFoundryResourceName>.services.ai.azure.com/api/projects/<ProjectName>`
6363

64-
[!INCLUDE [connection-string-portal](connection-string-portal.md)]
65-
66-
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
67-
68-
```azurecli
69-
az ml workspace show -n {project_name} --resource-group {resource_group_name} --query discovery_url
70-
```
64+
[!INCLUDE [endpoint-string-portal](endpoint-string-portal.md)]
7165

7266
For example, your connection string may look something like:
7367

74-
`eastus.api.azureml.ms;12345678-abcd-1234-9fc6-62780b3d3e05;my-resource-group;my-project-name`
68+
`https://myresource.services.ai.azure.com/api/projects/myproject`
7569

76-
Set this connection string as an environment variable named `PROJECT_CONNECTION_STRING`.
70+
Set this connection string as an environment variable named `PROJECT_ENDPOINT`.
7771

7872

7973
```csharp
@@ -90,7 +84,7 @@ public class Sample_Agent
9084
{
9185
static async Task Main()
9286
{
93-
var connectionString = Environment.GetEnvironmentVariable("PROJECT_CONNECTION_STRING");
87+
var connectionString = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
9488

9589
AgentsClient client = new AgentsClient(connectionString, new DefaultAzureCredential());
9690

articles/ai-services/agents/includes/quickstart-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Use the following code to create and run an agent. To run this code, you will ne
6767

6868
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
6969

70-
[!INCLUDE [connection-string-portal](connection-string-portal.md)]
70+
[!INCLUDE [connection-string-portal](endpoint-string-portal.md)]
7171

7272
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
7373

articles/ai-services/agents/includes/quickstart-python-openai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Use the following code to create and run an agent. To run this code, you will ne
5353

5454
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
5555

56-
[!INCLUDE [connection-string-portal](connection-string-portal.md)]
56+
[!INCLUDE [connection-string-portal](endpoint-string-portal.md)]
5757

5858
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
5959

articles/ai-services/agents/includes/quickstart-python.md

Lines changed: 49 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -48,104 +48,74 @@ Next, to authenticate your API requests and run the program, use the [az login](
4848
az login
4949
```
5050

51-
Use the following code to create and run an agent. To run this code, you will need to create a connection string using information from your project. This string is in the format:
51+
Use the following code to create and run an agent. To run this code, you will need to get the endpoint for your project. This string is in the format:
5252

53-
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
53+
`https://<AIFoundryResourceName>.services.ai.azure.com/api/projects/<ProjectName>`
5454

55-
[!INCLUDE [connection-string-portal](connection-string-portal.md)]
56-
57-
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
58-
59-
```azurecli
60-
az ml workspace show -n {project_name} --resource-group {resource_group_name} --query discovery_url
61-
```
55+
[!INCLUDE [endpoint-string-portal](endpoint-string-portal.md)]
6256

6357
For example, your connection string may look something like:
6458

65-
`eastus.api.azureml.ms;12345678-abcd-1234-9fc6-62780b3d3e05;my-resource-group;my-project-name`
59+
`https://myresource.services.ai.azure.com/api/projects/myproject`
60+
61+
Set this connection string as an environment variable named `PROJECT_ENDPOINT`.
6662

67-
Set this connection string as an environment variable named `PROJECT_CONNECTION_STRING`.
6863

6964
```python
7065
import os
71-
from azure.ai.projects import AIProjectClient
72-
from azure.ai.projects.models import CodeInterpreterTool
66+
import os, time
7367
from azure.identity import DefaultAzureCredential
74-
from typing import Any
68+
from azure.ai.projects import AIProjectClient
7569
from pathlib import Path
7670

77-
# Create an Azure AI Client from a connection string, copied from your Azure AI Foundry project.
78-
# At the moment, it should be in the format "<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>"
79-
# HostName can be found by navigating to your discovery_url and removing the leading "https://" and trailing "/discovery"
80-
# To find your discovery_url, run the CLI command: az ml workspace show -n {project_name} --resource-group {resource_group_name} --query discovery_url
81-
# Project Connection example: eastus.api.azureml.ms;12345678-abcd-1234-9fc6-62780b3d3e05;my-resource-group;my-project-name
82-
# Customer needs to login to Azure subscription via Azure CLI and set the environment variables
71+
# Retrieve the project endpoint from environment variables
72+
project_endpoint = os.environ["PROJECT_ENDPOINT"]
8373

84-
project_client = AIProjectClient.from_connection_string(
85-
credential=DefaultAzureCredential(), conn_str=os.environ["PROJECT_CONNECTION_STRING"]
74+
# Initialize the AIProjectClient
75+
project_client = AIProjectClient(
76+
endpoint=project_endpoint,
77+
credential=DefaultAzureCredential(),
78+
api_version="latest",
8679
)
8780

88-
with project_client:
89-
# Create an instance of the CodeInterpreterTool
90-
code_interpreter = CodeInterpreterTool()
81+
# Initialize the FunctionTool with user-defined functions
82+
functions = FunctionTool(functions=user_functions)
9183

92-
# The CodeInterpreterTool needs to be included in creation of the agent
84+
with project_client:
85+
# Create an agent with custom functions
9386
agent = project_client.agents.create_agent(
94-
model="gpt-4o-mini",
87+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
9588
name="my-agent",
96-
instructions="You are helpful agent",
97-
tools=code_interpreter.definitions,
98-
tool_resources=code_interpreter.resources,
89+
instructions="You are a helpful agent"
9990
)
100-
print(f"Created agent, agent ID: {agent.id}")
91+
print(f"Created agent, ID: {agent.id}")
10192

102-
# Create a thread
103-
thread = project_client.agents.create_thread()
104-
print(f"Created thread, thread ID: {thread.id}")
93+
# Create a thread for communication
94+
thread = project_client.agents.threads.create()
95+
print(f"Created thread, ID: {thread.id}")
10596

106-
# Create a message
107-
message = project_client.agents.create_message(
108-
thread_id=thread.id,
109-
role="user",
110-
content="Could you please create a bar chart for the operating profit using the following data and provide the file to me? Company A: $1.2 million, Company B: $2.5 million, Company C: $3.0 million, Company D: $1.8 million",
111-
)
112-
print(f"Created message, message ID: {message.id}")
113-
114-
# Run the agent
115-
run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id)
116-
print(f"Run finished with status: {run.status}")
117-
118-
if run.status == "failed":
119-
# Check if you got "Rate limit is exceeded.", then you want to get more quota
120-
print(f"Run failed: {run.last_error}")
121-
122-
# Get messages from the thread
123-
messages = project_client.agents.list_messages(thread_id=thread.id)
124-
print(f"Messages: {messages}")
125-
126-
# Get the last message from the sender
127-
last_msg = messages.get_last_text_message_by_role("assistant")
128-
if last_msg:
129-
print(f"Last Message: {last_msg.text.value}")
130-
131-
# Generate an image file for the bar chart
132-
for image_content in messages.image_contents:
133-
print(f"Image File ID: {image_content.image_file.file_id}")
134-
file_name = f"{image_content.image_file.file_id}_image_file.png"
135-
project_client.agents.save_file(file_id=image_content.image_file.file_id, file_name=file_name)
136-
print(f"Saved image file to: {Path.cwd() / file_name}")
137-
138-
# Print the file path(s) from the messages
139-
for file_path_annotation in messages.file_path_annotations:
140-
print(f"File Paths:")
141-
print(f"Type: {file_path_annotation.type}")
142-
print(f"Text: {file_path_annotation.text}")
143-
print(f"File ID: {file_path_annotation.file_path.file_id}")
144-
print(f"Start Index: {file_path_annotation.start_index}")
145-
print(f"End Index: {file_path_annotation.end_index}")
146-
project_client.agents.save_file(file_id=file_path_annotation.file_path.file_id, file_name=Path(file_path_annotation.text).name)
147-
148-
# Delete the agent once done
149-
project_client.agents.delete_agent(agent.id)
150-
print("Deleted agent")
97+
# Create a message in the thread
98+
message = project_client.agents.messages.create(
99+
thread_id=thread.id,
100+
role="user", # Role of the message sender
101+
content="When was Microsoft founded?", # Message content
102+
)
103+
print(f"Created message, ID: {message['id']}")
104+
105+
# Create and process an agent run in the thread
106+
run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)
107+
print(f"Run finished with status: {run.status}")
108+
109+
# Check if the run failed
110+
if run.status == "failed":
111+
print(f"Run failed: {run.last_error}")
112+
113+
# Fetch and log all messages from the thread
114+
messages = project_client.agents.messages.list(thread_id=thread.id)
115+
for message in messages.data:
116+
print(f"Role: {message.role}, Content: {message.content}")
117+
118+
# Delete the agent after use
119+
project_client.agents.delete_agent(agent.id)
120+
print("Deleted agent")
151121
```

articles/ai-services/agents/includes/quickstart-typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Use the following code to create and run an agent. To run this code, you will ne
5858

5959
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
6060

61-
[!INCLUDE [connection-string-portal](connection-string-portal.md)]
61+
[!INCLUDE [connection-string-portal](endpoint-string-portal.md)]
6262

6363
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
6464

Binary file not shown.

0 commit comments

Comments
 (0)