Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Bildirim temelli aracılar, programlı kod yazmak yerine YAML veya JSON dosyalarını kullanarak aracı yapılandırmasını tanımlamanızı sağlar. Bu yaklaşım aracıların ekipler arasında tanımlanmasını, değiştirilmesini ve paylaşılacağını kolaylaştırır.
Aşağıdaki örnekte YAML yapılandırmasından bildirim temelli aracı oluşturma gösterilmektedir:
using System;
using System.IO;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
// Load agent configuration from a YAML file
var yamlContent = File.ReadAllText("agent-config.yaml");
// Create the agent from the YAML definition
AIAgent agent = AgentFactory.CreateFromYaml(
yamlContent,
new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new AzureCliCredential()));
// Run the declarative agent
Console.WriteLine(await agent.RunAsync("Why is the sky blue?"));
YAML ile satır içi aracı tanımlama
Tam YAML belirtimini doğrudan kodunuzda bir dize olarak tanımlayabilirsiniz:
import asyncio
from agent_framework.declarative import AgentFactory
from azure.identity.aio import AzureCliCredential
async def main():
"""Create an agent from an inline YAML definition and run it."""
yaml_definition = """kind: Prompt
name: DiagnosticAgent
displayName: Diagnostic Assistant
instructions: Specialized diagnostic and issue detection agent for systems with critical error protocol and automatic handoff capabilities
description: An agent that performs diagnostics on systems and can escalate issues when critical errors are detected.
model:
id: =Env.AZURE_OPENAI_MODEL
connection:
kind: remote
endpoint: =Env.AZURE_AI_PROJECT_ENDPOINT
"""
async with (
AzureCliCredential() as credential,
AgentFactory(client_kwargs={"credential": credential}).create_agent_from_yaml(yaml_definition) as agent,
):
response = await agent.run("What can you do for me?")
print("Agent response:", response.text)
if __name__ == "__main__":
asyncio.run(main())
YAML dosyasından aracı yükleme
YAML tanımını bir dosyadan da yükleyebilirsiniz:
import asyncio
from pathlib import Path
from agent_framework.declarative import AgentFactory
from azure.identity import AzureCliCredential
async def main():
"""Create an agent from a declarative YAML file and run it."""
yaml_path = Path(__file__).parent / "agent-config.yaml"
with yaml_path.open("r") as f:
yaml_str = f.read()
agent = AgentFactory(client_kwargs={"credential": AzureCliCredential()}).create_agent_from_yaml(yaml_str)
response = await agent.run("Why is the sky blue?")
print("Agent response:", response.text)
if __name__ == "__main__":
asyncio.run(main())