mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
57da1bcfeb
* Updated declarative kind mapping * Fixed required property handling * Updated inline yaml sample * Fixed remaining declarative samples * Added lazy initialization for PowerFx engine * Small fix
35 lines
1021 B
Python
35 lines
1021 B
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
import asyncio
|
|
from pathlib import Path
|
|
|
|
from agent_framework.declarative import AgentFactory
|
|
from dotenv import load_dotenv
|
|
|
|
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 / "agent-samples" / "openai" / "OpenAIResponses.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(safe_mode=False).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
|
|
print("Agent response:", parsed)
|
|
except Exception:
|
|
print("Agent response:", response.text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|