-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: add(azure-ai): support reasoning config for AzureAIClient #3403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50a2898
add(azure-ai): support reasoning config for AzureAIClient
moonbox3 e878f35
Update sample
moonbox3 f9cb2d5
Merge branch 'main' into azure-ai-reasoning
moonbox3 4701442
Merge main
moonbox3 2d71196
improvements
moonbox3 39493e7
improve sample
moonbox3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
python/samples/getting_started/agents/azure_ai/azure_ai_with_reasoning.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| import asyncio | ||
|
|
||
| from agent_framework.azure import AzureAIProjectAgentProvider | ||
| from azure.ai.projects.models import Reasoning | ||
| from azure.identity.aio import AzureCliCredential | ||
|
|
||
| """ | ||
| Azure AI Agent with Reasoning Example | ||
|
|
||
| Demonstrates how to enable reasoning capabilities using the Reasoning option. | ||
| Shows both non-streaming and streaming approaches, including how to access | ||
| reasoning content (type="text_reasoning") separately from answer content. | ||
|
|
||
| Requires a reasoning-capable model (e.g., gpt-5.2) deployed in your Azure AI Project configured | ||
| as `AZURE_AI_MODEL_DEPLOYMENT_NAME` in your environment. | ||
| """ | ||
|
|
||
|
|
||
| async def non_streaming_example() -> None: | ||
| """Example of non-streaming response (get the complete result at once).""" | ||
| print("=== Non-streaming Response Example ===") | ||
|
|
||
| # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred | ||
| # authentication option. | ||
| async with ( | ||
| AzureCliCredential() as credential, | ||
| AzureAIProjectAgentProvider(credential=credential) as provider, | ||
| ): | ||
| agent = await provider.create_agent( | ||
| name="ReasoningWeatherAgent", | ||
| instructions="You are a helpful weather agent who likes to understand the underlying physics.", | ||
| default_options={"reasoning": Reasoning(effort="medium", summary="concise")}, | ||
| ) | ||
|
|
||
| query = "How does the Bernoulli effect work?" | ||
| print(f"User: {query}") | ||
| result = await agent.run(query) | ||
|
|
||
| for msg in result.messages: | ||
| for content in msg.contents: | ||
| if content.type == "text_reasoning": | ||
| print(f"[Reasoning]: {content.text}") | ||
| elif content.type == "text": | ||
| print(f"[Answer]: {content.text}") | ||
| print() | ||
|
|
||
|
|
||
| async def streaming_example() -> None: | ||
| """Example of streaming response (get results as they are generated).""" | ||
| print("=== Streaming Response Example ===") | ||
|
|
||
| # For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred | ||
| # authentication option. | ||
| async with ( | ||
| AzureCliCredential() as credential, | ||
| AzureAIProjectAgentProvider(credential=credential) as provider, | ||
| ): | ||
| agent = await provider.create_agent( | ||
| name="ReasoningWeatherAgent", | ||
| instructions="You are a helpful weather agent who likes to understand the underlying physics.", | ||
| default_options={"reasoning": Reasoning(effort="medium", summary="concise")}, | ||
| ) | ||
|
|
||
| query = "Help explain how air updrafts work?" | ||
| print(f"User: {query}") | ||
|
|
||
| shown_reasoning_label = False | ||
| shown_text_label = False | ||
| async for chunk in agent.run_stream(query): | ||
| for content in chunk.contents: | ||
| if content.type == "text_reasoning": | ||
| if not shown_reasoning_label: | ||
| print("[Reasoning]: ", end="", flush=True) | ||
| shown_reasoning_label = True | ||
| print(content.text, end="", flush=True) | ||
| elif content.type == "text": | ||
| if not shown_text_label: | ||
| print("\n\n[Answer]: ", end="", flush=True) | ||
| shown_text_label = True | ||
| print(content.text, end="", flush=True) | ||
| print("\n") | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| print("=== Azure AI Agent with Reasoning Example ===") | ||
|
|
||
| # await non_streaming_example() | ||
| await streaming_example() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.