mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Update
This commit is contained in:
+5
-1
@@ -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<PersonInfo> response = await agent.RunAsync<PersonInfo>("Please provide information about John Smith, who is a 35-year-old software engineer.");
|
||||
|
||||
+1
-8
@@ -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();
|
||||
|
||||
+14
-8
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user