mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Standardize model selection on model (#4999)
* Refactor Anthropic model option and provider clients Rename the Anthropic client model option from model_id to model, add provider-specific Anthropic wrappers for Foundry, Bedrock, and Vertex, and expose them through the Anthropic, Foundry, Amazon, and Google namespaces. Update core option handling, docs, samples, and tests accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Anthropic skills sample typing Cast the Anthropic beta client to Any in the skills sample so the pre-commit sample pyright check no longer fails on beta skills and files endpoints that are not exposed by the current SDK stubs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * undo sample mypy * Retry CI after transient external failures Retrigger PR validation after an unrelated Copilot review workflow SAML failure and a transient external tau2 git fetch failure in the Windows Python test setup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address review feedback on model option merging Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address Anthropic compatibility review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * moved all to `model` * fixes for azure ai search * Python: standardize remaining sample env var names Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Python: fix foundry-local pyright compatibility Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * updated env vars in cicd --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
95550dd0dc
commit
6acab3d1d6
@@ -51,7 +51,7 @@ Depending on the selected client, set the appropriate environment variables:
|
||||
|
||||
**For Azure OpenAI clients (`azure_openai_responses` and `azure_openai_chat_completion`):**
|
||||
- `AZURE_OPENAI_ENDPOINT`: Your Azure OpenAI endpoint
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`: The Azure OpenAI deployment used by the sample
|
||||
- `AZURE_OPENAI_MODEL`: The Azure OpenAI deployment used by the sample
|
||||
- `AZURE_OPENAI_API_VERSION` (optional): Azure OpenAI API version override
|
||||
- `AZURE_OPENAI_API_KEY` (optional): Azure OpenAI API key if you are not using `AzureCliCredential`
|
||||
|
||||
@@ -66,13 +66,13 @@ Depending on the selected client, set the appropriate environment variables:
|
||||
|
||||
**For Anthropic client (`anthropic`):**
|
||||
- `ANTHROPIC_API_KEY`: Your Anthropic API key
|
||||
- `ANTHROPIC_CHAT_MODEL_ID`: The Anthropic model ID (for example, `claude-sonnet-4-5`)
|
||||
- `ANTHROPIC_CHAT_MODEL`: The Anthropic model to use (for example, `claude-sonnet-4-5`)
|
||||
|
||||
**For Ollama client (`ollama`):**
|
||||
- `OLLAMA_HOST`: Ollama server URL (defaults to `http://localhost:11434` if unset)
|
||||
- `OLLAMA_MODEL_ID`: Ollama model name (for example, `mistral`, `qwen2.5:8b`)
|
||||
- `OLLAMA_MODEL`: Ollama model name (for example, `mistral`, `qwen2.5:8b`)
|
||||
|
||||
**For Bedrock client (`bedrock`):**
|
||||
- `BEDROCK_CHAT_MODEL_ID`: Bedrock model ID (for example, `anthropic.claude-3-5-sonnet-20240620-v1:0`)
|
||||
- `BEDROCK_CHAT_MODEL`: Bedrock model ID (for example, `anthropic.claude-3-5-sonnet-20240620-v1:0`)
|
||||
- `BEDROCK_REGION`: AWS region (defaults to `us-east-1` if unset)
|
||||
- AWS credentials via standard environment variables (for example, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)
|
||||
|
||||
@@ -24,7 +24,7 @@ async def main() -> None:
|
||||
Creates a task for the chat request, waits briefly, then cancels it to show proper cleanup.
|
||||
|
||||
Configuration:
|
||||
- OpenAI model ID: Use "model_id" parameter or "OPENAI_MODEL" environment variable
|
||||
- OpenAI model ID: Use "model" parameter or "OPENAI_MODEL" environment variable
|
||||
- OpenAI API key: Use "api_key" parameter or "OPENAI_API_KEY" environment variable
|
||||
"""
|
||||
client = FoundryChatClient(credential=AzureCliCredential())
|
||||
|
||||
@@ -102,7 +102,7 @@ class EchoingChatClient(BaseChatClient[OptionsT]):
|
||||
|
||||
response = ChatResponse(
|
||||
messages=[response_message],
|
||||
model_id="echo-model-v1",
|
||||
model="echo-model-v1",
|
||||
response_id=f"echo-resp-{random.randint(1000, 9999)}",
|
||||
)
|
||||
|
||||
@@ -120,7 +120,7 @@ class EchoingChatClient(BaseChatClient[OptionsT]):
|
||||
contents=[Content.from_text(char)],
|
||||
role="assistant",
|
||||
response_id=f"echo-stream-resp-{random.randint(1000, 9999)}",
|
||||
model_id="echo-model-v1",
|
||||
model="echo-model-v1",
|
||||
)
|
||||
await asyncio.sleep(stream_delay_seconds)
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@ Key components:
|
||||
class TiktokenTokenizer(TokenizerProtocol):
|
||||
"""TokenizerProtocol implementation backed by tiktoken's o200k_base (gpt-4.1 and up default) encoding."""
|
||||
|
||||
def __init__(self, *, encoding_name: str = "o200k_base", model_name: str | None = None) -> None:
|
||||
if model_name is not None:
|
||||
self._encoding = tiktoken.encoding_for_model(model_name)
|
||||
def __init__(self, *, encoding_name: str = "o200k_base", model: str | None = None) -> None:
|
||||
if model is not None:
|
||||
self._encoding = tiktoken.encoding_for_model(model)
|
||||
else:
|
||||
self._encoding: Any = tiktoken.get_encoding(encoding_name)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ rather than chat history. The memory store is deleted at the end of the run.
|
||||
Prerequisites:
|
||||
1. Set FOUNDRY_PROJECT_ENDPOINT environment variable
|
||||
2. Set FOUNDRY_MODEL for the chat/responses model
|
||||
3. Set AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME for the embedding model
|
||||
3. Set AZURE_OPENAI_EMBEDDING_MODEL for the embedding model
|
||||
4. Deploy both a chat model (e.g. gpt-4) and an embedding model (e.g. text-embedding-3-small)
|
||||
"""
|
||||
load_dotenv()
|
||||
@@ -55,7 +55,7 @@ async def main() -> None:
|
||||
)
|
||||
memory_store_definition = MemoryStoreDefaultDefinition(
|
||||
chat_model=os.environ["FOUNDRY_MODEL"],
|
||||
embedding_model=os.environ["AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME"],
|
||||
embedding_model=os.environ["AZURE_OPENAI_EMBEDDING_MODEL"],
|
||||
options=options,
|
||||
)
|
||||
print(f"Creating memory store '{memory_store_name}'...")
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ Prerequisites:
|
||||
- AZURE_SEARCH_INDEX_NAME: Your search index name
|
||||
- FOUNDRY_PROJECT_ENDPOINT: Your Azure AI Foundry project endpoint
|
||||
- FOUNDRY_MODEL: Your model deployment name (e.g., "gpt-4o")
|
||||
- AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: (Optional) Your Azure OpenAI embedding deployment for hybrid search
|
||||
- AZURE_OPENAI_EMBEDDING_MODEL: (Optional) Your Azure OpenAI embedding deployment for hybrid search
|
||||
- AZURE_OPENAI_ENDPOINT: (Optional) Your Azure OpenAI resource URL, required if using Azure OpenAI embeddings
|
||||
"""
|
||||
|
||||
@@ -56,7 +56,7 @@ async def main() -> None:
|
||||
project_endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"]
|
||||
model_deployment = os.environ.get("FOUNDRY_MODEL", "gpt-4o")
|
||||
openai_endpoint = os.environ.get("AZURE_OPENAI_ENDPOINT")
|
||||
embedding_deployment = os.environ.get("AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME")
|
||||
embedding_deployment = os.environ.get("AZURE_OPENAI_EMBEDDING_MODEL")
|
||||
|
||||
embedding_client = None
|
||||
if openai_endpoint and embedding_deployment:
|
||||
|
||||
@@ -159,7 +159,7 @@ agent_factory = AgentFactory(
|
||||
"MyProvider": {
|
||||
"package": "my_custom_module",
|
||||
"name": "MyCustomChatClient",
|
||||
"model_id_field": "model_id",
|
||||
"model_field": "model",
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -176,7 +176,7 @@ agent = agent_factory.create_agent_from_yaml_path(Path("custom_provider.yaml"))
|
||||
This allows you to extend the declarative framework with custom chat client implementations. The mapping requires:
|
||||
- **package**: The Python package/module to import from
|
||||
- **name**: The class name of your SupportsChatGetResponse implementation
|
||||
- **model_id_field**: The constructor parameter name that accepts the value of the `model.id` field from the YAML
|
||||
- **model_field**: The constructor parameter name that accepts the value of the `model.id` field from the YAML
|
||||
|
||||
You can reference your custom provider using either `Provider.ApiType` format or just `Provider` in your YAML configuration, as long as it matches the registered mapping.
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ FOUNDRY_MODEL=gpt-4o
|
||||
|
||||
# Azure OpenAI workflow sample
|
||||
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
|
||||
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME=gpt-4o
|
||||
AZURE_OPENAI_RESPONSES_MODEL=gpt-4o
|
||||
# Optional fallback env name also supported by workflow_with_agents/workflow.py:
|
||||
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
|
||||
AZURE_OPENAI_MODEL=gpt-4o
|
||||
# Optional if you need to override the default API version:
|
||||
AZURE_OPENAI_API_VERSION=2024-10-21
|
||||
|
||||
@@ -94,7 +94,7 @@ workflow_name/
|
||||
| Sample | What it demonstrates | Required keys / auth |
|
||||
| ------ | -------------------- | -------------------- |
|
||||
| [**workflow_declarative/**](workflow_declarative/) | A YAML-defined workflow loaded through `WorkflowFactory`, with nested age-based branching and no model client code. | None |
|
||||
| [**workflow_with_agents/**](workflow_with_agents/) | A content review workflow that uses agents as executors and routes based on structured review output (`Writer -> Reviewer -> Editor/Publisher -> Summarizer`). | `AZURE_OPENAI_ENDPOINT`, plus `AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME` or `AZURE_OPENAI_DEPLOYMENT_NAME`; Azure CLI auth via `az login`; `AZURE_OPENAI_API_VERSION` is optional |
|
||||
| [**workflow_with_agents/**](workflow_with_agents/) | A content review workflow that uses agents as executors and routes based on structured review output (`Writer -> Reviewer -> Editor/Publisher -> Summarizer`). | `AZURE_OPENAI_ENDPOINT`, plus `AZURE_OPENAI_RESPONSES_MODEL` or `AZURE_OPENAI_MODEL`; Azure CLI auth via `az login`; `AZURE_OPENAI_API_VERSION` is optional |
|
||||
| [**workflow_spam/**](workflow_spam/) | A multi-step spam detection workflow with human-in-the-loop approval, branching for spam vs. legitimate messages, and a final reporting step. | None |
|
||||
| [**workflow_fanout/**](workflow_fanout/) | A larger fan-out/fan-in data processing workflow with parallel validation, multiple transformations, QA, aggregation, and demo failure toggles. | None |
|
||||
|
||||
@@ -130,8 +130,8 @@ export FOUNDRY_MODEL="gpt-4o"
|
||||
|
||||
# Azure OpenAI workflow_with_agents sample
|
||||
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com"
|
||||
export AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o"
|
||||
export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o"
|
||||
export AZURE_OPENAI_RESPONSES_MODEL="gpt-4o"
|
||||
export AZURE_OPENAI_MODEL="gpt-4o"
|
||||
|
||||
az login
|
||||
```
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# This sample uses Azure CLI auth, so run `az login` before starting DevUI.
|
||||
|
||||
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
|
||||
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME=gpt-4o
|
||||
AZURE_OPENAI_RESPONSES_MODEL=gpt-4o
|
||||
# Optional fallback env name also supported by the client:
|
||||
# AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
|
||||
# AZURE_OPENAI_MODEL=gpt-4o
|
||||
# Optional if you need to override the default API version:
|
||||
AZURE_OPENAI_API_VERSION=2024-10-21
|
||||
|
||||
@@ -65,7 +65,7 @@ def is_approved(message: Any) -> bool:
|
||||
|
||||
# Create Azure OpenAI Responses chat client
|
||||
client = OpenAIChatClient(
|
||||
model=os.environ.get("AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME") or os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME"),
|
||||
model=os.environ.get("AZURE_OPENAI_RESPONSES_MODEL") or os.environ.get("AZURE_OPENAI_MODEL"),
|
||||
azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
|
||||
api_version=os.environ.get("AZURE_OPENAI_API_VERSION"),
|
||||
credential=AzureCliCredential(),
|
||||
|
||||
@@ -31,9 +31,9 @@ Prerequisites:
|
||||
- AZURE_AI_INFERENCE_ENDPOINT: Your Azure AI model inference endpoint URL, for instance:
|
||||
https://<apim-instance>.azure-api.net/<foundry-instance>/models
|
||||
- AZURE_AI_INFERENCE_API_KEY: Your API key
|
||||
- AZURE_AI_INFERENCE_EMBEDDING_MODEL_ID: The text embedding model name
|
||||
- AZURE_AI_INFERENCE_EMBEDDING_MODEL: The text embedding model name
|
||||
(e.g. "text-embedding-3-small")
|
||||
- AZURE_AI_INFERENCE_IMAGE_EMBEDDING_MODEL_ID: The image embedding model name
|
||||
- AZURE_AI_INFERENCE_IMAGE_EMBEDDING_MODEL: The image embedding model name
|
||||
(e.g. "Cohere-embed-v3-english")
|
||||
"""
|
||||
|
||||
@@ -49,7 +49,7 @@ async def main() -> None:
|
||||
result = await client.get_embeddings([image_content])
|
||||
print(f"Image embedding dimensions: {result[0].dimensions}")
|
||||
print(f"First 5 values: {result[0].vector[:5]}")
|
||||
print(f"Model: {result[0].model_id}")
|
||||
print(f"Model: {result[0].model}")
|
||||
print(f"Usage: {result.usage}")
|
||||
print()
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ from dotenv import load_dotenv
|
||||
Prerequisites:
|
||||
Set the following environment variables or add them to a local ``.env`` file:
|
||||
- ``AZURE_OPENAI_ENDPOINT``: Your Azure OpenAI endpoint URL
|
||||
- ``AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME``: The embedding deployment name
|
||||
- ``AZURE_OPENAI_EMBEDDING_MODEL``: The embedding deployment name
|
||||
- ``AZURE_OPENAI_API_VERSION``: Optional API version override
|
||||
|
||||
Sign in with ``az login`` before running the sample.
|
||||
@@ -27,7 +27,7 @@ async def main() -> None:
|
||||
"""Generate embeddings with Azure OpenAI."""
|
||||
async with AzureCliCredential() as credential:
|
||||
client = OpenAIEmbeddingClient(
|
||||
model=os.getenv("AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME"),
|
||||
model=os.getenv("AZURE_OPENAI_EMBEDDING_MODEL"),
|
||||
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
|
||||
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
|
||||
credential=credential,
|
||||
|
||||
@@ -41,7 +41,7 @@ def response_matches_expected(response: str, expected_output: str) -> float:
|
||||
async def main() -> None:
|
||||
client = FoundryChatClient(
|
||||
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
|
||||
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
|
||||
model=os.environ.get("FOUNDRY_MODEL", "gpt-4o"),
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ Set the following environment variables before running the examples:
|
||||
**For Azure OpenAI:**
|
||||
|
||||
- `AZURE_OPENAI_ENDPOINT`: Your Azure OpenAI endpoint
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`: The name of your Azure OpenAI chat model deployment
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`: The name of your Azure OpenAI responses model deployment
|
||||
- `AZURE_OPENAI_MODEL`: The name of your Azure OpenAI chat model deployment
|
||||
- `AZURE_OPENAI_MODEL`: The name of your Azure OpenAI responses model deployment
|
||||
|
||||
Optionally for Azure OpenAI:
|
||||
- `AZURE_OPENAI_API_VERSION`: The API version to use (default is `2024-10-21`)
|
||||
|
||||
@@ -23,7 +23,7 @@ async def test_image() -> None:
|
||||
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
|
||||
# authentication option. Requires AZURE_OPENAI_ENDPOINT and FOUNDRY_MODEL
|
||||
# environment variables to be set.
|
||||
# Alternatively, you can pass deployment_name explicitly:
|
||||
# Alternatively, you can pass model explicitly:
|
||||
# client = FoundryChatClient(credential=AzureCliCredential(), model="your-deployment-name")
|
||||
client = FoundryChatClient(credential=AzureCliCredential())
|
||||
image_uri = create_sample_image()
|
||||
|
||||
@@ -32,7 +32,7 @@ async def test_image() -> None:
|
||||
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
|
||||
# authentication option. Requires AZURE_OPENAI_ENDPOINT and FOUNDRY_MODEL
|
||||
# environment variables to be set.
|
||||
# Alternatively, you can pass deployment_name explicitly:
|
||||
# Alternatively, you can pass model explicitly:
|
||||
# client = FoundryChatClient(credential=AzureCliCredential(), model="your-deployment-name")
|
||||
client = FoundryChatClient(credential=AzureCliCredential())
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Bedrock Examples
|
||||
|
||||
This folder contains examples demonstrating how to use AWS Bedrock models with the Agent Framework. The sample
|
||||
uses `BEDROCK_CHAT_MODEL_ID`, `BEDROCK_REGION`, and AWS credentials (`AWS_ACCESS_KEY_ID`,
|
||||
uses `BEDROCK_CHAT_MODEL`, `BEDROCK_REGION`, and AWS credentials (`AWS_ACCESS_KEY_ID`,
|
||||
`AWS_SECRET_ACCESS_KEY`, optional `AWS_SESSION_TOKEN`).
|
||||
|
||||
## Examples
|
||||
@@ -12,6 +12,6 @@ uses `BEDROCK_CHAT_MODEL_ID`, `BEDROCK_REGION`, and AWS credentials (`AWS_ACCESS
|
||||
|
||||
## Environment Variables
|
||||
|
||||
- `BEDROCK_CHAT_MODEL_ID`: Bedrock model ID (for example, `anthropic.claude-3-5-sonnet-20240620-v1:0`)
|
||||
- `BEDROCK_CHAT_MODEL`: Bedrock model ID (for example, `anthropic.claude-3-5-sonnet-20240620-v1:0`)
|
||||
- `BEDROCK_REGION`: AWS region (defaults to `us-east-1` if unset)
|
||||
- AWS credentials via standard variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, optional `AWS_SESSION_TOKEN`)
|
||||
|
||||
@@ -17,7 +17,7 @@ Bedrock Chat Client Example
|
||||
This sample demonstrates using `BedrockChatClient` with an agent and a simple tool.
|
||||
|
||||
Environment variables used:
|
||||
- `BEDROCK_CHAT_MODEL_ID`
|
||||
- `BEDROCK_CHAT_MODEL`
|
||||
- `BEDROCK_REGION` (defaults to `us-east-1` if unset)
|
||||
- AWS credentials via standard variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`,
|
||||
optional `AWS_SESSION_TOKEN`)
|
||||
|
||||
@@ -28,14 +28,14 @@ This folder contains examples demonstrating how to use Anthropic's Claude models
|
||||
### Anthropic Client
|
||||
|
||||
- `ANTHROPIC_API_KEY`: Your Anthropic API key (get one from [Anthropic Console](https://console.anthropic.com/))
|
||||
- `ANTHROPIC_CHAT_MODEL_ID`: The Claude model to use (e.g., `claude-haiku-4-5`, `claude-sonnet-4-5-20250929`)
|
||||
- `ANTHROPIC_CHAT_MODEL`: The Claude model to use (e.g., `claude-haiku-4-5`, `claude-sonnet-4-5-20250929`)
|
||||
|
||||
### Foundry
|
||||
|
||||
- `ANTHROPIC_FOUNDRY_API_KEY`: Your Foundry Anthropic API key
|
||||
- `ANTHROPIC_FOUNDRY_RESOURCE`: Your Foundry resource name (for example `my-foundry-resource`)
|
||||
- `ANTHROPIC_FOUNDRY_BASE_URL`: Optional full Foundry Anthropic base URL alternative to `ANTHROPIC_FOUNDRY_RESOURCE`
|
||||
- `ANTHROPIC_CHAT_MODEL_ID`: The Claude model to use in Foundry (e.g., `claude-haiku-4-5`)
|
||||
- `ANTHROPIC_CHAT_MODEL`: The Claude model to use in Foundry (e.g., `claude-haiku-4-5`)
|
||||
|
||||
### Claude Agent
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ async def non_streaming_example() -> None:
|
||||
print("=== Non-streaming Response Example ===")
|
||||
|
||||
agent = Agent(
|
||||
client=AnthropicClient(model_id="claude-sonnet-4-5-20250929"),
|
||||
client=AnthropicClient(model="claude-sonnet-4-5-20250929"),
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
@@ -52,7 +52,7 @@ async def streaming_example() -> None:
|
||||
print("=== Streaming Response Example ===")
|
||||
|
||||
agent = Agent(
|
||||
client=AnthropicClient(model_id="claude-sonnet-4-5-20250929"),
|
||||
client=AnthropicClient(model="claude-sonnet-4-5-20250929"),
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
import asyncio
|
||||
|
||||
from agent_framework import Agent
|
||||
from agent_framework.anthropic import AnthropicClient
|
||||
from anthropic import AsyncAnthropicFoundry
|
||||
from agent_framework.foundry import AnthropicFoundryClient
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
@@ -27,14 +26,14 @@ To use the Foundry integration ensure you have the following environment variabl
|
||||
- ANTHROPIC_FOUNDRY_BASE_URL
|
||||
Optional alternative to ANTHROPIC_FOUNDRY_RESOURCE. Should be something like
|
||||
https://<your-resource-name>.services.ai.azure.com/anthropic/
|
||||
- ANTHROPIC_CHAT_MODEL_ID
|
||||
- ANTHROPIC_CHAT_MODEL
|
||||
Should be something like claude-haiku-4-5
|
||||
"""
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
"""Example of streaming response (get results as they are generated)."""
|
||||
client = AnthropicClient(anthropic_client=AsyncAnthropicFoundry())
|
||||
client = AnthropicFoundryClient()
|
||||
|
||||
# Create MCP tool configuration using instance method
|
||||
mcp_tool = client.get_mcp_tool(
|
||||
|
||||
@@ -29,7 +29,7 @@ async def main() -> None:
|
||||
client = AnthropicClient[AnthropicChatOptions](additional_beta_flags=["skills-2025-10-02"])
|
||||
|
||||
# List Anthropic-managed Skills
|
||||
skills = await client.anthropic_client.beta.skills.list(source="anthropic", betas=["skills-2025-10-02"])
|
||||
skills = await client.anthropic_client.beta.skills.list(source="anthropic", betas=["skills-2025-10-02"]) # type: ignore
|
||||
for skill in skills.data:
|
||||
print(f"{skill.source}: {skill.id} (version: {skill.latest_version})")
|
||||
|
||||
@@ -81,7 +81,7 @@ async def main() -> None:
|
||||
# Since I'm using the pptx skill, the files will be PowerPoint presentations
|
||||
print("Generated files:")
|
||||
for idx, file in enumerate(files):
|
||||
file_content = await client.anthropic_client.beta.files.download(
|
||||
file_content = await client.anthropic_client.beta.files.download( # type: ignore
|
||||
file_id=file.file_id, betas=["files-api-2025-04-14"]
|
||||
)
|
||||
with open(Path(__file__).parent / f"python_programming-{idx}.pptx", "wb") as f:
|
||||
|
||||
@@ -26,7 +26,7 @@ This folder contains Azure-backed samples for the generic OpenAI clients in
|
||||
Set these before running the Azure provider samples:
|
||||
|
||||
- `AZURE_OPENAI_ENDPOINT`
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`
|
||||
- `AZURE_OPENAI_MODEL`
|
||||
|
||||
Optionally, you can also set:
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ async def non_streaming_example() -> None:
|
||||
|
||||
agent = Agent(
|
||||
client=OpenAIChatCompletionClient(
|
||||
model=os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"),
|
||||
model=os.getenv("AZURE_OPENAI_MODEL"),
|
||||
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
|
||||
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
|
||||
credential=AzureCliCredential(),
|
||||
@@ -60,7 +60,7 @@ async def streaming_example() -> None:
|
||||
|
||||
agent = Agent(
|
||||
client=OpenAIChatCompletionClient(
|
||||
model=os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"),
|
||||
model=os.getenv("AZURE_OPENAI_MODEL"),
|
||||
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
|
||||
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
|
||||
credential=AzureCliCredential(),
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ async def main() -> None:
|
||||
# authentication option.
|
||||
agent = Agent(
|
||||
client=OpenAIChatCompletionClient(
|
||||
model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
|
||||
model=os.environ["AZURE_OPENAI_MODEL"],
|
||||
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
|
||||
credential=AzureCliCredential(),
|
||||
),
|
||||
|
||||
@@ -38,7 +38,7 @@ async def non_streaming_example() -> None:
|
||||
|
||||
agent = Agent(
|
||||
client=OpenAIChatClient(
|
||||
model=os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"),
|
||||
model=os.getenv("AZURE_OPENAI_MODEL"),
|
||||
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
|
||||
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
|
||||
credential=AzureCliCredential(),
|
||||
@@ -60,7 +60,7 @@ async def streaming_example() -> None:
|
||||
|
||||
agent = Agent(
|
||||
client=OpenAIChatClient(
|
||||
model=os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"),
|
||||
model=os.getenv("AZURE_OPENAI_MODEL"),
|
||||
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
|
||||
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
|
||||
credential=AzureCliCredential(),
|
||||
|
||||
@@ -45,4 +45,4 @@ This folder contains Azure AI Foundry and Foundry Local samples for Agent Framew
|
||||
|
||||
### Environment Variables
|
||||
|
||||
- `FOUNDRY_LOCAL_MODEL_ID`: Optional model alias/ID to use by default when `model_id` is not passed to `FoundryLocalClient`.
|
||||
- `FOUNDRY_LOCAL_MODEL`: Optional model alias/ID to use by default when `model` is not passed to `FoundryLocalClient`.
|
||||
|
||||
@@ -40,8 +40,8 @@ Set the following environment variables:
|
||||
- `OLLAMA_HOST`: The base URL for your Ollama server (optional, defaults to `http://localhost:11434`)
|
||||
- Example: `export OLLAMA_HOST="http://localhost:11434"`
|
||||
|
||||
- `OLLAMA_MODEL_ID`: The model name to use
|
||||
- Example: `export OLLAMA_MODEL_ID="qwen2.5:8b"`
|
||||
- `OLLAMA_MODEL`: The model name to use
|
||||
- Example: `export OLLAMA_MODEL="qwen2.5:8b"`
|
||||
- Must be a model you have pulled with Ollama
|
||||
|
||||
### For OpenAI Client with Ollama (`ollama_with_openai_chat_client.py`)
|
||||
|
||||
@@ -17,7 +17,7 @@ This sample demonstrates implementing a Ollama agent with basic tool usage.
|
||||
|
||||
Ensure to install Ollama and have a model running locally before running the sample
|
||||
Not all Models support function calling, to test function calling try llama3.2 or qwen3:4b
|
||||
Set the model to use via the OLLAMA_MODEL_ID environment variable or modify the code below.
|
||||
Set the model to use via the OLLAMA_MODEL environment variable or modify the code below.
|
||||
https://ollama.com/
|
||||
|
||||
"""
|
||||
|
||||
@@ -16,7 +16,7 @@ This sample demonstrates implementing a Ollama agent with reasoning.
|
||||
|
||||
Ensure to install Ollama and have a model running locally before running the sample
|
||||
Not all Models support reasoning, to test reasoning try qwen3:8b
|
||||
Set the model to use via the OLLAMA_MODEL_ID environment variable or modify the code below.
|
||||
Set the model to use via the OLLAMA_MODEL environment variable or modify the code below.
|
||||
https://ollama.com/
|
||||
|
||||
"""
|
||||
|
||||
@@ -17,7 +17,7 @@ This sample demonstrates using the native Ollama Chat Client directly.
|
||||
|
||||
Ensure to install Ollama and have a model running locally before running the sample.
|
||||
Not all Models support function calling, to test function calling try llama3.2
|
||||
Set the model to use via the OLLAMA_MODEL_ID environment variable or modify the code below.
|
||||
Set the model to use via the OLLAMA_MODEL environment variable or modify the code below.
|
||||
https://ollama.com/
|
||||
|
||||
"""
|
||||
|
||||
@@ -16,7 +16,7 @@ This sample demonstrates implementing a Ollama agent with multimodal input capab
|
||||
|
||||
Ensure to install Ollama and have a model running locally before running the sample
|
||||
Not all Models support multimodal input, to test multimodal input try gemma3:4b
|
||||
Set the model to use via the OLLAMA_MODEL_ID environment variable or modify the code below.
|
||||
Set the model to use via the OLLAMA_MODEL environment variable or modify the code below.
|
||||
https://ollama.com/
|
||||
|
||||
"""
|
||||
|
||||
@@ -28,7 +28,7 @@ code_defined_skill/
|
||||
Set the required environment variables in a `.env` file (see `python/.env.example`):
|
||||
|
||||
- `FOUNDRY_PROJECT_ENDPOINT`: Your Azure AI Foundry project endpoint
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`: The name of your model deployment (defaults to `gpt-4o-mini`)
|
||||
- `AZURE_OPENAI_MODEL`: The name of your model deployment (defaults to `gpt-4o-mini`)
|
||||
|
||||
### Authentication
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ file_based_skill/
|
||||
Set the required environment variables in a `.env` file (see `python/.env.example`):
|
||||
|
||||
- `FOUNDRY_PROJECT_ENDPOINT`: Your Azure AI Foundry project endpoint
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`: The name of your model deployment (defaults to `gpt-4o-mini`)
|
||||
- `AZURE_OPENAI_MODEL`: The name of your model deployment (defaults to `gpt-4o-mini`)
|
||||
|
||||
### Authentication
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ Set environment variables (or create a `.env` file):
|
||||
|
||||
```
|
||||
FOUNDRY_PROJECT_ENDPOINT=https://your-project.openai.azure.com/
|
||||
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o-mini
|
||||
AZURE_OPENAI_MODEL=gpt-4o-mini
|
||||
```
|
||||
|
||||
Authenticate with Azure CLI:
|
||||
|
||||
@@ -29,7 +29,7 @@ When `require_script_approval=True` is set, the agent pauses before executing an
|
||||
Set the required environment variables in a `.env` file (see `python/.env.example`):
|
||||
|
||||
- `FOUNDRY_PROJECT_ENDPOINT`: Your Azure AI Foundry project endpoint
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`: The name of your model deployment (defaults to `gpt-4o-mini`)
|
||||
- `AZURE_OPENAI_MODEL`: The name of your model deployment (defaults to `gpt-4o-mini`)
|
||||
|
||||
### Authentication
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ async def demo_anthropic_chat_client() -> None:
|
||||
print("\n=== Anthropic ChatClient with TypedDict Options ===\n")
|
||||
|
||||
# Create Anthropic client
|
||||
client = AnthropicClient(model_id="claude-sonnet-4-5-20250929")
|
||||
client = AnthropicClient(model="claude-sonnet-4-5-20250929")
|
||||
|
||||
# Standard options work great:
|
||||
response = await client.get_response(
|
||||
@@ -53,14 +53,14 @@ async def demo_anthropic_chat_client() -> None:
|
||||
)
|
||||
|
||||
print(f"Anthropic Response: {response.text}")
|
||||
print(f"Model used: {response.model_id}")
|
||||
print(f"Model used: {response.model}")
|
||||
|
||||
|
||||
async def demo_anthropic_agent() -> None:
|
||||
"""Demonstrate Agent with Anthropic client and typed options."""
|
||||
print("\n=== Agent with Anthropic and Typed Options ===\n")
|
||||
|
||||
client = AnthropicClient(model_id="claude-sonnet-4-5-20250929")
|
||||
client = AnthropicClient(model="claude-sonnet-4-5-20250929")
|
||||
|
||||
# Create a typed agent for Anthropic - IDE knows Anthropic-specific options!
|
||||
agent = Agent(
|
||||
@@ -129,7 +129,7 @@ async def demo_openai_chat_client_reasoning_models() -> None:
|
||||
)
|
||||
|
||||
print(f"OpenAI Response: {response.text}")
|
||||
print(f"Model used: {response.model_id}")
|
||||
print(f"Model used: {response.model}")
|
||||
|
||||
|
||||
async def demo_openai_agent() -> None:
|
||||
|
||||
@@ -67,12 +67,12 @@ def main() -> None:
|
||||
|
||||
# Validate environment
|
||||
project_endpoint = os.getenv("FOUNDRY_PROJECT_ENDPOINT")
|
||||
deployment_name = os.getenv("FOUNDRY_MODEL")
|
||||
model = os.getenv("FOUNDRY_MODEL")
|
||||
|
||||
if not project_endpoint:
|
||||
print("Error: FOUNDRY_PROJECT_ENDPOINT environment variable is not set.")
|
||||
sys.exit(1)
|
||||
if not deployment_name:
|
||||
if not model:
|
||||
print("Error: FOUNDRY_MODEL environment variable is not set.")
|
||||
sys.exit(1)
|
||||
|
||||
@@ -80,7 +80,7 @@ def main() -> None:
|
||||
credential = AzureCliCredential()
|
||||
client = FoundryChatClient(
|
||||
project_endpoint=project_endpoint,
|
||||
model=deployment_name,
|
||||
model=model,
|
||||
credential=credential,
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Components used in this sample:
|
||||
- AgentFunctionApp to register multiple agents and expose dedicated HTTP endpoints.
|
||||
- Custom tool functions to demonstrate tool invocation from different agents.
|
||||
|
||||
Prerequisites: set `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_DEPLOYMENT_NAME`, and sign in with Azure CLI before starting the Functions host."""
|
||||
Prerequisites: set `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_MODEL`, and sign in with Azure CLI before starting the Functions host."""
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
@@ -10,4 +10,4 @@ TASKHUB_NAME=default
|
||||
|
||||
# Azure OpenAI Configuration
|
||||
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
|
||||
AZURE_OPENAI_DEPLOYMENT_NAME=your-deployment-name
|
||||
AZURE_OPENAI_MODEL=your-deployment-name
|
||||
|
||||
@@ -99,7 +99,7 @@ The sample can run locally without Azure Functions infrastructure using DevUI:
|
||||
```
|
||||
|
||||
2. Configure `.env` with your Azure OpenAI credentials (`AZURE_OPENAI_ENDPOINT` and
|
||||
`AZURE_OPENAI_DEPLOYMENT_NAME`)
|
||||
`AZURE_OPENAI_MODEL`)
|
||||
|
||||
3. Install dependencies:
|
||||
```bash
|
||||
|
||||
@@ -21,7 +21,7 @@ Key architectural points:
|
||||
- Mixed agent/executor fan-outs execute concurrently
|
||||
|
||||
Prerequisites:
|
||||
- Configure `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_DEPLOYMENT_NAME`
|
||||
- Configure `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_MODEL`
|
||||
- Sign in with Azure CLI (`az login`) for `AzureCliCredential`
|
||||
- Ensure Azurite and the Durable Task Scheduler emulator are running
|
||||
"""
|
||||
@@ -362,7 +362,7 @@ def _create_workflow() -> Workflow:
|
||||
credential = AzureCliCredential()
|
||||
|
||||
chat_client = OpenAIChatCompletionClient(
|
||||
model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
|
||||
model=os.environ["AZURE_OPENAI_MODEL"],
|
||||
api_key=get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default"),
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -6,6 +6,6 @@
|
||||
"DURABLE_TASK_SCHEDULER_CONNECTION_STRING": "Endpoint=http://localhost:8080;TaskHub=default;Authentication=None",
|
||||
"TASKHUB_NAME": "default",
|
||||
"AZURE_OPENAI_ENDPOINT": "<AZURE_OPENAI_ENDPOINT>",
|
||||
"AZURE_OPENAI_DEPLOYMENT_NAME": "<AZURE_OPENAI_DEPLOYMENT_NAME>"
|
||||
"AZURE_OPENAI_MODEL": "<AZURE_OPENAI_MODEL>"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ each with their own specialized capabilities and tools.
|
||||
|
||||
Prerequisites:
|
||||
- The worker must be running with both agents registered
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME when running the worker
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_MODEL when running the worker
|
||||
- Sign in with Azure CLI for AzureCliCredential authentication
|
||||
- Durable Task Scheduler must be running
|
||||
"""
|
||||
|
||||
@@ -5,7 +5,7 @@ This sample demonstrates running both the worker and client in a single process
|
||||
for multiple agents with different tools. The worker registers two agents
|
||||
(WeatherAgent and MathAgent), each with their own specialized capabilities.
|
||||
Prerequisites:
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_MODEL
|
||||
- Sign in with Azure CLI for AzureCliCredential authentication
|
||||
- Durable Task Scheduler must be running (e.g., using Docker)
|
||||
To run this sample:
|
||||
|
||||
@@ -7,7 +7,7 @@ with their own specialized tools. This demonstrates how to host multiple agents
|
||||
with different capabilities in a single worker process.
|
||||
|
||||
Prerequisites:
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_MODEL
|
||||
- Sign in with Azure CLI for AzureCliCredential authentication
|
||||
- Start a Durable Task Scheduler (e.g., using Docker)
|
||||
"""
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ See the [README.md](../README.md) file in the parent directory for more informat
|
||||
This sample uses Azure OpenAI credentials:
|
||||
|
||||
- `AZURE_OPENAI_ENDPOINT`
|
||||
- `AZURE_OPENAI_DEPLOYMENT_NAME`
|
||||
- `AZURE_OPENAI_MODEL`
|
||||
|
||||
## Running the Sample
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ that uses conditional logic to either handle spam emails or draft professional r
|
||||
|
||||
Prerequisites:
|
||||
- The worker must be running with both agents, orchestration, and activities registered
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_MODEL
|
||||
- Sign in with Azure CLI for AzureCliCredential authentication
|
||||
- Durable Task Scheduler must be running
|
||||
"""
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ The orchestration branches based on spam detection results, calling different
|
||||
activity functions to handle spam or send legitimate email responses.
|
||||
|
||||
Prerequisites:
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_MODEL
|
||||
- Sign in with Azure CLI for AzureCliCredential authentication
|
||||
- Durable Task Scheduler must be running (e.g., using Docker)
|
||||
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ orchestration function that routes execution based on spam detection results. Ac
|
||||
handle side effects (spam handling and email sending).
|
||||
|
||||
Prerequisites:
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_MODEL
|
||||
- Sign in with Azure CLI for AzureCliCredential authentication
|
||||
- Start a Durable Task Scheduler (e.g., using Docker)
|
||||
"""
|
||||
@@ -69,7 +69,7 @@ def create_spam_agent() -> "Agent":
|
||||
"""
|
||||
return Agent(
|
||||
client=OpenAIChatCompletionClient(
|
||||
model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
|
||||
model=os.environ["AZURE_OPENAI_MODEL"],
|
||||
api_key=get_async_bearer_token_provider(
|
||||
AsyncAzureCliCredential(), "https://cognitiveservices.azure.com/.default"
|
||||
),
|
||||
@@ -87,7 +87,7 @@ def create_email_agent() -> "Agent":
|
||||
"""
|
||||
return Agent(
|
||||
client=OpenAIChatCompletionClient(
|
||||
model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
|
||||
model=os.environ["AZURE_OPENAI_MODEL"],
|
||||
api_key=get_async_bearer_token_provider(
|
||||
AsyncAzureCliCredential(), "https://cognitiveservices.azure.com/.default"
|
||||
),
|
||||
|
||||
@@ -177,7 +177,7 @@ pip install agent-framework-chatkit fastapi uvicorn azure-identity
|
||||
```bash
|
||||
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
|
||||
export AZURE_OPENAI_API_VERSION="2024-06-01"
|
||||
export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o"
|
||||
export AZURE_OPENAI_MODEL="gpt-4o"
|
||||
```
|
||||
|
||||
3. **Authenticate with Azure:**
|
||||
|
||||
@@ -10,7 +10,7 @@ See ``evaluate_tool_calls_sample.py`` for tool-call accuracy evaluation.
|
||||
|
||||
Prerequisites:
|
||||
- An Azure AI Foundry project with a deployed model
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME in .env
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL in .env
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
@@ -48,7 +48,7 @@ async def main() -> None:
|
||||
# 1. Set up the chat client
|
||||
chat_client = FoundryChatClient(
|
||||
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
|
||||
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
|
||||
model=os.environ.get("FOUNDRY_MODEL", "gpt-4o"),
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ a different aspect of agent behavior:
|
||||
|
||||
Prerequisites:
|
||||
- An Azure AI Foundry project with a deployed model
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME in .env
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL in .env
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -94,7 +94,7 @@ def print_split(item: EvalItem, split: ConversationSplit = ConversationSplit.LAS
|
||||
async def main() -> None:
|
||||
chat_client = FoundryChatClient(
|
||||
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
|
||||
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
|
||||
model=os.environ.get("FOUNDRY_MODEL", "gpt-4o"),
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ by using ``FoundryEvals.evaluate()`` with ``TOOL_CALL_ACCURACY``.
|
||||
|
||||
Prerequisites:
|
||||
- An Azure AI Foundry project with a deployed model
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME in .env
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL in .env
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -39,7 +39,7 @@ def get_flight_price(origin: str, destination: str) -> str:
|
||||
async def main() -> None:
|
||||
chat_client = FoundryChatClient(
|
||||
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
|
||||
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
|
||||
model=os.environ.get("FOUNDRY_MODEL", "gpt-4o"),
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ Prerequisites:
|
||||
- An Azure AI Foundry project with a deployed model
|
||||
- Response IDs from prior agent runs (for Pattern 1)
|
||||
- OTel traces exported to App Insights (for Pattern 2)
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME in .env
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL in .env
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -30,7 +30,7 @@ async def main() -> None:
|
||||
# 1. Set up the chat client
|
||||
chat_client = FoundryChatClient(
|
||||
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
|
||||
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
|
||||
model=os.environ.get("FOUNDRY_MODEL", "gpt-4o"),
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ breakdown in sub_results so you can identify which agent is underperforming.
|
||||
|
||||
Prerequisites:
|
||||
- An Azure AI Foundry project with a deployed model
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME in .env
|
||||
- Set FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL in .env
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -46,7 +46,7 @@ async def main() -> None:
|
||||
# 1. Set up the chat client
|
||||
client = FoundryChatClient(
|
||||
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
|
||||
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
|
||||
model=os.environ.get("FOUNDRY_MODEL", "gpt-4o"),
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Azure OpenAI Configuration (for the agent being tested)
|
||||
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
|
||||
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
|
||||
AZURE_OPENAI_MODEL=gpt-4o
|
||||
# AZURE_OPENAI_API_KEY=your-api-key-here
|
||||
|
||||
# Azure AI Project Configuration (for red teaming)
|
||||
|
||||
@@ -43,7 +43,7 @@ Create a `.env` file in this directory or set these environment variables:
|
||||
```bash
|
||||
# Azure OpenAI (for the agent being tested)
|
||||
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
|
||||
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
|
||||
AZURE_OPENAI_MODEL=gpt-4o
|
||||
# AZURE_OPENAI_API_KEY is optional if using Azure CLI authentication
|
||||
|
||||
# Azure AI Project (for red teaming)
|
||||
|
||||
@@ -51,7 +51,7 @@ async def main() -> None:
|
||||
credential = AzureCliCredential()
|
||||
# Create the agent
|
||||
# Constructor automatically reads from environment variables:
|
||||
# AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_DEPLOYMENT_NAME, AZURE_OPENAI_API_KEY
|
||||
# AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_MODEL, AZURE_OPENAI_API_KEY
|
||||
agent = Agent(
|
||||
client=FoundryChatClient(credential=credential),
|
||||
name="FinancialAdvisor",
|
||||
|
||||
@@ -76,7 +76,7 @@ Example `.env` for Azure OpenAI samples:
|
||||
|
||||
```dotenv
|
||||
AZURE_OPENAI_ENDPOINT=https://<your-openai-resource>.openai.azure.com/
|
||||
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4.1
|
||||
AZURE_OPENAI_MODEL=gpt-4.1
|
||||
```
|
||||
|
||||
Example `.env` for Foundry project samples:
|
||||
|
||||
@@ -22,7 +22,7 @@ template:
|
||||
environment_variables:
|
||||
- name: AZURE_OPENAI_ENDPOINT
|
||||
value: ${AZURE_OPENAI_ENDPOINT}
|
||||
- name: AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- name: AZURE_OPENAI_MODEL
|
||||
value: "{{chat}}"
|
||||
resources:
|
||||
- kind: model
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# IMPORTANT: Never commit .env to version control - add it to .gitignore
|
||||
PROJECT_ENDPOINT=
|
||||
MODEL_DEPLOYMENT_NAME=
|
||||
FOUNDRY_PROJECT_ENDPOINT=
|
||||
FOUNDRY_MODEL=
|
||||
@@ -59,24 +59,24 @@ Before running this sample, ensure you have:
|
||||
|
||||
Set the following environment variables (matching `agent.yaml`):
|
||||
|
||||
- `PROJECT_ENDPOINT` - Your Microsoft Foundry project endpoint URL (required)
|
||||
- `MODEL_DEPLOYMENT_NAME` - The deployment name for your chat model (defaults to `gpt-4.1-mini`)
|
||||
- `FOUNDRY_PROJECT_ENDPOINT` - Your Microsoft Foundry project endpoint URL (required)
|
||||
- `FOUNDRY_MODEL` - The deployment name for your chat model (defaults to `gpt-4.1-mini`)
|
||||
|
||||
This sample loads environment variables from a local `.env` file if present.
|
||||
|
||||
Create a `.env` file in this directory with the following content:
|
||||
|
||||
```
|
||||
PROJECT_ENDPOINT=https://<your-resource>.services.ai.azure.com/api/projects/<your-project>
|
||||
MODEL_DEPLOYMENT_NAME=gpt-4.1-mini
|
||||
FOUNDRY_PROJECT_ENDPOINT=https://<your-resource>.services.ai.azure.com/api/projects/<your-project>
|
||||
FOUNDRY_MODEL=gpt-4.1-mini
|
||||
```
|
||||
|
||||
Or set them via PowerShell:
|
||||
|
||||
```powershell
|
||||
# Replace with your actual values
|
||||
$env:PROJECT_ENDPOINT="https://<your-resource>.services.ai.azure.com/api/projects/<your-project>"
|
||||
$env:MODEL_DEPLOYMENT_NAME="gpt-4.1-mini"
|
||||
$env:FOUNDRY_PROJECT_ENDPOINT="https://<your-resource>.services.ai.azure.com/api/projects/<your-project>"
|
||||
$env:FOUNDRY_MODEL="gpt-4.1-mini"
|
||||
```
|
||||
|
||||
### Running the Sample
|
||||
|
||||
@@ -21,7 +21,7 @@ protocols:
|
||||
- protocol: responses
|
||||
version: v1
|
||||
environment_variables:
|
||||
- name: PROJECT_ENDPOINT
|
||||
value: ${PROJECT_ENDPOINT}
|
||||
- name: MODEL_DEPLOYMENT_NAME
|
||||
value: ${MODEL_DEPLOYMENT_NAME}
|
||||
- name: FOUNDRY_PROJECT_ENDPOINT
|
||||
value: ${FOUNDRY_PROJECT_ENDPOINT}
|
||||
- name: FOUNDRY_MODEL
|
||||
value: ${FOUNDRY_MODEL}
|
||||
@@ -18,10 +18,8 @@ from azure.identity.aio import AzureCliCredential, ManagedIdentityCredential
|
||||
|
||||
# Configure these for your Foundry project
|
||||
# Read the explicit variables present in the .env file
|
||||
PROJECT_ENDPOINT = os.getenv("PROJECT_ENDPOINT") # e.g., "https://<project>.services.ai.azure.com"
|
||||
MODEL_DEPLOYMENT_NAME = os.getenv(
|
||||
"MODEL_DEPLOYMENT_NAME", "gpt-4.1-mini"
|
||||
) # Your model deployment name e.g., "gpt-4.1-mini"
|
||||
FOUNDRY_PROJECT_ENDPOINT = os.getenv("FOUNDRY_PROJECT_ENDPOINT") # e.g., "https://<project>.services.ai.azure.com"
|
||||
FOUNDRY_MODEL = os.getenv("FOUNDRY_MODEL", "gpt-4.1-mini") # Your model deployment name e.g., "gpt-4.1-mini"
|
||||
|
||||
|
||||
# Simulated hotel data for Seattle
|
||||
@@ -116,8 +114,8 @@ async def main():
|
||||
"""Main function to run the agent as a web server."""
|
||||
async with get_credential() as credential:
|
||||
client = FoundryChatClient(
|
||||
project_endpoint=PROJECT_ENDPOINT,
|
||||
model=MODEL_DEPLOYMENT_NAME,
|
||||
project_endpoint=FOUNDRY_PROJECT_ENDPOINT,
|
||||
model=FOUNDRY_MODEL,
|
||||
credential=credential,
|
||||
)
|
||||
agent = Agent(
|
||||
|
||||
@@ -25,7 +25,7 @@ template:
|
||||
environment_variables:
|
||||
- name: AZURE_OPENAI_ENDPOINT
|
||||
value: ${AZURE_OPENAI_ENDPOINT}
|
||||
- name: AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- name: AZURE_OPENAI_MODEL
|
||||
value: "{{chat}}"
|
||||
resources:
|
||||
- kind: model
|
||||
|
||||
@@ -20,7 +20,7 @@ template:
|
||||
environment_variables:
|
||||
- name: AZURE_OPENAI_ENDPOINT
|
||||
value: ${AZURE_OPENAI_ENDPOINT}
|
||||
- name: AZURE_OPENAI_DEPLOYMENT_NAME
|
||||
- name: AZURE_OPENAI_MODEL
|
||||
value: "{{chat}}"
|
||||
resources:
|
||||
- kind: model
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
# IMPORTANT: Never commit .env to version control - add it to .gitignore
|
||||
PROJECT_ENDPOINT=
|
||||
MODEL_DEPLOYMENT_NAME=
|
||||
FOUNDRY_PROJECT_ENDPOINT=
|
||||
FOUNDRY_MODEL=
|
||||
+6
-6
@@ -56,24 +56,24 @@ Before running this sample, ensure you have:
|
||||
|
||||
Set the following environment variables (matching `agent.yaml`):
|
||||
|
||||
- `PROJECT_ENDPOINT` - Your Microsoft Foundry project endpoint URL (required)
|
||||
- `MODEL_DEPLOYMENT_NAME` - The deployment name for your chat model (defaults to `gpt-4.1-mini`)
|
||||
- `FOUNDRY_PROJECT_ENDPOINT` - Your Microsoft Foundry project endpoint URL (required)
|
||||
- `FOUNDRY_MODEL` - The deployment name for your chat model (defaults to `gpt-4.1-mini`)
|
||||
|
||||
This sample loads environment variables from a local `.env` file if present.
|
||||
|
||||
Create a `.env` file in this directory with the following content:
|
||||
|
||||
```
|
||||
PROJECT_ENDPOINT=https://<your-resource>.services.ai.azure.com/api/projects/<your-project>
|
||||
MODEL_DEPLOYMENT_NAME=gpt-4.1-mini
|
||||
FOUNDRY_PROJECT_ENDPOINT=https://<your-resource>.services.ai.azure.com/api/projects/<your-project>
|
||||
FOUNDRY_MODEL=gpt-4.1-mini
|
||||
```
|
||||
|
||||
Or set them via PowerShell:
|
||||
|
||||
```powershell
|
||||
# Replace with your actual values
|
||||
$env:PROJECT_ENDPOINT="https://<your-resource>.services.ai.azure.com/api/projects/<your-project>"
|
||||
$env:MODEL_DEPLOYMENT_NAME="gpt-4.1-mini"
|
||||
$env:FOUNDRY_PROJECT_ENDPOINT="https://<your-resource>.services.ai.azure.com/api/projects/<your-project>"
|
||||
$env:FOUNDRY_MODEL="gpt-4.1-mini"
|
||||
```
|
||||
|
||||
### Running the Sample
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ protocols:
|
||||
- protocol: responses
|
||||
version: v1
|
||||
environment_variables:
|
||||
- name: PROJECT_ENDPOINT
|
||||
value: ${PROJECT_ENDPOINT}
|
||||
- name: MODEL_DEPLOYMENT_NAME
|
||||
value: ${MODEL_DEPLOYMENT_NAME}
|
||||
- name: FOUNDRY_PROJECT_ENDPOINT
|
||||
value: ${FOUNDRY_PROJECT_ENDPOINT}
|
||||
- name: FOUNDRY_MODEL
|
||||
value: ${FOUNDRY_MODEL}
|
||||
+7
-9
@@ -14,12 +14,10 @@ load_dotenv(override=True)
|
||||
|
||||
# Configure these for your Foundry project
|
||||
# Read the explicit variables present in the .env file
|
||||
PROJECT_ENDPOINT = os.getenv(
|
||||
"PROJECT_ENDPOINT"
|
||||
FOUNDRY_PROJECT_ENDPOINT = os.getenv(
|
||||
"FOUNDRY_PROJECT_ENDPOINT"
|
||||
) # e.g., "https://<project>.services.ai.azure.com/api/projects/<project-name>"
|
||||
MODEL_DEPLOYMENT_NAME = os.getenv(
|
||||
"MODEL_DEPLOYMENT_NAME", "gpt-4.1-mini"
|
||||
) # Your model deployment name e.g., "gpt-4.1-mini"
|
||||
FOUNDRY_MODEL = os.getenv("FOUNDRY_MODEL", "gpt-4.1-mini") # Your model deployment name e.g., "gpt-4.1-mini"
|
||||
|
||||
|
||||
def get_credential():
|
||||
@@ -31,8 +29,8 @@ def get_credential():
|
||||
async def create_agents():
|
||||
async with get_credential() as credential:
|
||||
client = FoundryChatClient(
|
||||
project_endpoint=PROJECT_ENDPOINT,
|
||||
model=MODEL_DEPLOYMENT_NAME,
|
||||
project_endpoint=FOUNDRY_PROJECT_ENDPOINT,
|
||||
model=FOUNDRY_MODEL,
|
||||
credential=credential,
|
||||
)
|
||||
writer = Agent(
|
||||
@@ -60,8 +58,8 @@ async def main() -> None:
|
||||
The writer and reviewer multi-agent workflow.
|
||||
|
||||
Environment variables required:
|
||||
- PROJECT_ENDPOINT: Your Microsoft Foundry project endpoint
|
||||
- MODEL_DEPLOYMENT_NAME: Your Microsoft Foundry model deployment name
|
||||
- FOUNDRY_PROJECT_ENDPOINT: Your Microsoft Foundry project endpoint
|
||||
- FOUNDRY_MODEL: Your Microsoft Foundry model deployment name
|
||||
"""
|
||||
|
||||
async with create_agents() as (writer, reviewer):
|
||||
|
||||
@@ -18,7 +18,7 @@ This getting-started sample shows how to attach Microsoft Purview policy evaluat
|
||||
| Variable | Required | Purpose |
|
||||
|----------|----------|---------|
|
||||
| `AZURE_OPENAI_ENDPOINT` | Yes | Azure OpenAI endpoint (https://<name>.openai.azure.com) |
|
||||
| `AZURE_OPENAI_DEPLOYMENT_NAME` | Optional | Model deployment name (defaults inside SDK if omitted) |
|
||||
| `AZURE_OPENAI_MODEL` | Optional | Model deployment name (defaults inside SDK if omitted) |
|
||||
| `PURVIEW_CLIENT_APP_ID` | Yes* | Client (application) ID used for Purview authentication |
|
||||
| `PURVIEW_USE_CERT_AUTH` | Optional (`true`/`false`) | Switch between certificate and interactive auth |
|
||||
| `PURVIEW_TENANT_ID` | Yes (when cert auth on) | Tenant ID for certificate authentication |
|
||||
|
||||
@@ -12,7 +12,7 @@ Note: Caching is automatic and enabled by default.
|
||||
|
||||
Environment variables:
|
||||
- AZURE_OPENAI_ENDPOINT (required)
|
||||
- AZURE_OPENAI_DEPLOYMENT_NAME (optional, defaults to gpt-4o-mini)
|
||||
- AZURE_OPENAI_MODEL (optional, defaults to gpt-4o-mini)
|
||||
- PURVIEW_CLIENT_APP_ID (required)
|
||||
- PURVIEW_USE_CERT_AUTH (optional, set to "true" for certificate auth)
|
||||
- PURVIEW_TENANT_ID (required if certificate auth)
|
||||
@@ -143,7 +143,7 @@ async def run_with_agent_middleware() -> None:
|
||||
print("Skipping run: AZURE_OPENAI_ENDPOINT not set")
|
||||
return
|
||||
|
||||
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", "gpt-4o-mini")
|
||||
deployment = os.environ.get("AZURE_OPENAI_MODEL", "gpt-4o-mini")
|
||||
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
|
||||
client = FoundryChatClient(model=deployment, endpoint=endpoint, credential=AzureCliCredential())
|
||||
|
||||
@@ -179,7 +179,7 @@ async def run_with_chat_middleware() -> None:
|
||||
print("Skipping chat middleware run: AZURE_OPENAI_ENDPOINT not set")
|
||||
return
|
||||
|
||||
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", default="gpt-4o-mini")
|
||||
deployment = os.environ.get("AZURE_OPENAI_MODEL", default="gpt-4o-mini")
|
||||
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
|
||||
|
||||
client = FoundryChatClient(
|
||||
@@ -229,7 +229,7 @@ async def run_with_custom_cache_provider() -> None:
|
||||
print("Skipping custom cache provider run: AZURE_OPENAI_ENDPOINT not set")
|
||||
return
|
||||
|
||||
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", "gpt-4o-mini")
|
||||
deployment = os.environ.get("AZURE_OPENAI_MODEL", "gpt-4o-mini")
|
||||
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
|
||||
client = FoundryChatClient(model=deployment, endpoint=endpoint, credential=AzureCliCredential())
|
||||
|
||||
@@ -269,7 +269,7 @@ async def run_with_custom_cache_provider() -> None:
|
||||
print("Skipping default cache run: AZURE_OPENAI_ENDPOINT not set")
|
||||
return
|
||||
|
||||
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", "gpt-4o-mini")
|
||||
deployment = os.environ.get("AZURE_OPENAI_MODEL", "gpt-4o-mini")
|
||||
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
|
||||
client = FoundryChatClient(model=deployment, endpoint=endpoint, credential=AzureCliCredential())
|
||||
|
||||
|
||||
@@ -145,14 +145,14 @@ class ResearchLead(Executor):
|
||||
|
||||
|
||||
async def run_workflow_with_response_tracking(
|
||||
query: str, client: FoundryChatClient | None = None, deployment_name: str | None = None
|
||||
query: str, client: FoundryChatClient | None = None, model: str | None = None
|
||||
) -> dict:
|
||||
"""Run multi-agent workflow and track conversation IDs, response IDs, and interaction sequence.
|
||||
|
||||
Args:
|
||||
query: The user query to process through the multi-agent workflow
|
||||
client: Optional FoundryChatClient instance
|
||||
deployment_name: Optional model deployment name for the workflow agents
|
||||
model: Optional model for the workflow agents
|
||||
|
||||
Returns:
|
||||
Dictionary containing interaction sequence, conversation/response IDs, and conversation analysis
|
||||
@@ -166,7 +166,7 @@ async def run_workflow_with_response_tracking(
|
||||
)
|
||||
|
||||
async with project_client:
|
||||
client = FoundryChatClient(project_client=project_client, model=deployment_name)
|
||||
client = FoundryChatClient(project_client=project_client, model=model)
|
||||
return await _run_workflow_with_client(query, client)
|
||||
except Exception as e:
|
||||
print(f"Error during workflow execution: {e}")
|
||||
@@ -347,11 +347,11 @@ def _track_agent_ids(event, agent, response_ids, conversation_ids):
|
||||
conversation_ids[agent].append(raw.conversation_id)
|
||||
|
||||
|
||||
async def create_and_run_workflow(deployment_name: str | None = None):
|
||||
async def create_and_run_workflow(model: str | None = None):
|
||||
"""Run the workflow evaluation and display results.
|
||||
|
||||
Args:
|
||||
deployment_name: Optional model deployment name for the workflow agents
|
||||
model: Optional model for the workflow agents
|
||||
|
||||
Returns:
|
||||
Dictionary containing agents data with conversation IDs, response IDs, and query information
|
||||
@@ -365,7 +365,7 @@ async def create_and_run_workflow(deployment_name: str | None = None):
|
||||
query = example_queries[0]
|
||||
print(f"Query: {query}\n")
|
||||
|
||||
result = await run_workflow_with_response_tracking(query, model=deployment_name)
|
||||
result = await run_workflow_with_response_tracking(query, model=model)
|
||||
|
||||
# Create output data structure
|
||||
output_data = {"agents": {}, "query": result["query"], "output": result.get("output", "")}
|
||||
|
||||
@@ -46,11 +46,11 @@ def print_section(title: str):
|
||||
print(f"{'=' * 80}")
|
||||
|
||||
|
||||
async def run_workflow(deployment_name: str | None = None) -> dict[str, Any]:
|
||||
async def run_workflow(model: str | None = None) -> dict[str, Any]:
|
||||
"""Execute the multi-agent travel planning workflow.
|
||||
|
||||
Args:
|
||||
deployment_name: Optional model deployment name for the workflow agents
|
||||
model: Optional model for the workflow agents
|
||||
|
||||
Returns:
|
||||
Dictionary containing workflow data with agent response IDs
|
||||
@@ -58,7 +58,7 @@ async def run_workflow(deployment_name: str | None = None) -> dict[str, Any]:
|
||||
print("Executing multi-agent travel planning workflow...")
|
||||
print("This may take a few minutes...")
|
||||
|
||||
workflow_data = await create_and_run_workflow(model=deployment_name)
|
||||
workflow_data = await create_and_run_workflow(model=model)
|
||||
|
||||
print("Workflow execution completed")
|
||||
return workflow_data
|
||||
@@ -97,9 +97,9 @@ def fetch_agent_responses(openai_client: OpenAI, workflow_data: dict[str, Any],
|
||||
print(f" Error: {e}")
|
||||
|
||||
|
||||
def create_evaluation(openai_client: OpenAI, deployment_name: str | None = "gpt-5.2") -> EvalCreateResponse:
|
||||
def create_evaluation(openai_client: OpenAI, model: str | None = "gpt-5.2") -> EvalCreateResponse:
|
||||
"""Create evaluation with multiple evaluators."""
|
||||
deployment_name = os.environ.get("FOUNDRY_MODEL", deployment_name)
|
||||
model = os.environ.get("FOUNDRY_MODEL", model)
|
||||
data_source_config = {"type": "azure_ai_source", "scenario": "responses"}
|
||||
|
||||
testing_criteria = [
|
||||
@@ -107,25 +107,25 @@ def create_evaluation(openai_client: OpenAI, deployment_name: str | None = "gpt-
|
||||
"type": "azure_ai_evaluator",
|
||||
"name": "relevance",
|
||||
"evaluator_name": "builtin.relevance",
|
||||
"initialization_parameters": {"deployment_name": deployment_name},
|
||||
"initialization_parameters": {"deployment_name": model},
|
||||
},
|
||||
{
|
||||
"type": "azure_ai_evaluator",
|
||||
"name": "groundedness",
|
||||
"evaluator_name": "builtin.groundedness",
|
||||
"initialization_parameters": {"deployment_name": deployment_name},
|
||||
"initialization_parameters": {"deployment_name": model},
|
||||
},
|
||||
{
|
||||
"type": "azure_ai_evaluator",
|
||||
"name": "tool_call_accuracy",
|
||||
"evaluator_name": "builtin.tool_call_accuracy",
|
||||
"initialization_parameters": {"deployment_name": deployment_name},
|
||||
"initialization_parameters": {"deployment_name": model},
|
||||
},
|
||||
{
|
||||
"type": "azure_ai_evaluator",
|
||||
"name": "tool_output_utilization",
|
||||
"evaluator_name": "builtin.tool_output_utilization",
|
||||
"initialization_parameters": {"deployment_name": deployment_name},
|
||||
"initialization_parameters": {"deployment_name": model},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
+10
-10
@@ -91,11 +91,11 @@ variable.
|
||||
| package | class | env var | example value |
|
||||
| --- | --- | --- | --- |
|
||||
| `agent-framework-anthropic` | `AnthropicClient` | `ANTHROPIC_API_KEY` | `sk-ant-api03-...` |
|
||||
| `agent-framework-anthropic` | `AnthropicClient` | `ANTHROPIC_CHAT_MODEL_ID` | `claude-sonnet-4-5-20250929` |
|
||||
| `agent-framework-anthropic` | `AnthropicClient` | `ANTHROPIC_CHAT_MODEL` | `claude-sonnet-4-5-20250929` |
|
||||
| `agent-framework-azure-ai` | `AzureAIInferenceEmbeddingClient` | `AZURE_AI_INFERENCE_ENDPOINT` | `https://my-endpoint.inference.ai.azure.com` |
|
||||
| `agent-framework-azure-ai` | `AzureAIInferenceEmbeddingClient` | `AZURE_AI_INFERENCE_API_KEY` | `env-key` |
|
||||
| `agent-framework-azure-ai` | `AzureAIInferenceEmbeddingClient` | `AZURE_AI_INFERENCE_EMBEDDING_MODEL_ID` | `text-embedding-3-small` |
|
||||
| `agent-framework-azure-ai` | `AzureAIInferenceEmbeddingClient` | `AZURE_AI_INFERENCE_IMAGE_EMBEDDING_MODEL_ID` | `Cohere-embed-v3-english` |
|
||||
| `agent-framework-azure-ai` | `AzureAIInferenceEmbeddingClient` | `AZURE_AI_INFERENCE_EMBEDDING_MODEL` | `text-embedding-3-small` |
|
||||
| `agent-framework-azure-ai` | `AzureAIInferenceEmbeddingClient` | `AZURE_AI_INFERENCE_IMAGE_EMBEDDING_MODEL` | `Cohere-embed-v3-english` |
|
||||
| `agent-framework-azure-ai-search` | `AzureAISearchContextProvider` | `AZURE_SEARCH_ENDPOINT` | `https://my-search.search.windows.net` |
|
||||
| `agent-framework-azure-ai-search` | `AzureAISearchContextProvider` | `AZURE_SEARCH_API_KEY` | `search-key` |
|
||||
| `agent-framework-azure-ai-search` | `AzureAISearchContextProvider` | `AZURE_SEARCH_INDEX_NAME` | `hotels-index` |
|
||||
@@ -105,9 +105,9 @@ variable.
|
||||
| `agent-framework-azure-cosmos` | `CosmosHistoryProvider` | `AZURE_COSMOS_CONTAINER_NAME` | `messages` |
|
||||
| `agent-framework-azure-cosmos` | `CosmosHistoryProvider` | `AZURE_COSMOS_KEY` | `C2F...==` |
|
||||
| `agent-framework-bedrock` | `BedrockChatClient` | `BEDROCK_REGION` | `us-east-1` |
|
||||
| `agent-framework-bedrock` | `BedrockChatClient` | `BEDROCK_CHAT_MODEL_ID` | `anthropic.claude-3-5-sonnet-20241022-v2:0` |
|
||||
| `agent-framework-bedrock` | `BedrockChatClient` | `BEDROCK_CHAT_MODEL` | `anthropic.claude-3-5-sonnet-20241022-v2:0` |
|
||||
| `agent-framework-bedrock` | `BedrockEmbeddingClient` | `BEDROCK_REGION` | `us-east-1` |
|
||||
| `agent-framework-bedrock` | `BedrockEmbeddingClient` | `BEDROCK_EMBEDDING_MODEL_ID` | `amazon.titan-embed-text-v2:0` |
|
||||
| `agent-framework-bedrock` | `BedrockEmbeddingClient` | `BEDROCK_EMBEDDING_MODEL` | `amazon.titan-embed-text-v2:0` |
|
||||
| `agent-framework-bedrock` | `BedrockChatClient / BedrockEmbeddingClient` | `AWS_ACCESS_KEY_ID` | `AKIAIOSFODNN7EXAMPLE` |
|
||||
| `agent-framework-bedrock` | `BedrockChatClient / BedrockEmbeddingClient` | `AWS_SECRET_ACCESS_KEY` | `wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY` |
|
||||
| `agent-framework-bedrock` | `BedrockChatClient / BedrockEmbeddingClient` | `AWS_SESSION_TOKEN` | `IQoJb3JpZ2luX2VjEO7//////////wEaCXVzLXdlc3QtMiJHMEUCIQD...` |
|
||||
@@ -141,7 +141,7 @@ variable.
|
||||
| `agent-framework-github-copilot` | `GitHubCopilotAgent` | `GITHUB_COPILOT_LOG_LEVEL` | `info` |
|
||||
| `agent-framework-mem0` | `agent_framework_mem0 package import` | `MEM0_TELEMETRY` | `false` |
|
||||
| `agent-framework-ollama` | `OllamaChatClient` | `OLLAMA_HOST` | `http://localhost:11434` |
|
||||
| `agent-framework-ollama` | `OllamaChatClient` | `OLLAMA_MODEL_ID` | `llama3.1:8b` |
|
||||
| `agent-framework-ollama` | `OllamaChatClient` | `OLLAMA_MODEL` | `llama3.1:8b` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `OPENAI_API_KEY` | `sk-proj-...` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `OPENAI_MODEL` | `gpt-4o-mini` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient` | `OPENAI_RESPONSES_MODEL` | `gpt-4.1-mini` |
|
||||
@@ -153,10 +153,10 @@ variable.
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `AZURE_OPENAI_API_KEY` | `sk-azure-...` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `AZURE_OPENAI_API_VERSION` | `2024-10-21` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `AZURE_OPENAI_BASE_URL` | `https://my-resource.openai.azure.com/openai/v1/` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `AZURE_OPENAI_DEPLOYMENT_NAME` | `gpt-4o` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient` | `AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME` | `gpt-4.1` |
|
||||
| `agent-framework-openai` | `OpenAIChatCompletionClient` | `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME` | `gpt-4o-mini` |
|
||||
| `agent-framework-openai` | `OpenAIEmbeddingClient` | `AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME` | `text-embedding-3-large` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `AZURE_OPENAI_MODEL` | `gpt-4o` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient` | `AZURE_OPENAI_RESPONSES_MODEL` | `gpt-4.1` |
|
||||
| `agent-framework-openai` | `OpenAIChatCompletionClient` | `AZURE_OPENAI_CHAT_MODEL` | `gpt-4o-mini` |
|
||||
| `agent-framework-openai` | `OpenAIEmbeddingClient` | `AZURE_OPENAI_EMBEDDING_MODEL` | `text-embedding-3-large` |
|
||||
| `agent-framework-openai` | `OpenAIChatClient / OpenAIChatCompletionClient / OpenAIEmbeddingClient` | `AZURE_OPENAI_RESOURCE_URL` | `https://cognitiveservices.azure.com/` |
|
||||
|
||||
`agent-framework-openai` supports the Azure OpenAI client-specific deployment aliases listed above; keep
|
||||
|
||||
+2
-2
@@ -23,12 +23,12 @@ async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
|
||||
|
||||
openai_settings = OpenAISettings()
|
||||
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
|
||||
assert openai_settings.responses_model is not None, "Responses model ID must be set in OpenAISettings"
|
||||
|
||||
client = OpenAIResponsesAgent.create_client()
|
||||
# SK response agents wrap OpenAI's hosted Responses API.
|
||||
agent = OpenAIResponsesAgent(
|
||||
ai_model_id=openai_settings.responses_model_id,
|
||||
ai_model=openai_settings.responses_model,
|
||||
client=client,
|
||||
instructions="Answer in one concise sentence.",
|
||||
name="Expert",
|
||||
|
||||
+2
-2
@@ -29,12 +29,12 @@ async def run_semantic_kernel() -> None:
|
||||
return a + b
|
||||
|
||||
openai_settings = OpenAISettings()
|
||||
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
|
||||
assert openai_settings.responses_model is not None, "Responses model ID must be set in OpenAISettings"
|
||||
|
||||
client = OpenAIResponsesAgent.create_client()
|
||||
# Plugins advertise callable tools to the Responses agent.
|
||||
agent = OpenAIResponsesAgent(
|
||||
ai_model_id=openai_settings.responses_model_id,
|
||||
ai_model=openai_settings.responses_model,
|
||||
client=client,
|
||||
instructions="Use the add tool when math is required.",
|
||||
name="MathExpert",
|
||||
|
||||
+2
-2
@@ -30,12 +30,12 @@ async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
|
||||
|
||||
openai_settings = OpenAISettings()
|
||||
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
|
||||
assert openai_settings.responses_model is not None, "Responses model ID must be set in OpenAISettings"
|
||||
|
||||
client = OpenAIResponsesAgent.create_client()
|
||||
# response_format requests schema-constrained output from the model.
|
||||
agent = OpenAIResponsesAgent(
|
||||
ai_model_id=openai_settings.responses_model_id,
|
||||
ai_model=openai_settings.responses_model,
|
||||
client=client,
|
||||
instructions="Return launch briefs as structured JSON.",
|
||||
name="ProductMarketer",
|
||||
|
||||
@@ -54,15 +54,15 @@ async def build_semantic_kernel_agents() -> list[ChatCompletionAgent | OpenAIAss
|
||||
instructions=(
|
||||
"You are a Researcher. You find information without additional computation or quantitative analysis."
|
||||
),
|
||||
service=OpenAIChatCompletion(ai_model_id="gpt-4o-mini-search-preview"),
|
||||
service=OpenAIChatCompletion(ai_model="gpt-4o-mini-search-preview"),
|
||||
)
|
||||
|
||||
client = OpenAIAssistantAgent.create_client()
|
||||
code_interpreter_tool, code_interpreter_tool_resources = OpenAIAssistantAgent.configure_code_interpreter_tool()
|
||||
openai_settings = OpenAISettings()
|
||||
model_id = openai_settings.chat_model_id if openai_settings.chat_model_id else "gpt-5"
|
||||
model = openai_settings.chat_model if openai_settings.chat_model else "gpt-5"
|
||||
definition = await client.beta.assistants.create( # pyright: ignore[reportDeprecated]
|
||||
model=model_id,
|
||||
model=model,
|
||||
name="CoderAgent",
|
||||
description="A helpful assistant that writes and executes code to process and analyze data.",
|
||||
instructions="You solve questions using code. Please provide detailed analysis and computation process.",
|
||||
|
||||
Reference in New Issue
Block a user