db620d33df
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
import asyncio
|
|
from pathlib import Path
|
|
|
|
from agent_framework.declarative import AgentFactory
|
|
from azure.identity import AzureCliCredential
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables from .env file
|
|
load_dotenv()
|
|
|
|
|
|
async def main():
|
|
"""Create an agent from a declarative yaml specification and run it."""
|
|
# get the path
|
|
current_path = Path(__file__).parent
|
|
yaml_path = (
|
|
current_path.parent.parent.parent.parent
|
|
/ "declarative-agents"
|
|
/ "agent-samples"
|
|
/ "azure"
|
|
/ "AzureOpenAIResponses.yaml"
|
|
)
|
|
# load the yaml from the path
|
|
with yaml_path.open("r") as f:
|
|
yaml_str = f.read()
|
|
# create the agent from the yaml
|
|
agent = AgentFactory(client_kwargs={"credential": AzureCliCredential()}).create_agent_from_yaml(yaml_str)
|
|
# use the agent
|
|
response = await agent.run("Why is the sky blue, answer in Dutch?")
|
|
# Use response.value with try/except for safe parsing
|
|
try:
|
|
parsed = response.value
|
|
model_dump_json = getattr(parsed, "model_dump_json", None)
|
|
if callable(model_dump_json):
|
|
print("Agent response:", model_dump_json(indent=2))
|
|
else:
|
|
print("Agent response:", response.text)
|
|
except Exception:
|
|
print("Agent response:", response.text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|