Python: [BREAKING] updated structure and samples (#875)

* updated structure and samples

* updated names and removed cross tests

* updated projects etc

* updated tests

* updated test

* test fixes

* removed devui for now

* updated all-tests task

* removed old style configs

* remove coverage from tests

* updated to unit tests with all-tests

* updated foundry everywhere

* fix azure ai tests

* fix merge tests

* fix mypy
This commit is contained in:
Eduard van Valkenburg
2025-09-25 09:02:53 +02:00
committed by GitHub
Unverified
parent 366a7f7d47
commit 9355329dfd
169 changed files with 1159 additions and 1761 deletions
@@ -1,5 +1,5 @@
# Connector environment variables
# Foundry
# Azure AI
# see ../../../env.example for details
# OpenAI
# see ../../../env.example for details
@@ -6,7 +6,7 @@ from random import randint
from typing import Annotated
from agent_framework import HostedCodeInterpreterTool
from agent_framework.foundry import FoundryChatClient
from agent_framework.azure import AzureAIAgentClient
from agent_framework.observability import get_tracer, setup_observability
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import AzureCliCredential
@@ -15,12 +15,12 @@ from opentelemetry.trace.span import format_trace_id
from pydantic import Field
"""
This sample, shows you can leverage the built-in telemetry in Foundry.
It uses the Foundry client to setup the telemetry, this calls
out to Foundry for a telemetry connection strings,
This sample, shows you can leverage the built-in telemetry in Azure AI.
It uses the Azure AI client to setup the telemetry, this calls
out to Azure AI for a telemetry connection strings,
and then call the setup_observability function in the agent framework.
If you want to compare with the trace sent to a generic OTLP endpoint,
switch the `use_foundry_telemetry` variable to False.
switch the `use_azure_ai_telemetry` variable to False.
"""
@@ -47,10 +47,10 @@ async def main() -> None:
The telemetry will include information about the AI service execution.
In foundry you will also see specific operations happening that are called by the Foundry implementation,
In azure_ai you will also see specific operations happening that are called by the Azure AI implementation,
such as `create_agent`.
"""
use_foundry_obs = True
use_azure_ai_obs = True
questions = [
"What's the weather in Amsterdam and in Paris?",
"Why is the sky blue?",
@@ -59,16 +59,16 @@ async def main() -> None:
]
async with (
AzureCliCredential() as credential,
AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project,
FoundryChatClient(client=project, setup_tracing=False) as client,
AIProjectClient(endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], credential=credential) as project,
AzureAIAgentClient(client=project, setup_tracing=False) as client,
):
if use_foundry_obs:
await client.setup_foundry_observability(enable_live_metrics=True)
if use_azure_ai_obs:
await client.setup_observability(enable_live_metrics=True)
else:
setup_observability()
with get_tracer().start_as_current_span(
name="Foundry Telemetry from Agent Framework", kind=SpanKind.CLIENT
name="Azure AI Telemetry from Agent Framework", kind=SpanKind.CLIENT
) as span:
for question in questions:
print(f"{BLUE}User: {question}{RESET}")
@@ -6,16 +6,16 @@ from random import randint
from typing import Annotated
from agent_framework import ChatAgent
from agent_framework.azure import AzureAIAgentClient
from agent_framework.observability import get_tracer
from agent_framework_foundry import FoundryChatClient
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import AzureCliCredential
from opentelemetry.trace import SpanKind
from pydantic import Field
"""
This sample shows you can can setup telemetry with a agent from Foundry.
We once again call the `setup_foundry_observability` method to set up telemetry in order to include the overall spans.
This sample shows you can can setup telemetry with a agent from Azure AI.
We once again call the `setup_observability` method to set up telemetry in order to include the overall spans.
"""
@@ -34,11 +34,11 @@ async def main():
questions = ["What's the weather in Amsterdam?", "and in Paris, and which is better?", "Why is the sky blue?"]
async with (
AzureCliCredential() as credential,
AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project,
# this calls `setup_foundry_observability` through the context manager
FoundryChatClient(client=project) as client,
AIProjectClient(endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], credential=credential) as project,
# this calls `setup_observability` through the context manager
AzureAIAgentClient(client=project) as client,
):
await client.setup_foundry_observability(enable_live_metrics=True)
await client.setup_observability(enable_live_metrics=True)
with get_tracer().start_as_current_span("Single Agent Chat", kind=SpanKind.CLIENT):
print("Running Single Agent Chat")
print("Welcome to the chat, type 'exit' to quit.")
@@ -26,7 +26,7 @@ The Agent Framework Python SDK is designed to efficiently generate comprehensive
### Required resources
2. OpenAI or [Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal)
2. [Foundry project](https://ai.azure.com/doc/azure/ai-foundry/what-is-azure-ai-foundry)
2. [Azure AI project](https://ai.azure.com/doc/azure/ai-foundry/what-is-azure-ai-foundry)
### Optional resources
@@ -55,12 +55,12 @@ This folder contains different samples demonstrating how to use telemetry in var
### [01 - zero_code](./01-zero_code.py):
A simple example showing how to enable telemetry in a zero-touch scenario. When the above environment variables are set, telemetry will be automatically enabled, however since you do not define any overarching tracer, you will only see the spans for the specific calls to the chat client and tools.
### [02a](./02a-generic_chat_client.py) and [02b](./02b-foundry_chat_client.py) Chat Clients:
These two samples show how to first setup the telemetry by manually importing the `setup_observability` function from the `agent_framework.observability` module and calling it. After this is done, the trace that get's created will live in the same context as the chat client calls, allowing you to see the end-to-end flow of your application. For Foundry, there is a method in the Foundry project client to get the azure monitor connection string for your project, the `.setup_foundry_observability()` method in the `FoundryChatClient` class will use this url to configure telemetry and you then do not have to import and call `setup_observability()` manually.
### [02a](./02a-generic_chat_client.py) and [02b](./02b-azure_ai_chat_client.py) Chat Clients:
These two samples show how to first setup the telemetry by manually importing the `setup_observability` function from the `agent_framework.observability` module and calling it. After this is done, the trace that get's created will live in the same context as the chat client calls, allowing you to see the end-to-end flow of your application. For Azure AI, there is a method in the Azure AI project client to get the azure monitor connection string for your project, the `.setup_observability()` method in the `AzureAIAgentClient` class will use this url to configure telemetry and you then do not have to import and call `setup_observability()` manually.
If you or some other process already configure global tracer_providers or metrics_providers, the `setup_observability()` function will not override them, but instead use the existing tracer_provider, if possible. Metrics cannot be setup this way, so if you want to use metrics, you will have to call `setup_observability()` manually, before another process.
### [03a](./03a-generic_agent.py) and [03b](./03b-foundry_agent.py) Agents:
These two samples show how to setup telemetry when using the Agent Framework's agent abstraction layer. They are similar to the chat client samples, but also show how to create an agent and invoke it. The same rules apply for setting up telemetry, you can either call `setup_observability()` manually, or use the `setup_foundry_observability()` method in the `FoundryChatClient` class.
### [03a](./03a-generic_agent.py) and [03b](./03b-azure_ai_agent.py) Agents:
These two samples show how to setup telemetry when using the Agent Framework's agent abstraction layer. They are similar to the chat client samples, but also show how to create an agent and invoke it. The same rules apply for setting up telemetry, you can either call `setup_observability()` manually, or use the `setup_observability()` method in the `AzureAIAgentClient` class.
### [04 - workflow](./04-workflow.py) Workflow:
This sample shows how to setup telemetry when using the Agent Framework's workflow execution engine. It demonstrates a simple workflow scenario with telemetry.