From f5d605607494d2ea96c901f2b5b9502ed1189be0 Mon Sep 17 00:00:00 2001 From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> Date: Fri, 7 Nov 2025 19:57:27 +0000 Subject: [PATCH] Update --- .../Program.cs | 6 ++++- .../Program.cs | 9 +------- .../Program.cs | 22 ++++++++++++------- .../AzureAIAgentChatClient.cs | 5 ++++- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step05_StructuredOutput/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step05_StructuredOutput/Program.cs index d127f7dbd7..7eacdd9fa5 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step05_StructuredOutput/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step05_StructuredOutput/Program.cs @@ -10,6 +10,8 @@ using Azure.Identity; using Microsoft.Agents.AI; using SampleApp; +#pragma warning disable CA5399 + var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set."); var deploymentName = "gpt-5"; // Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; @@ -20,7 +22,9 @@ const string AssistantName = "StructuredOutputAssistant"; var agentsClient = new AgentsClient(new Uri(endpoint), new AzureCliCredential()); // Create ChatClientAgent directly -ChatClientAgent agent = await agentsClient.CreateAIAgentAsync(model: deploymentName, new ChatClientAgentOptions(name: AssistantName, instructions: AssistantInstructions)); +ChatClientAgent agent = await agentsClient.CreateAIAgentAsync( + model: deploymentName, + new ChatClientAgentOptions(name: AssistantName, instructions: AssistantInstructions)); // Set PersonInfo as the type parameter of RunAsync method to specify the expected structured output from the agent and invoke the agent with some unstructured input. AgentRunResponse response = await agent.RunAsync("Please provide information about John Smith, who is a 35-year-old software engineer."); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step06_PersistedConversations/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step06_PersistedConversations/Program.cs index 8e67acb776..9eb06768c6 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step06_PersistedConversations/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step06_PersistedConversations/Program.cs @@ -16,14 +16,7 @@ const string JokerName = "JokerAgent"; // Get a client to create/retrieve/delete server side agents with Azure Foundry Agents. var agentsClient = new AgentsClient(new Uri(endpoint), new AzureCliCredential()); -// Define the agent you want to create. (Prompt Agent in this case) -var agentDefinition = new PromptAgentDefinition(model: deploymentName) { Instructions = JokerInstructions }; - -// Create a server side agent version with the Azure.AI.Agents SDK client. -var agentVersion = agentsClient.CreateAgentVersion(agentName: JokerName, definition: agentDefinition); - -// Retrieve an AIAgent for the created server side agent version. -AIAgent agent = agentsClient.GetAIAgent(agentVersion); +AIAgent agent = await agentsClient.CreateAIAgentAsync(name: JokerName, model: deploymentName, instructions: JokerInstructions); // Start a new thread for the agent conversation. AgentThread thread = agent.GetNewThread(); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step07_3rdPartyThreadStorage/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step07_3rdPartyThreadStorage/Program.cs index cac94e0882..801c3c2978 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step07_3rdPartyThreadStorage/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/AzureAIAgents_Step07_3rdPartyThreadStorage/Program.cs @@ -26,14 +26,20 @@ VectorStore vectorStore = new InMemoryVectorStore(); // Get a client to create/retrieve/delete server side agents with Azure Foundry Agents. var agentsClient = new AgentsClient(new Uri(endpoint), new AzureCliCredential()); -// Define the agent you want to create. (Prompt Agent in this case) -var agentDefinition = new PromptAgentDefinition(model: deploymentName) { Instructions = JokerInstructions }; - -// Create a server side agent version with the Azure.AI.Agents SDK client. -var agentVersion = agentsClient.CreateAgentVersion(agentName: JokerName, definition: agentDefinition); - -// Retrieve an AIAgent for the created server side agent version. -AIAgent agent = agentsClient.GetAIAgent(agentVersion); +AIAgent agent = await agentsClient.CreateAIAgentAsync( + deploymentName, + new ChatClientAgentOptions + { + Instructions = JokerInstructions, + Name = JokerName, + ChatMessageStoreFactory = ctx => + { + // Create a new chat message store for this agent that stores the messages in a vector store. + // Each thread must get its own copy of the VectorChatMessageStore, since the store + // also contains the id that the thread is stored under. + return new VectorChatMessageStore(vectorStore, ctx.SerializedState, ctx.JsonSerializerOptions); + } + }); // Start a new thread for the agent conversation. AgentThread thread = agent.GetNewThread(); diff --git a/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs b/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs index 53730f64a8..c7e11cf4f9 100644 --- a/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs +++ b/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs @@ -97,9 +97,12 @@ internal sealed class AzureAIAgentChatClient : DelegatingChatClient private ChatOptions GetConversationEnabledChatOptions(ChatOptions? chatOptions, string conversationId) { - // Ignore all the chatOptions provided per-request and use by default the one provided at the agent creation. + // Start with a clone of the base chat options defined for the agent, if any. ChatOptions conversationChatOptions = this._chatOptions?.Clone() ?? new(); + // Ignore per-request all options that can't be overriden. + conversationChatOptions.Instructions = null; + // Preserve the original RawRepresentationFactory var originalFactory = chatOptions?.RawRepresentationFactory;