Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
using Azure.Identity;
using Azure.AI.Projects;
using Azure.AI.Projects.OpenAI;
using Azure.Identity;
using OpenAI.Responses;

#pragma warning disable OPENAI001

string projectEndpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT")
?? throw new InvalidOperationException("Missing environment variable 'PROJECT_ENDPOINT'");
string modelDeploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME")
?? throw new InvalidOperationException("Missing environment variable 'MODEL_DEPLOYMENT_NAME'");
string agentName = Environment.GetEnvironmentVariable("AGENT_NAME")
?? throw new InvalidOperationException("Missing environment variable 'AGENT_NAME'");
// Format: "https://resource_name.ai.azure.com/api/projects/project_name"
var projectEndpoint = "your_project_endpoint";
var agentName = "your_agent_name";

AIProjectClient projectClient = new(new Uri(projectEndpoint), new AzureCliCredential());
// Create project client to call Foundry API
AIProjectClient projectClient = new(
endpoint: new Uri(projectEndpoint),
tokenProvider: new DefaultAzureCredential());

// Optional Step: Create a conversation to use with the agent
// Create a conversation for multi-turn chat
ProjectConversation conversation = projectClient.OpenAI.Conversations.CreateProjectConversation();

// Chat with the agent to answer questions
ProjectResponsesClient responsesClient = projectClient.OpenAI.GetProjectResponsesClientForAgent(
defaultAgent: agentName,
defaultConversationId: conversation.Id);

// Chat with the agent to answer questions
ResponseResult response = responsesClient.CreateResponse("What is the size of France in square miles?");
Console.WriteLine(response.GetOutputText());

// Optional Step: Ask a follow-up question in the same conversation
// Ask a follow-up question in the same conversation
response = responsesClient.CreateResponse("And what is the capital city?");
Console.WriteLine(response.GetOutputText());
28 changes: 12 additions & 16 deletions samples/csharp/quickstart/create-agent/quickstart-create-agent.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
using Azure.Identity;
using Azure.AI.Projects;
using Azure.AI.Projects.OpenAI;
using Azure.Identity;

string projectEndpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT")
?? throw new InvalidOperationException("Missing environment variable 'PROJECT_ENDPOINT'");
string modelDeploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME")
?? throw new InvalidOperationException("Missing environment variable 'MODEL_DEPLOYMENT_NAME'");
string agentName = Environment.GetEnvironmentVariable("AGENT_NAME")
?? throw new InvalidOperationException("Missing environment variable 'AGENT_NAME'");
// Format: "https://resource_name.ai.azure.com/api/projects/project_name"
var projectEndpoint = "your_project_endpoint";
var agentName = "your_agent_name";

AIProjectClient projectClient = new(new Uri(projectEndpoint), new AzureCliCredential());
// Create project client to call Foundry API
AIProjectClient projectClient = new(
endpoint: new Uri(projectEndpoint),
tokenProvider: new DefaultAzureCredential());

AgentDefinition agentDefinition = new PromptAgentDefinition(modelDeploymentName)
// Create an agent with a model and instructions
AgentDefinition agentDefinition = new PromptAgentDefinition("gpt-5-mini")
{
Instructions = "You are a helpful assistant that answers general questions",
};

AgentVersion newAgentVersion = projectClient.Agents.CreateAgentVersion(
AgentVersion agent = projectClient.Agents.CreateAgentVersion(
agentName,
options: new(agentDefinition));

List<AgentVersion> agentVersions = [..projectClient.Agents.GetAgentVersions(agentName)];
foreach (AgentVersion agentVersion in agentVersions)
{
Console.WriteLine($"Agent: {agentVersion.Id}, Name: {agentVersion.Name}, Version: {agentVersion.Version}");
}
Console.WriteLine($"Agent created (id: {agent.Id}, name: {agent.Name}, version: {agent.Version})");
20 changes: 11 additions & 9 deletions samples/csharp/quickstart/responses/quickstart-responses.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using Azure.Identity;
using Azure.AI.Projects;
using Azure.AI.Projects.OpenAI;
using Azure.Identity;
using OpenAI.Responses;

#pragma warning disable OPENAI001

string projectEndpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT")
?? throw new InvalidOperationException("Missing environment variable 'PROJECT_ENDPOINT'");
string modelDeploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME")
?? throw new InvalidOperationException("Missing environment variable 'MODEL_DEPLOYMENT_NAME'");

AIProjectClient projectClient = new(new Uri(projectEndpoint), new AzureCliCredential());
// Format: "https://resource_name.ai.azure.com/api/projects/project_name"
var projectEndpoint = "your_project_endpoint";

ProjectResponsesClient responseClient = projectClient.OpenAI.GetProjectResponsesClientForModel(modelDeploymentName);
ResponseResult response = await responseClient.CreateResponseAsync("What is the size of France in square miles?");
// Create project client to call Foundry API
AIProjectClient projectClient = new(
endpoint: new Uri(projectEndpoint),
tokenProvider: new DefaultAzureCredential());

// Run a responses API call
ProjectResponsesClient responseClient = projectClient.OpenAI.GetProjectResponsesClientForModel("gpt-5-mini");
ResponseResult response = await responseClient.CreateResponseAsync(
"What is the size of France in square miles?");
Console.WriteLine(response.GetOutputText());
Original file line number Diff line number Diff line change
@@ -1,64 +1,33 @@
package com.azure.ai.agents;

import com.azure.ai.agents.models.AgentReference;
import com.azure.ai.agents.models.AgentVersionDetails;
import com.azure.ai.agents.models.PromptAgentDefinition;
import com.azure.identity.AuthenticationUtil;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.openai.azure.AzureOpenAIServiceVersion;
import com.openai.azure.AzureUrlPathMode;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.credential.BearerTokenCredential;
import com.openai.models.conversations.Conversation;
import com.openai.models.conversations.items.ItemCreateParams;
import com.openai.models.responses.EasyInputMessage;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCreateParams;

public class ChatWithAgent {
public static void main(String[] args) {
String endpoint = Configuration.getGlobalConfiguration().get("AZURE_AGENTS_ENDPOINT");
String agentName = "MyAgent";

AgentsClient agentsClient = new AgentsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint(endpoint)
.buildAgentsClient();
// Format: "https://resource_name.ai.azure.com/api/projects/project_name"
String projectEndpoint = "your_project_endpoint";
String agentName = "your_agent_name";

AgentDetails agent = agentsClient.getAgent(agentName);
// Create clients to call Foundry API
AgentsClientBuilder builder = new AgentsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint(projectEndpoint);
ResponsesClient responsesClient = builder.buildResponsesClient();
ConversationsClient conversationsClient = builder.buildConversationsClient();

// Create a conversation for multi-turn chat
Conversation conversation = conversationsClient.getConversationService().create();
conversationsClient.getConversationService().items().create(
ItemCreateParams.builder()
.conversationId(conversation.id())
.addItem(EasyInputMessage.builder()
.role(EasyInputMessage.Role.SYSTEM)
.content("You are a helpful assistant that speaks like a pirate.")
.build()
).addItem(EasyInputMessage.builder()
.role(EasyInputMessage.Role.USER)
.content("Hello, agent!")
.build()
).build()
);

AgentReference agentReference = new AgentReference(agent.getName()).setVersion(agent.getVersion());
Response response = responsesClient.createWithAgentConversation(agentReference, conversation.id());

OpenAIClient client = OpenAIOkHttpClient.builder()
.baseUrl(endpoint.endsWith("/") ? endpoint + "openai" : endpoint + "/openai")
.azureUrlPathMode(AzureUrlPathMode.UNIFIED)
.credential(BearerTokenCredential.create(AuthenticationUtil.getBearerTokenSupplier(
new DefaultAzureCredentialBuilder().build(), "https://ai.azure.com/.default")))
.azureServiceVersion(AzureOpenAIServiceVersion.fromString("2025-11-15-preview"))
.build();

// TODO: Java SDK does not yet support passing conversation ID or agent reference
// to ResponseCreateParams. Update once the SDK adds agent+conversation support.
// Chat with the agent to answer questions
ResponseCreateParams responseRequest = new ResponseCreateParams.Builder()
.input("Hello, how can you help me?")
.model(model)
.build();

Response result = client.responses().create(responseRequest);
.input("What is the size of France in square miles?")
.build();
Response response = responsesClient.getResponseService().create(responseRequest);
System.out.println(response.output());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import com.azure.ai.agents.models.AgentVersionDetails;
import com.azure.ai.agents.models.PromptAgentDefinition;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;

public class CreateAgent {
public static void main(String[] args) {
String endpoint = Configuration.getGlobalConfiguration().get("PROJECT_ENDPOINT");
String model = Configuration.getGlobalConfiguration().get("MODEL_DEPLOYMENT_NAME");
// Code sample for creating an agent
// Format: "https://resource_name.ai.azure.com/api/projects/project_name"
String projectEndpoint = "your_project_endpoint";
String agentName = "your_agent_name";

// Create agents client to call Foundry API
AgentsClient agentsClient = new AgentsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint(endpoint)
.endpoint(projectEndpoint)
.buildAgentsClient();

PromptAgentDefinition request = new PromptAgentDefinition(model);
AgentVersionDetails agent = agentsClient.createAgentVersion("MyAgent", request);
// Create an agent with a model and instructions
PromptAgentDefinition request = new PromptAgentDefinition("gpt-5-mini");
AgentVersionDetails agent = agentsClient.createAgentVersion(agentName, request);

System.out.println("Agent ID: " + agent.getId());
System.out.println("Agent Name: " + agent.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
package com.azure.ai.agents;

import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCreateParams;

public class CreateResponse {
public static void main(String[] args) {
String endpoint = Configuration.getGlobalConfiguration().get("PROJECT_ENDPOINT");
String model = Configuration.getGlobalConfiguration().get("MODEL_DEPLOYMENT_NAME");
// Code sample for creating a response
// Format: "https://resource_name.ai.azure.com/api/projects/project_name"
String projectEndpoint = "your_project_endpoint";

// Create responses client to call Foundry API
ResponsesClient responsesClient = new AgentsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint(endpoint)
.serviceVersion(AgentsServiceVersion.V2025_11_15_PREVIEW)
.endpoint(projectEndpoint)
.buildResponsesClient();

// Run a responses API call
ResponseCreateParams responseRequest = new ResponseCreateParams.Builder()
.input("Hello, how can you help me?")
.model(model)
.input("What is the size of France in square miles?")
.model("gpt-5-mini") // supports all Foundry direct models
.build();

Response response = responsesClient.getResponseService().create(responseRequest);

System.out.println("Response ID: " + response.id());
System.out.println("Response Model: " + response.model());
System.out.println("Response Created At: " + response.createdAt());
System.out.println("Response Output: " + response.output());
System.out.println(response.output());
}
}
36 changes: 17 additions & 19 deletions samples/python/quickstart/quickstart-chat-with-agent.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import os
from dotenv import load_dotenv
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient

load_dotenv()
# Format: "https://resource_name.ai.azure.com/api/projects/project_name"
FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint"
AGENT_NAME = "your_agent_name"

project_client = AIProjectClient(
endpoint=os.environ["PROJECT_ENDPOINT"],
# Create project and openai clients to call Foundry API
project = AIProjectClient(
endpoint=FOUNDRY_PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)
openai = project.get_openai_client()

agent_name = os.environ["AGENT_NAME"]
openai_client = project_client.get_openai_client()

# Optional Step: Create a conversation to use with the agent
conversation = openai_client.conversations.create()
print(f"Created conversation (id: {conversation.id})")
# Create a conversation for multi-turn chat
conversation = openai.conversations.create()

# Chat with the agent to answer questions
response = openai_client.responses.create(
conversation=conversation.id, #Optional conversation context for multi-turn
extra_body={"agent": {"name": agent_name, "type": "agent_reference"}},
response = openai.responses.create(
conversation=conversation.id,
extra_body={"agent": {"name": AGENT_NAME, "type": "agent_reference"}},
input="What is the size of France in square miles?",
)
print(f"Response output: {response.output_text}")
print(response.output_text)

# Optional Step: Ask a follow-up question in the same conversation
response = openai_client.responses.create(
# Ask a follow-up question in the same conversation
response = openai.responses.create(
conversation=conversation.id,
extra_body={"agent": {"name": agent_name, "type": "agent_reference"}},
extra_body={"agent": {"name": AGENT_NAME, "type": "agent_reference"}},
input="And what is the capital city?",
)
print(f"Response output: {response.output_text}")
print(response.output_text)
18 changes: 10 additions & 8 deletions samples/python/quickstart/quickstart-create-agent.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import os
from dotenv import load_dotenv
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import PromptAgentDefinition

load_dotenv()
# Format: "https://resource_name.ai.azure.com/api/projects/project_name"
FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint"
AGENT_NAME = "your_agent_name"

project_client = AIProjectClient(
endpoint=os.environ["PROJECT_ENDPOINT"],
# Create project client to call Foundry API
project = AIProjectClient(
endpoint=FOUNDRY_PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)

agent = project_client.agents.create_version(
agent_name=os.environ["AGENT_NAME"],
# Create an agent with a model and instructions
agent = project.agents.create_version(
agent_name=AGENT_NAME,
definition=PromptAgentDefinition(
model=os.environ["MODEL_DEPLOYMENT_NAME"],
model="gpt-5-mini", # supports all Foundry direct models
instructions="You are a helpful assistant that answers general questions",
),
)
Expand Down
21 changes: 9 additions & 12 deletions samples/python/quickstart/quickstart-responses.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import os
from dotenv import load_dotenv
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient

load_dotenv()
# Format: "https://resource_name.ai.azure.com/api/projects/project_name"
FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint"

print(f"Using PROJECT_ENDPOINT: {os.environ['PROJECT_ENDPOINT']}")
print(f"Using MODEL_DEPLOYMENT_NAME: {os.environ['MODEL_DEPLOYMENT_NAME']}")

project_client = AIProjectClient(
endpoint=os.environ["PROJECT_ENDPOINT"],
# Create project and openai clients to call Foundry API
project = AIProjectClient(
endpoint=FOUNDRY_PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)
openai = project.get_openai_client()

openai_client = project_client.get_openai_client()

response = openai_client.responses.create(
model=os.environ["MODEL_DEPLOYMENT_NAME"],
# Run a responses API call
response = openai.responses.create(
model="gpt-5-mini", # supports all Foundry direct models
input="What is the size of France in square miles?",
)
print(f"Response output: {response.output_text}")
Loading