Skip to content
Draft
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
4 changes: 2 additions & 2 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<!-- System.* -->
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.3" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="System.ClientModel" Version="1.8.1" />
<PackageVersion Include="System.ClientModel" Version="1.9.0" />
<PackageVersion Include="System.CodeDom" Version="10.0.0" />
<PackageVersion Include="System.Collections.Immutable" Version="10.0.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-rc.2.25502.107" />
Expand Down Expand Up @@ -109,7 +109,7 @@
<PackageVersion Include="AWSSDK.Extensions.Bedrock.MEAI" Version="4.0.5.1" />
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.10.0" />
<PackageVersion Include="OllamaSharp" Version="5.4.8" />
<PackageVersion Include="OpenAI" Version="2.8.0" />
<PackageVersion Include="OpenAI" Version="2.9.1" />
<!-- Identity -->
<PackageVersion Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.78.0" />
<!-- Workflows -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This sample shows how to create and use a simple AI agent with OpenAI Responses as the backend.

using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using OpenAI;
using OpenAI.Responses;

Expand All @@ -11,8 +12,17 @@

AIAgent agent = new OpenAIClient(
apiKey)
.GetResponsesClient(model)
.AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker");
.GetResponsesClient()
.AsAIAgent(
new ChatClientAgentOptions()
{
Name = "Joker",
ChatOptions = new ChatOptions()
{
ModelId = model,
Instructions = "You are good at telling jokes."
}
});

// Invoke the agent and output the text result.
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
var model = Environment.GetEnvironmentVariable("OPENAI_CHAT_MODEL_NAME") ?? "gpt-5";

var client = new OpenAIClient(apiKey)
.GetResponsesClient(model)
.GetResponsesClient()
.AsIChatClient().AsBuilder()
.ConfigureOptions(o =>
{
o.ModelId = model;
o.Reasoning = new()
{
Effort = ReasoningEffort.Medium,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// This sample demonstrates how to create OpenAIResponseClientAgent directly from an ResponsesClient instance.

using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using OpenAI;
using OpenAI.Responses;
using OpenAIResponseClientSample;
Expand All @@ -10,10 +12,18 @@
var model = Environment.GetEnvironmentVariable("OPENAI_CHAT_MODEL_NAME") ?? "gpt-4o-mini";

// Create a ResponsesClient directly from OpenAIClient
ResponsesClient responseClient = new OpenAIClient(apiKey).GetResponsesClient(model);
ResponsesClient responseClient = new OpenAIClient(apiKey).GetResponsesClient();

// Create an agent directly from the ResponsesClient using OpenAIResponseClientAgent
OpenAIResponseClientAgent agent = new(responseClient, instructions: "You are good at telling jokes.", name: "Joker");
OpenAIResponseClientAgent agent = new(responseClient, new ChatClientAgentOptions()
{
Name = "Joker",
ChatOptions = new ChatOptions()
{
ModelId = model,
Instructions = "You are good at telling jokes."
}
});

ResponseItem userMessage = ResponseItem.CreateUserMessageItem("Tell me a joke about a pirate.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
ConversationClient conversationClient = openAIClient.GetConversationClient();

// Create an agent directly from the ResponsesClient using OpenAIResponseClientAgent
ChatClientAgent agent = new(openAIClient.GetResponsesClient(model).AsIChatClient(), instructions: "You are a helpful assistant.", name: "ConversationAgent");
ChatClientAgent agent = new(openAIClient.GetResponsesClient().AsIChatClient(),
new ChatClientAgentOptions()
{
Name = "ConversationAgent",
ChatOptions = new ChatOptions()
{
ModelId = model,
Instructions = "You are a helpful assistant."
}
});

ClientResult createConversationResult = await conversationClient.CreateConversationAsync(BinaryContent.Create(BinaryData.FromString("{}")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public override async IAsyncEnumerable<AgentResponseUpdate> RunStreamingAsync(
Transport = new HttpClientPipelineTransport(httpClient)
};

var openAiClient = new ResponsesClient(model: agentName, credential: new ApiKeyCredential("dummy-key"), options: options).AsIChatClient();
var openAiClient = new ResponsesClient(credential: new ApiKeyCredential("dummy-key"), options: options).AsIChatClient();
var chatOptions = new ChatOptions()
{
ModelId = agentName,
ConversationId = sessionId
};

Expand Down
Loading