mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
aab621f5eb
* Fix tool normalization and provider samples - restore callable/single-tool normalization paths and unset tool-choice behavior\n- consolidate and expand chat/provider samples (OpenAI/Azure/Anthropic/Ollama/Bedrock)\n- migrate Bedrock lazy import surface to agent_framework.amazon and move provider samples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * small fix in sample * Finalize provider, samples, and core cleanup Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix CopilotTool passthrough in agent Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix link --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
import asyncio
|
|
import os
|
|
|
|
from agent_framework.azure import AzureOpenAIResponsesClient
|
|
from azure.identity import AzureCliCredential
|
|
|
|
"""
|
|
Hello Agent — Simplest possible agent
|
|
|
|
This sample creates a minimal agent using AzureOpenAIResponsesClient via an
|
|
Azure AI Foundry project endpoint, and runs it in both non-streaming and streaming modes.
|
|
|
|
There are XML tags in all of the get started samples, those are used to display the same code in the docs repo.
|
|
|
|
Environment variables:
|
|
AZURE_AI_PROJECT_ENDPOINT — Your Azure AI Foundry project endpoint
|
|
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME — Model deployment name (e.g. gpt-4o)
|
|
"""
|
|
|
|
|
|
async def main() -> None:
|
|
# <create_agent>
|
|
credential = AzureCliCredential()
|
|
client = AzureOpenAIResponsesClient(
|
|
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
|
|
deployment_name=os.environ["AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME"],
|
|
credential=credential,
|
|
)
|
|
|
|
agent = client.as_agent(
|
|
name="HelloAgent",
|
|
instructions="You are a friendly assistant. Keep your answers brief.",
|
|
)
|
|
# </create_agent>
|
|
|
|
# <run_agent>
|
|
# Non-streaming: get the complete response at once
|
|
result = await agent.run("What is the capital of France?")
|
|
print(f"Agent: {result}")
|
|
# </run_agent>
|
|
|
|
# <run_agent_streaming>
|
|
# Streaming: receive tokens as they are generated
|
|
print("Agent (streaming): ", end="", flush=True)
|
|
async for chunk in agent.run("Tell me a one-sentence fun fact.", stream=True):
|
|
if chunk.text:
|
|
print(chunk.text, end="", flush=True)
|
|
print()
|
|
# </run_agent_streaming>
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|