mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Merge branch 'main' into copilot/move-workflow-and-agent-samples
This commit is contained in:
@@ -68,7 +68,7 @@ Illustrates a basic agent using Azure OpenAI with structured responses.
|
||||
|
||||
**Key concepts**: Azure OpenAI integration, credential management, structured outputs
|
||||
|
||||
### 5. **OpenAI Responses Agent** ([`openai_responses_agent.py`](./openai_responses_agent.py))
|
||||
### 5. **OpenAI Responses Agent** ([`openai_agent.py`](./openai_agent.py))
|
||||
|
||||
Demonstrates the simplest possible agent using OpenAI directly.
|
||||
|
||||
@@ -159,7 +159,7 @@ agent_factory = AgentFactory(
|
||||
"MyProvider": {
|
||||
"package": "my_custom_module",
|
||||
"name": "MyCustomChatClient",
|
||||
"model_id_field": "model_id",
|
||||
"model_field": "model",
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -176,7 +176,7 @@ agent = agent_factory.create_agent_from_yaml_path(Path("custom_provider.yaml"))
|
||||
This allows you to extend the declarative framework with custom chat client implementations. The mapping requires:
|
||||
- **package**: The Python package/module to import from
|
||||
- **name**: The class name of your SupportsChatGetResponse implementation
|
||||
- **model_id_field**: The constructor parameter name that accepts the value of the `model.id` field from the YAML
|
||||
- **model_field**: The constructor parameter name that accepts the value of the `model.id` field from the YAML
|
||||
|
||||
You can reference your custom provider using either `Provider.ApiType` format or just `Provider` in your YAML configuration, as long as it matches the registered mapping.
|
||||
|
||||
|
||||
@@ -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 / "declarative-agents" / "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