mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
b0613a8ceb
* Bump Azure.AI.Projects to 2.0.0 GA - Update Azure.AI.Projects from 2.0.0-beta.2 to 2.0.0 in CPM - Update Azure.Identity from 1.19.0 to 1.20.0 (transitive dep) - Update System.ClientModel from 1.9.0 to 1.10.0 (transitive dep) - Rename types per Azure.AI.Projects.Agents 2.0.0 breaking changes: - AgentVersion -> ProjectsAgentVersion - AgentRecord -> ProjectsAgentRecord - AgentDefinition -> ProjectsAgentDefinition - AgentVersionCreationOptions -> ProjectsAgentVersionCreationOptions - PromptAgentDefinition -> DeclarativeAgentDefinition - AgentTool -> ProjectsAgentTool - AgentsClient -> AgentAdministrationClient - .Agents property -> .AgentAdministrationClient - Add using Azure.AI.Projects.Memory namespace (types moved) - Update AGENTS.md with BOM and output capture conventions * Address PR review feedback - Rename AIProjectClient parameter to aiProjectClient in AsChatClientAgent overloads - Fix XML doc: ProjectsAgentTool namespace from Azure.AI.Projects.OpenAI to Azure.AI.Projects.Agents - Rename test method to reflect DeclarativeAgentDefinition terminology
37 lines
1.6 KiB
C#
37 lines
1.6 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// This sample shows how to create, use, and clean up a FoundryAgent backed by a server-side
|
|
// versioned agent in Microsoft Foundry. It demonstrates the full lifecycle:
|
|
// create agent version -> wrap as FoundryAgent -> run -> delete.
|
|
|
|
using Azure.AI.Projects;
|
|
using Azure.AI.Projects.Agents;
|
|
using Azure.Identity;
|
|
using Microsoft.Agents.AI.Foundry;
|
|
|
|
string endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set.");
|
|
string deploymentName = Environment.GetEnvironmentVariable("AZURE_AI_MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
|
|
|
|
const string JokerName = "JokerAgent";
|
|
|
|
// Create the AIProjectClient to manage server-side agents.
|
|
AIProjectClient aiProjectClient = new(new Uri(endpoint), new AzureCliCredential());
|
|
|
|
// Create a server-side agent version using the native SDK.
|
|
ProjectsAgentVersion agentVersion = await aiProjectClient.AgentAdministrationClient.CreateAgentVersionAsync(
|
|
JokerName,
|
|
new ProjectsAgentVersionCreationOptions(
|
|
new DeclarativeAgentDefinition(model: deploymentName)
|
|
{
|
|
Instructions = "You are good at telling jokes.",
|
|
}));
|
|
|
|
// Wrap the agent version as a FoundryAgent using the AsAIAgent extension.
|
|
FoundryAgent agent = aiProjectClient.AsAIAgent(agentVersion);
|
|
|
|
// Once you have the agent, you can invoke it like any other AIAgent.
|
|
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
|
|
|
|
// Cleanup: deletes the agent and all its versions.
|
|
await aiProjectClient.AgentAdministrationClient.DeleteAgentAsync(agent.Name);
|