Skip to content

adding blueprints draft #42034

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

"""
DESCRIPTION:
This sample demonstrates how to use basic agent operations from
the Azure Agents service using a synchronous client, including
working with blueprints.

USAGE:
python sample_agents_blueprints.py

Before running the sample:

pip install azure-ai-projects azure-ai-agents azure-identity

Set these environment variables with your own values:
1) PROJECT_ENDPOINT - The Azure AI Project endpoint, as found in the Overview
page of your Azure AI Foundry portal.
2) MODEL_DEPLOYMENT_NAME - The deployment name of the AI model, as found under the "Name" column in
the "Models + endpoints" tab in your Azure AI Foundry project.
"""

import os, time
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
from azure.ai.agents.models import ListSortOrder, RunStatus

project_client = AIProjectClient(
endpoint=os.environ["PROJECT_ENDPOINT"],
credential=DefaultAzureCredential(),
)

with project_client:
agents_client = project_client.agents

# List available blueprints (latest versions)
blueprints = project_client.agent_blueprints.list_latest()
print("Available blueprints:")
for blueprint in blueprints:
print(f" - ID: {blueprint.id}, Name: {blueprint.name}, Version: {blueprint.version}")
print(f" Display Name: {blueprint.display_name}")
print(f" Description: {blueprint.description}")

# Convert to list to check if empty and access first item
blueprints_list = list(blueprints)

if not blueprints_list:
print("No blueprints available. Creating agent without blueprint.")
selected_blueprint = None
else:
# Select the first blueprint
selected_blueprint = blueprints_list[0]
print(f"Selected blueprint: {selected_blueprint.display_name} (Name: {selected_blueprint.name}, Version: {selected_blueprint.version})")

if selected_blueprint:
# Create agent with blueprint metadata
agent = agents_client.create_agent(
model=os.environ["MODEL_DEPLOYMENT_NAME"],
name="my-blueprint-agent",
metadata={"blueprintId": selected_blueprint.id}
)
print(f"Created agent from blueprint, agent ID: {agent.id}")
else:
# Create agent without blueprint
agent = agents_client.create_agent(
model=os.environ["MODEL_DEPLOYMENT_NAME"],
name="my-agent",
instructions="You are helpful agent",
)
print(f"Created agent without blueprint, agent ID: {agent.id}")

thread = agents_client.threads.create()
print(f"Created thread, thread ID: {thread.id}")

# List all threads for the agent
threads = agents_client.threads.list()

message = agents_client.messages.create(thread_id=thread.id, role="user", content="Hello, tell me a joke")
print(f"Created message, message ID: {message.id}")

run = agents_client.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)

if run.status != RunStatus.COMPLETED:
print(f"Run did not complete successfully.")

agents_client.delete_agent(agent.id)
print("Deleted agent")

messages = agents_client.messages.list(thread_id=thread.id, order=ListSortOrder.ASCENDING)
for msg in messages:
if msg.text_messages:
last_text = msg.text_messages[-1]
print(f"{msg.role}: {last_text.text.value}")
33 changes: 32 additions & 1 deletion sdk/ai/azure-ai-projects/apiview-properties.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
{
"CrossLanguagePackageId": "Azure.AI.Projects",
"CrossLanguageDefinitionId": {
"azure.ai.projects.models.AgentBlueprint": "Azure.AI.Projects.AgentBlueprint",
"azure.ai.projects.models.AgentBlueprintCatalogInformation": "Azure.AI.Projects.AgentBlueprintCatalogInformation",
"azure.ai.projects.models.AgentEvaluation": "Azure.AI.Projects.AgentEvaluation",
"azure.ai.projects.models.AgentEvaluationRedactionConfiguration": "Azure.AI.Projects.AgentEvaluationRedactionConfiguration",
"azure.ai.projects.models.AgentEvaluationRequest": "Azure.AI.Projects.AgentEvaluationRequest",
"azure.ai.projects.models.AgentEvaluationResult": "Azure.AI.Projects.AgentEvaluationResult",
"azure.ai.projects.models.AgentEvaluationSamplingConfiguration": "Azure.AI.Projects.AgentEvaluationSamplingConfiguration",
"azure.ai.projects.models.AgentImplementationDetails": "Azure.AI.Projects.AgentImplementationDetails",
"azure.ai.projects.models.BaseCredentials": "Azure.AI.Projects.BaseCredentials",
"azure.ai.projects.models.ApiKeyCredentials": "Azure.AI.Projects.ApiKeyCredentials",
"azure.ai.projects.models.AssetCredentialResponse": "Azure.AI.Projects.AssetCredentialResponse",
"azure.ai.projects.models.Index": "Azure.AI.Projects.Index",
"azure.ai.projects.models.AzureAISearchIndex": "Azure.AI.Projects.AzureAISearchIndex",
"azure.ai.projects.models.TargetConfig": "Azure.AI.Projects.TargetConfig",
"azure.ai.projects.models.AzureOpenAIModelConfiguration": "Azure.AI.Projects.AzureOpenAIModelConfiguration",
"azure.ai.projects.models.BaseAgentDependency": "Azure.AI.Projects.BaseAgentDependency",
"azure.ai.projects.models.BaseParameterDefinition": "Azure.AI.Projects.BaseParameterDefinition",
"azure.ai.projects.models.BaseParameterValue": "Azure.AI.Projects.BaseParameterValue",
"azure.ai.projects.models.BlobReference": "Azure.AI.Projects.BlobReference",
"azure.ai.projects.models.Connection": "Azure.AI.Projects.Connection",
"azure.ai.projects.models.ConnectionParameterDefinition": "Azure.AI.Projects.ConnectionParameterDefinition",
"azure.ai.projects.models.ConnectionParameterValue": "Azure.AI.Projects.ConnectionParameterValue",
"azure.ai.projects.models.CosmosDBIndex": "Azure.AI.Projects.CosmosDBIndex",
"azure.ai.projects.models.CustomCredential": "Azure.AI.Projects.CustomCredential",
"azure.ai.projects.models.DatasetVersion": "Azure.AI.Projects.DatasetVersion",
Expand All @@ -29,14 +37,21 @@
"azure.ai.projects.models.InputData": "Azure.AI.Projects.InputData",
"azure.ai.projects.models.InputDataset": "Azure.AI.Projects.InputDataset",
"azure.ai.projects.models.ManagedAzureAISearchIndex": "Azure.AI.Projects.ManagedAzureAISearchIndex",
"azure.ai.projects.models.ModelDependency": "Azure.AI.Projects.ModelDependency",
"azure.ai.projects.models.ModelDeployment": "Azure.AI.Projects.ModelDeployment",
"azure.ai.projects.models.NoAuthenticationCredentials": "Azure.AI.Projects.NoAuthenticationCredentials",
"azure.ai.projects.models.PendingUploadRequest": "Azure.AI.Projects.PendingUploadRequest",
"azure.ai.projects.models.PendingUploadResponse": "Azure.AI.Projects.PendingUploadResponse",
"azure.ai.projects.models.RedTeam": "Azure.AI.Projects.RedTeam",
"azure.ai.projects.models.SasCredential": "Azure.AI.Projects.SasCredential",
"azure.ai.projects.models.SASCredentials": "Azure.AI.Projects.SASCredentials",
"azure.ai.projects.models.ScaffoldRequest": "Azure.AI.Projects.ScaffoldRequest",
"azure.ai.projects.models.ScaffoldResponse": "Azure.AI.Projects.ScaffoldResponse",
"azure.ai.projects.models.Sku": "Azure.AI.Projects.Sku",
"azure.ai.projects.models.StringParameterDefinition": "Azure.AI.Projects.StringParameterDefinition",
"azure.ai.projects.models.StringParameterValue": "Azure.AI.Projects.StringParameterValue",
"azure.ai.projects.models.SystemData": "Azure.AI.Projects.SystemData",
"azure.ai.projects.models.ToolDependency": "Azure.AI.Projects.ToolDependency",
"azure.ai.projects.models.ConnectionType": "Azure.AI.Projects.ConnectionType",
"azure.ai.projects.models.CredentialType": "Azure.AI.Projects.CredentialType",
"azure.ai.projects.models.DatasetType": "Azure.AI.Projects.DatasetType",
Expand All @@ -55,6 +70,10 @@
"azure.ai.projects.aio.operations.EvaluationsOperations.create": "Azure.AI.Projects.Evaluations.create",
"azure.ai.projects.operations.EvaluationsOperations.create_agent_evaluation": "Azure.AI.Projects.Evaluations.createAgentEvaluation",
"azure.ai.projects.aio.operations.EvaluationsOperations.create_agent_evaluation": "Azure.AI.Projects.Evaluations.createAgentEvaluation",
"azure.ai.projects.operations.EvaluationsOperations.cancel": "Azure.AI.Projects.Evaluations.cancel",
"azure.ai.projects.aio.operations.EvaluationsOperations.cancel": "Azure.AI.Projects.Evaluations.cancel",
"azure.ai.projects.operations.EvaluationsOperations.delete": "Azure.AI.Projects.Evaluations.delete",
"azure.ai.projects.aio.operations.EvaluationsOperations.delete": "Azure.AI.Projects.Evaluations.delete",
"azure.ai.projects.operations.DatasetsOperations.list_versions": "Azure.AI.Projects.Datasets.listVersions",
"azure.ai.projects.aio.operations.DatasetsOperations.list_versions": "Azure.AI.Projects.Datasets.listVersions",
"azure.ai.projects.operations.DatasetsOperations.list": "Azure.AI.Projects.Datasets.listLatest",
Expand Down Expand Up @@ -88,6 +107,18 @@
"azure.ai.projects.operations.RedTeamsOperations.list": "Azure.AI.Projects.RedTeams.list",
"azure.ai.projects.aio.operations.RedTeamsOperations.list": "Azure.AI.Projects.RedTeams.list",
"azure.ai.projects.operations.RedTeamsOperations.create": "Azure.AI.Projects.RedTeams.create",
"azure.ai.projects.aio.operations.RedTeamsOperations.create": "Azure.AI.Projects.RedTeams.create"
"azure.ai.projects.aio.operations.RedTeamsOperations.create": "Azure.AI.Projects.RedTeams.create",
"azure.ai.projects.operations.AgentBlueprintsOperations.list_versions": "Azure.AI.Projects.AgentBlueprints.listVersions",
"azure.ai.projects.aio.operations.AgentBlueprintsOperations.list_versions": "Azure.AI.Projects.AgentBlueprints.listVersions",
"azure.ai.projects.operations.AgentBlueprintsOperations.list_latest": "Azure.AI.Projects.AgentBlueprints.listLatest",
"azure.ai.projects.aio.operations.AgentBlueprintsOperations.list_latest": "Azure.AI.Projects.AgentBlueprints.listLatest",
"azure.ai.projects.operations.AgentBlueprintsOperations.get_version": "Azure.AI.Projects.AgentBlueprints.getVersion",
"azure.ai.projects.aio.operations.AgentBlueprintsOperations.get_version": "Azure.AI.Projects.AgentBlueprints.getVersion",
"azure.ai.projects.operations.AgentBlueprintsOperations.delete_version": "Azure.AI.Projects.AgentBlueprints.deleteVersion",
"azure.ai.projects.aio.operations.AgentBlueprintsOperations.delete_version": "Azure.AI.Projects.AgentBlueprints.deleteVersion",
"azure.ai.projects.operations.AgentBlueprintsOperations.create_or_update_version": "Azure.AI.Projects.AgentBlueprints.createOrUpdateVersion",
"azure.ai.projects.aio.operations.AgentBlueprintsOperations.create_or_update_version": "Azure.AI.Projects.AgentBlueprints.createOrUpdateVersion",
"azure.ai.projects.operations.AgentBlueprintsOperations.scaffold_blueprint": "Azure.AI.Projects.AgentBlueprints.scaffoldBlueprint",
"azure.ai.projects.aio.operations.AgentBlueprintsOperations.scaffold_blueprint": "Azure.AI.Projects.AgentBlueprints.scaffoldBlueprint"
}
}
8 changes: 7 additions & 1 deletion sdk/ai/azure-ai-projects/azure/ai/projects/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ._configuration import AIProjectClientConfiguration
from ._utils.serialization import Deserializer, Serializer
from .operations import (
AgentBlueprintsOperations,
ConnectionsOperations,
DatasetsOperations,
DeploymentsOperations,
Expand All @@ -29,7 +30,7 @@
from azure.core.credentials import TokenCredential


class AIProjectClient:
class AIProjectClient: # pylint: disable=too-many-instance-attributes
"""AIProjectClient.

:ivar connections: ConnectionsOperations operations
Expand All @@ -44,6 +45,8 @@ class AIProjectClient:
:vartype deployments: azure.ai.projects.operations.DeploymentsOperations
:ivar red_teams: RedTeamsOperations operations
:vartype red_teams: azure.ai.projects.operations.RedTeamsOperations
:ivar agent_blueprints: AgentBlueprintsOperations operations
:vartype agent_blueprints: azure.ai.projects.operations.AgentBlueprintsOperations
:param endpoint: Project endpoint. In the form
"https://<your-ai-services-account-name>.services.ai.azure.com/api/projects/_project"
if your Foundry Hub has only one Project, or to use the default Project in your Hub. Or in the
Expand Down Expand Up @@ -92,6 +95,9 @@ def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any)
self.indexes = IndexesOperations(self._client, self._config, self._serialize, self._deserialize)
self.deployments = DeploymentsOperations(self._client, self._config, self._serialize, self._deserialize)
self.red_teams = RedTeamsOperations(self._client, self._config, self._serialize, self._deserialize)
self.agent_blueprints = AgentBlueprintsOperations(
self._client, self._config, self._serialize, self._deserialize
)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.
Expand Down
20 changes: 18 additions & 2 deletions sdk/ai/azure-ai-projects/azure/ai/projects/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
def api_version_validation(**kwargs):
params_added_on = kwargs.pop("params_added_on", {})
method_added_on = kwargs.pop("method_added_on", "")
api_versions_list = kwargs.pop("api_versions_list", [])

def _index_with_default(value: str, default: int = -1) -> int:
"""Get the index of value in lst, or return default if not found.

:param value: The value to search for in the api_versions_list.
:type value: str
:param default: The default value to return if the value is not found.
:type default: int
:return: The index of the value in the list, or the default value if not found.
:rtype: int
"""
try:
return api_versions_list.index(value)
except ValueError:
return default

def decorator(func):
@functools.wraps(func)
Expand All @@ -21,7 +37,7 @@ def wrapper(*args, **kwargs):
except AttributeError:
return func(*args, **kwargs)

if method_added_on > client_api_version:
if _index_with_default(method_added_on) > _index_with_default(client_api_version):
raise ValueError(
f"'{func.__name__}' is not available in API version "
f"{client_api_version}. Pass service API version {method_added_on} or newer to your client."
Expand All @@ -31,7 +47,7 @@ def wrapper(*args, **kwargs):
parameter: api_version
for api_version, parameters in params_added_on.items()
for parameter in parameters
if parameter in kwargs and api_version > client_api_version
if parameter in kwargs and _index_with_default(api_version) > _index_with_default(client_api_version)
}
if unsupported:
raise ValueError(
Expand Down
8 changes: 7 additions & 1 deletion sdk/ai/azure-ai-projects/azure/ai/projects/aio/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .._utils.serialization import Deserializer, Serializer
from ._configuration import AIProjectClientConfiguration
from .operations import (
AgentBlueprintsOperations,
ConnectionsOperations,
DatasetsOperations,
DeploymentsOperations,
Expand All @@ -29,7 +30,7 @@
from azure.core.credentials_async import AsyncTokenCredential


class AIProjectClient:
class AIProjectClient: # pylint: disable=too-many-instance-attributes
"""AIProjectClient.

:ivar connections: ConnectionsOperations operations
Expand All @@ -44,6 +45,8 @@ class AIProjectClient:
:vartype deployments: azure.ai.projects.aio.operations.DeploymentsOperations
:ivar red_teams: RedTeamsOperations operations
:vartype red_teams: azure.ai.projects.aio.operations.RedTeamsOperations
:ivar agent_blueprints: AgentBlueprintsOperations operations
:vartype agent_blueprints: azure.ai.projects.aio.operations.AgentBlueprintsOperations
:param endpoint: Project endpoint. In the form
"https://<your-ai-services-account-name>.services.ai.azure.com/api/projects/_project"
if your Foundry Hub has only one Project, or to use the default Project in your Hub. Or in the
Expand Down Expand Up @@ -92,6 +95,9 @@ def __init__(self, endpoint: str, credential: "AsyncTokenCredential", **kwargs:
self.indexes = IndexesOperations(self._client, self._config, self._serialize, self._deserialize)
self.deployments = DeploymentsOperations(self._client, self._config, self._serialize, self._deserialize)
self.red_teams = RedTeamsOperations(self._client, self._config, self._serialize, self._deserialize)
self.agent_blueprints = AgentBlueprintsOperations(
self._client, self._config, self._serialize, self._deserialize
)

def send_request(
self, request: HttpRequest, *, stream: bool = False, **kwargs: Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ._operations import IndexesOperations # type: ignore
from ._operations import DeploymentsOperations # type: ignore
from ._operations import RedTeamsOperations # type: ignore
from ._operations import AgentBlueprintsOperations # type: ignore

from ._patch import __all__ as _patch_all
from ._patch import *
Expand All @@ -30,6 +31,7 @@
"IndexesOperations",
"DeploymentsOperations",
"RedTeamsOperations",
"AgentBlueprintsOperations",
]
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
_patch_sdk()
Loading
Loading