-
Notifications
You must be signed in to change notification settings - Fork 4k
Python: Support Declarative Spec for OpenAIAssistantAgent & OpenAIResponsesAgent #12247
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
moonbox3
merged 23 commits into
microsoft:main
from
moonbox3:assistant-declarative-agent
May 26, 2025
Merged
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9c5255f
wip
moonbox3 b599ef6
wip
moonbox3 8da28cf
wip
moonbox3 2db93ac
Merge branch 'main' into assistant-declarative-agent
moonbox3 05546ec
Updates for declarative spec
moonbox3 a741eab
Wip for Responses Agent
moonbox3 6491f2a
wip
moonbox3 62a86f5
Merge main
moonbox3 e9fbfc4
Updates for declarative spec
moonbox3 7549c62
Merge branch 'main' into assistant-declarative-agent
moonbox3 f119f81
Updates
moonbox3 bb81c78
Cleanup
moonbox3 be6fd36
Clean up naming
moonbox3 854d9bf
Simplify imports, clean up samples
moonbox3 8e6999a
Simplify imports, clean up samples
moonbox3 9305aee
Fix typo
moonbox3 3f04752
PR Feedback
moonbox3 4d8ccc3
Fix typo
moonbox3 24a83d0
Update sample doc string
moonbox3 1feb4f4
Merge main to branch
moonbox3 b44e37b
Resolve conflict with uv.lock
moonbox3 d890e7d
Fix typing for new openai pkg
moonbox3 0e9655d
Merge branch 'main' into assistant-declarative-agent
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
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
71 changes: 71 additions & 0 deletions
71
python/samples/concepts/agents/azure_ai_agent/azure_ai_agent_declarative_templating.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,71 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
import asyncio | ||
|
||
from azure.identity.aio import DefaultAzureCredential | ||
|
||
from semantic_kernel.agents import AgentRegistry, AzureAIAgent | ||
|
||
""" | ||
The following sample demonstrates how to create an Azure AI agent that answers | ||
user questions using the file search tool. | ||
|
||
The agent is used to answer user questions that require file search to help ground | ||
answers from the model. | ||
""" | ||
|
||
# Define the YAML string for the sample | ||
spec = """ | ||
type: foundry_agent | ||
name: StoryAgent | ||
description: An agent that generates a story about a topic. | ||
instructions: Tell a story about {{$topic}} that is {{$length}} sentences long. | ||
model: | ||
id: ${AzureAI:ChatModelId} | ||
connection: | ||
connection_string: ${AzureAI:ConnectionString} | ||
inputs: | ||
topic: | ||
description: The topic of the story. | ||
required: true | ||
default: Cats | ||
length: | ||
description: The number of sentences in the story. | ||
required: true | ||
default: 2 | ||
outputs: | ||
output1: | ||
description: The generated story. | ||
template: | ||
format: semantic-kernel | ||
""" | ||
|
||
|
||
async def main(): | ||
async with ( | ||
DefaultAzureCredential() as creds, | ||
AzureAIAgent.create_client(credential=creds) as client, | ||
): | ||
try: | ||
# Create the AzureAI Agent from the YAML spec | ||
agent: AzureAIAgent = await AgentRegistry.create_from_yaml( | ||
yaml_str=spec, | ||
client=client, | ||
) | ||
|
||
# Invoke the agent for the specified task | ||
async for response in agent.invoke( | ||
messages=None, | ||
moonbox3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): | ||
print(f"# {response.name}: {response}") | ||
finally: | ||
# Cleanup: Delete the agent, vector store, and file | ||
await client.agents.delete_agent(agent.id) | ||
|
||
""" | ||
|
||
moonbox3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
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
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
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.