mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
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:
committed by
GitHub
Unverified
parent
6acab3d1d6
commit
519bb0cb2b
@@ -18,7 +18,7 @@ Prerequisites:
|
||||
- `pip install agent-framework-foundry agent-framework-declarative --pre`
|
||||
- Set the following environment variables in a .env file or your environment:
|
||||
- FOUNDRY_PROJECT_ENDPOINT
|
||||
- AZURE_OPENAI_MODEL
|
||||
- FOUNDRY_MODEL
|
||||
"""
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ instructions: Specialized diagnostic and issue detection agent for systems with
|
||||
description: A agent that performs diagnostics on systems and can escalate issues when critical errors are detected.
|
||||
|
||||
model:
|
||||
id: =Env.AZURE_OPENAI_MODEL
|
||||
id: =Env.FOUNDRY_MODEL
|
||||
"""
|
||||
# create the agent from the yaml
|
||||
async with (
|
||||
|
||||
@@ -9,6 +9,20 @@ from dotenv import load_dotenv
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
"""
|
||||
This sample demonstrates creating an agent from a declarative YAML file specification.
|
||||
|
||||
It uses a MCP server to connect to the Microsoft Learn content and a FoundryChatClient.
|
||||
|
||||
The yaml also has some chat options set, such as temperature and topP.
|
||||
These options do not work with newer OpenAI models, so ensure to use a compatible model such as gpt-4o-mini.
|
||||
|
||||
Environment variables:
|
||||
- FOUNDRY_PROJECT_ENDPOINT: The endpoint URL for the Foundry project.
|
||||
- FOUNDRY_MODEL: The model ID to use for the agent, make sure it is compatible with the chat options specified in
|
||||
the yaml, or remove the options.
|
||||
"""
|
||||
|
||||
|
||||
async def main():
|
||||
"""Create an agent from a declarative yaml specification and run it."""
|
||||
|
||||
+1
-4
@@ -14,11 +14,8 @@ async def main():
|
||||
# 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)
|
||||
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
|
||||
Reference in New Issue
Block a user