mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fixed declarative samples (#4051)
* Updated declarative kind mapping * Fixed required property handling * Updated inline yaml sample * Fixed remaining declarative samples * Added lazy initialization for PowerFx engine * Small fix
This commit is contained in:
committed by
GitHub
Unverified
parent
1b87a07377
commit
57da1bcfeb
@@ -7,6 +7,9 @@ from typing import Literal
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from agent_framework.declarative import AgentFactory
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
def get_weather(location: str, unit: Literal["celsius", "fahrenheit"] = "celsius") -> str:
|
||||
|
||||
@@ -3,6 +3,9 @@ import asyncio
|
||||
|
||||
from agent_framework.declarative import AgentFactory
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
"""
|
||||
This sample shows how to create an agent using an inline YAML string rather than a file.
|
||||
@@ -34,7 +37,7 @@ model:
|
||||
# create the agent from the yaml
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AgentFactory(client_kwargs={"credential": credential}).create_agent_from_yaml(yaml_definition) as agent,
|
||||
AgentFactory(client_kwargs={"credential": credential}, safe_mode=False).create_agent_from_yaml(yaml_definition) as agent,
|
||||
):
|
||||
response = await agent.run("What can you do for me?")
|
||||
print("Agent response:", response.text)
|
||||
|
||||
@@ -28,7 +28,6 @@ import asyncio
|
||||
from agent_framework.declarative import AgentFactory
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
# Example 1: OpenAI.Responses with API key authentication
|
||||
|
||||
@@ -4,6 +4,9 @@ from pathlib import Path
|
||||
|
||||
from agent_framework.declarative import AgentFactory
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
async def main():
|
||||
@@ -15,7 +18,7 @@ async def main():
|
||||
# create the agent from the yaml
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AgentFactory(client_kwargs={"credential": credential}).create_agent_from_yaml_path(yaml_path) as agent,
|
||||
AgentFactory(client_kwargs={"credential": credential}, safe_mode=False).create_agent_from_yaml_path(yaml_path) as agent,
|
||||
):
|
||||
response = await agent.run("How do I create a storage account with private endpoint using bicep?")
|
||||
print("Agent response:", response.text)
|
||||
|
||||
@@ -3,6 +3,9 @@ import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agent_framework.declarative import AgentFactory
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
async def main():
|
||||
@@ -16,7 +19,7 @@ async def main():
|
||||
yaml_str = f.read()
|
||||
|
||||
# create the agent from the yaml
|
||||
agent = AgentFactory().create_agent_from_yaml(yaml_str)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user