Skip to content

Python: Update the AzureAIAgent packages, types, and APIs based on Azure SDK's new code #12084

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 25 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd4dc81
updates to azure ai agent
moonbox3 May 13, 2025
f3af59f
Updates to AzureAIAgent based on changes from Azure SDK. Update unit …
moonbox3 May 13, 2025
c5fdea6
Merge main to branch
moonbox3 May 15, 2025
f76906c
Updates to declarative spec for AzureAIAgent changes
moonbox3 May 15, 2025
6490058
Updates to support latest AzureAIAgent abstractions
moonbox3 May 15, 2025
b9fe403
Revert setting name
moonbox3 May 15, 2025
18701e5
Revert to model_deployment_name in README
moonbox3 May 15, 2025
a676d26
Cleanup for api version and README
moonbox3 May 16, 2025
9f43564
Update to latest published packages.
moonbox3 May 16, 2025
51c441d
Bump Python version to 1.31.0
moonbox3 May 16, 2025
3fc1969
Merge branch 'main' into py-update-azureaiagent
moonbox3 May 16, 2025
4f2327f
Updating CI/CD env var name
moonbox3 May 16, 2025
5ed0a26
Merge branch 'py-update-azureaiagent' of github.com:moonbox3/semantic…
moonbox3 May 16, 2025
189f0db
Merge branch 'main' into py-update-azureaiagent
TaoChenOSU May 16, 2025
a3ef5bc
updates
moonbox3 May 19, 2025
c9a73c8
Merge branch 'py-update-azureaiagent' of github.com:moonbox3/semantic…
moonbox3 May 19, 2025
a94eb37
Merge branch 'main' into py-update-azureaiagent
moonbox3 May 19, 2025
791cb83
Merge branch 'main' into py-update-azureaiagent
moonbox3 May 19, 2025
6cd04d5
Merge branch 'py-update-azureaiagent' of github.com:moonbox3/semantic…
moonbox3 May 19, 2025
a249070
Update to azure extra project names
moonbox3 May 19, 2025
df71639
updates to use endpoint
moonbox3 May 19, 2025
ffc041a
Merge branch 'main' into py-update-azureaiagent
moonbox3 May 19, 2025
c3a1e7c
Validate tools on the agent
moonbox3 May 19, 2025
5732ec5
Merge branch 'py-update-azureaiagent' of github.com:moonbox3/semantic…
moonbox3 May 19, 2025
da0544f
Merge branch 'main' into py-update-azureaiagent
moonbox3 May 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ autogen = [
aws = [
"boto3>=1.36.4,<1.39.0",
]
# This is temporary to get the PR reviewed, and will be replaced when their new version is public.
azure = [
"azure-ai-projects >= 1.0.0b11",
"azure-ai-agents >= 1.0.0b3",
"azure-ai-inference >= 1.0.0b6",
"azure-ai-projects >= 1.0.0b7",
"azure-core-tracing-opentelemetry >= 1.0.0b11",
"azure-search-documents >= 11.6.0b4",
"azure-cosmos ~= 4.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ async def main() -> None:

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
# Create the agent definition
agent_definition = await client.agents.create_agent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import asyncio
import logging

from azure.ai.projects.models import AzureAISearchTool, ConnectionType
from azure.ai.agents.models import AzureAISearchTool
from azure.ai.projects.models import ConnectionType
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
Expand Down Expand Up @@ -39,17 +40,12 @@ async def main() -> None:

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
conn_list = await client.connections.list()

ai_search_conn_id = ""
for conn in conn_list:
if conn.connection_type == ConnectionType.AZURE_AI_SEARCH and conn.authentication_type == "ApiKey":
ai_search_conn_id = conn.id
async for connection in client.connections.list():
if connection.type == ConnectionType.AZURE_AI_SEARCH:
ai_search_conn_id = connection.id
break

ai_search = AzureAISearchTool(index_connection_id=ai_search_conn_id, index_name=AZURE_AI_SEARCH_INDEX_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio

from azure.ai.projects.models import BingGroundingTool
from azure.ai.agents.models import BingGroundingTool
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
from functools import reduce

from azure.ai.projects.models import BingGroundingTool
from azure.ai.agents.models import BingGroundingTool
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
from functools import reduce

from azure.ai.projects.models import CodeInterpreterTool
from azure.ai.agents.models import CodeInterpreterTool
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import os

from azure.ai.projects.models import FilePurpose
from azure.ai.agents.models import FilePurpose
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings
Expand All @@ -28,15 +28,15 @@
model:
id: ${AzureAI:ChatModelId}
connection:
connection_string: ${AzureAI:ConnectionString}
connection_string: ${AzureAI:Endpoint}
tools:
- type: code_interpreter
options:
file_ids:
- ${AzureAI:FileId1}
"""

settings = AzureAIAgentSettings() # ChatModelId & ConnectionString come from env vars
settings = AzureAIAgentSettings() # ChatModelId & Endpoint come from env vars


async def main():
Expand All @@ -54,7 +54,7 @@ async def main():

try:
# Upload the CSV file to the agent service
file = await client.agents.upload_file_and_poll(file_path=csv_file_path, purpose=FilePurpose.AGENTS)
file = await client.agents.files.upload_and_poll(file_path=csv_file_path, purpose=FilePurpose.AGENTS)

# Create the AzureAI Agent from the YAML spec
# Note: the extras can be provided in the short-format (shown below) or
Expand Down Expand Up @@ -100,7 +100,7 @@ async def main():
finally:
# Cleanup: Delete the thread and agent
await client.agents.delete_agent(agent.id)
await client.agents.delete_file(file.id)
await client.agents.files.delete(file.id)

"""
Sample output:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import os

from azure.ai.projects.models import OpenAIFile, VectorStore
from azure.ai.agents.models import VectorStore
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings
Expand All @@ -28,15 +28,15 @@
model:
id: ${AzureAI:ChatModelId}
connection:
connection_string: ${AzureAI:ConnectionString}
connection_string: ${AzureAI:Endpoint}
tools:
- type: file_search
options:
vector_store_ids:
- ${AzureAI:VectorStoreId}
"""

settings = AzureAIAgentSettings() # ChatModelId & ConnectionString come from .env/env vars
settings = AzureAIAgentSettings() # ChatModelId & Endpoint come from .env/env vars


async def main():
Expand All @@ -52,10 +52,8 @@ async def main():
"employees.pdf",
)
# Upload the pdf file to the agent service
file: OpenAIFile = await client.agents.upload_file_and_poll(file_path=pdf_file_path, purpose="assistants")
vector_store: VectorStore = await client.agents.create_vector_store_and_poll(
file_ids=[file.id], name="my_vectorstore"
)
file = await client.agents.files.upload_and_poll(file_path=pdf_file_path, purpose="assistants")
vector_store: VectorStore = await client.agents.vector_stores.create(file_ids=[file.id], name="my_vectorstore")

try:
# Create the AzureAI Agent from the YAML spec
Expand All @@ -82,8 +80,8 @@ async def main():
finally:
# Cleanup: Delete the agent, vector store, and file
await client.agents.delete_agent(agent.id)
await client.agents.delete_vector_store(vector_store.id)
await client.agents.delete_file(file.id)
await client.agents.vector_stores.delete(vector_store.id)
await client.agents.files.delete(file.id)

"""
Sample output:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ def get_item_price(
return "$9.99"


# Function spec

settings = AzureAIAgentSettings() # The Spec's ChatModelId & ConnectionString come from .env/env vars


async def main():
async with (
DefaultAzureCredential() as creds,
Expand All @@ -59,7 +54,7 @@ async def main():
file_path,
plugins=[MenuPlugin()],
client=client,
settings=settings,
settings=AzureAIAgentSettings(), # The Spec's ChatModelId & Endpoint come from .env/env vars
)

# Create the agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
model:
id: ${AzureAI:ChatModelId}
connection:
connection_string: ${AzureAI:ConnectionString}
connection_string: ${AzureAI:Endpoint}
options:
temperature: 0.4
tools:
Expand Down Expand Up @@ -153,7 +153,7 @@
schemes: {}
"""

settings = AzureAIAgentSettings() # ChatModelId & ConnectionString come from .env/env vars
settings = AzureAIAgentSettings() # ChatModelId & Endpoint come from .env/env vars


async def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import os

from azure.ai.projects.models import CodeInterpreterTool, FilePurpose
from azure.ai.agents.models import CodeInterpreterTool, FilePurpose
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
Expand All @@ -22,10 +22,7 @@ async def main() -> None:

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
csv_file_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))),
Expand All @@ -34,7 +31,7 @@ async def main() -> None:
"sales.csv",
)

file = await client.agents.upload_file_and_poll(file_path=csv_file_path, purpose=FilePurpose.AGENTS)
file = await client.agents.files.upload_and_poll(file_path=csv_file_path, purpose=FilePurpose.AGENTS)

code_interpreter = CodeInterpreterTool(file_ids=[file.id])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ async def main() -> None:

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
AGENT_NAME = "Host"
AGENT_INSTRUCTIONS = "Answer questions about the menu."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ async def main() -> None:

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
# Create agent definition
agent_definition = await client.agents.create_agent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ async def invoke_agent_with_template(template_str: str, template_format: str, de

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
# Create agent definition
agent_definition = await client.agents.create_agent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ async def main() -> None:

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
AGENT_NAME = "Host"
AGENT_INSTRUCTIONS = "Answer questions about the menu."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
from enum import Enum

from azure.ai.projects.models import (
from azure.ai.agents.models import (
ResponseFormatJsonSchema,
ResponseFormatJsonSchemaType,
)
Expand Down Expand Up @@ -38,10 +38,7 @@ async def main():
ai_agent_settings = AzureAIAgentSettings()
async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
# Create the agent definition
agent_definition = await client.agents.create_agent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio

from azure.ai.projects.models import TruncationObject
from azure.ai.agents.models import TruncationObject
from azure.identity.aio import DefaultAzureCredential

from semantic_kernel.agents import (
Expand All @@ -28,10 +28,7 @@ async def main() -> None:

async with (
DefaultAzureCredential() as creds,
AzureAIAgent.create_client(
credential=creds,
conn_str=ai_agent_settings.project_connection_string.get_secret_value(),
) as client,
AzureAIAgent.create_client(credential=creds, endpoint=ai_agent_settings.endpoint) as client,
):
# Create the agent definition
agent_definition = await client.agents.create_agent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ instructions: Use the provided functions to answer questions about the menu.
model:
id: ${AzureAI:ChatModelId}
connection:
connection_string: ${AzureAI:ConnectionString}
connection_string: ${AzureAI:Endpoint}
options:
temperature: 0.4
tools:
Expand Down
Loading
Loading