Python: updated declarative samples and handling of non-pydantic response formats (#5022)

* updated declarative samples and handling of non-pydantic response formats

* fixed from comments

* update docstring
This commit is contained in:
Eduard van Valkenburg
2026-04-01 19:16:00 +00:00
committed by GitHub
parent 6acab3d1d6
commit 519bb0cb2b
21 changed files with 370 additions and 90 deletions
@@ -0,0 +1,30 @@
# Copyright (c) Microsoft. All rights reserved.
import asyncio
from pathlib import Path
from agent_framework.declarative import AgentFactory
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 / "agent-samples" / "openai" / "OpenAIResponses.yaml"
# create the agent from the yaml
agent = AgentFactory(safe_mode=False).create_agent_from_yaml_path(yaml_path)
# 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())