mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: added inline yaml sample (#2582)
* added inline yaml sample * fixed some typos and added intro comment * added description params and pass through to client * add azure assistants * fix tests * observabiltiy mypy fix * for some reason mypy doesn't accept a subclass --------- Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
42ffe59592
commit
d774b64df0
@@ -47,7 +47,17 @@ Shows how to create an agent that can search and retrieve information from Micro
|
||||
|
||||
**Key concepts**: Azure AI Foundry integration, MCP server usage, async patterns, resource management
|
||||
|
||||
### 3. **Azure OpenAI Responses Agent** ([`azure_openai_responses_agent.py`](./azure_openai_responses_agent.py))
|
||||
### 3. **Inline YAML Agent** ([`inline_yaml.py`](./inline_yaml.py))
|
||||
|
||||
Shows how to create an agent using an inline YAML string rather than a file.
|
||||
|
||||
- Uses Azure AI Foundry v2 Client with instructions.
|
||||
|
||||
**Requirements**: `pip install agent-framework-azure-ai --pre`
|
||||
|
||||
**Key concepts**: Inline YAML definition.
|
||||
|
||||
### 4. **Azure OpenAI Responses Agent** ([`azure_openai_responses_agent.py`](./azure_openai_responses_agent.py))
|
||||
|
||||
Illustrates a basic agent using Azure OpenAI with structured responses.
|
||||
|
||||
@@ -58,7 +68,7 @@ Illustrates a basic agent using Azure OpenAI with structured responses.
|
||||
|
||||
**Key concepts**: Azure OpenAI integration, credential management, structured outputs
|
||||
|
||||
### 4. **OpenAI Responses Agent** ([`openai_responses_agent.py`](./openai_responses_agent.py))
|
||||
### 5. **OpenAI Responses Agent** ([`openai_responses_agent.py`](./openai_responses_agent.py))
|
||||
|
||||
Demonstrates the simplest possible agent using OpenAI directly.
|
||||
|
||||
@@ -243,6 +253,7 @@ Each sample can be run independently. Make sure you have the required environmen
|
||||
# Run a specific sample
|
||||
python get_weather_agent.py
|
||||
python microsoft_learn_agent.py
|
||||
python inline_yaml.py
|
||||
python azure_openai_responses_agent.py
|
||||
python openai_responses_agent.py
|
||||
```
|
||||
|
||||
@@ -26,7 +26,7 @@ async def main():
|
||||
|
||||
# create the AgentFactory with a chat client and bindings
|
||||
agent_factory = AgentFactory(
|
||||
AzureOpenAIResponsesClient(credential=AzureCliCredential()),
|
||||
chat_client=AzureOpenAIResponsesClient(credential=AzureCliCredential()),
|
||||
bindings={"get_weather": get_weather},
|
||||
)
|
||||
# create the agent from the yaml
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
import asyncio
|
||||
|
||||
from agent_framework.declarative import AgentFactory
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
"""
|
||||
This sample shows how to create an agent using an inline YAML string rather than a file.
|
||||
|
||||
It uses a Azure AI Client so it needs the credential to be passed into the AgentFactory.
|
||||
|
||||
Prerequisites:
|
||||
- `pip install agent-framework-azure-ai agent-framework-declarative --pre`
|
||||
- Set the following environment variables in a .env file or your environment:
|
||||
- AZURE_AI_PROJECT_ENDPOINT
|
||||
- AZURE_OPENAI_MODEL
|
||||
"""
|
||||
|
||||
|
||||
async def main():
|
||||
"""Create an agent from a declarative YAML specification 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: A 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
|
||||
"""
|
||||
# create the agent from the yaml
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AgentFactory(client_kwargs={"async_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())
|
||||
Reference in New Issue
Block a user