mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b59a22d4d7 |
@@ -206,5 +206,9 @@ The samples typically read configuration from environment variables. Common requ
|
||||
- [Architectural Decision Records](./docs/decisions)
|
||||
|
||||
## Important Notes
|
||||
|
||||
If you use the Microsoft Agent Framework to build applications that operate with third-party servers or agents, you do so at your own risk. We recommend reviewing all data being shared with third-party servers or agents and being cognizant of third-party practices for retention and location of data. It is your responsibility to manage whether your data will flow outside of your organization's Azure compliance and geographic boundaries and any related implications.
|
||||
> [!IMPORTANT]
|
||||
> If you use Microsoft Agent Framework to build applications that operate with any third-party servers, agents, code, or non-Azure Direct models (“Third-Party Systems”), you do so at your own risk. Third-Party Systems are Non-Microsoft Products under the Microsoft Product Terms and are governed by their own third-party license terms. You are responsible for any usage and associated costs.
|
||||
>
|
||||
> We recommend reviewing all data being shared with and received from Third-Party Systems and being cognizant of third-party practices for handling, sharing, retention and location of data. It is your responsibility to manage whether your data will flow outside of your organization’s Azure compliance and geographic boundaries and any related implications, and that appropriate permissions, boundaries and approvals are provisioned.
|
||||
>
|
||||
> You are responsible for carefully reviewing and testing applications you build using Microsoft Agent Framework in the context of your specific use cases, and making all appropriate decisions and customizations. This includes implementing your own responsible AI mitigations such as metaprompt, content filters, or other safety systems, and ensuring your applications meet appropriate quality, reliability, security, and trustworthiness standards. See also: [Transparency FAQ](./TRANSPARENCY_FAQ.md.md)
|
||||
|
||||
@@ -8,12 +8,11 @@ from typing import Annotated
|
||||
from agent_framework import Message, tool
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
from agent_framework.observability import enable_instrumentation
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
from opentelemetry._logs import set_logger_provider
|
||||
from opentelemetry.metrics import set_meter_provider
|
||||
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
|
||||
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor, ConsoleLogRecordExporter
|
||||
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor, ConsoleLogExporter
|
||||
from opentelemetry.sdk.metrics import MeterProvider
|
||||
from opentelemetry.sdk.metrics.export import ConsoleMetricExporter, PeriodicExportingMetricReader
|
||||
from opentelemetry.sdk.resources import Resource
|
||||
@@ -38,7 +37,7 @@ def setup_logging():
|
||||
# Create and set a global logger provider for the application.
|
||||
logger_provider = LoggerProvider(resource=resource)
|
||||
# Log processors are initialized with an exporter which is responsible
|
||||
logger_provider.add_log_record_processor(BatchLogRecordProcessor(ConsoleLogRecordExporter()))
|
||||
logger_provider.add_log_record_processor(BatchLogRecordProcessor(ConsoleLogExporter()))
|
||||
# Sets the global default logger provider
|
||||
set_logger_provider(logger_provider)
|
||||
# Create a logging handler to write logging records, in OTLP format, to the exporter.
|
||||
@@ -116,15 +115,11 @@ async def run_chat_client() -> None:
|
||||
2 spans with gen_ai.operation.name=execute_tool
|
||||
|
||||
"""
|
||||
client = FoundryChatClient(credential=AzureCliCredential())
|
||||
client = FoundryChatClient()
|
||||
message = "What's the weather in Amsterdam and in Paris?"
|
||||
print(f"User: {message}")
|
||||
print("Assistant: ", end="")
|
||||
async for chunk in client.get_response(
|
||||
[Message(role="user", text=message)],
|
||||
stream=True,
|
||||
options={"tools": [get_weather]},
|
||||
):
|
||||
async for chunk in client.get_response([Message(role="user", text=message)], tools=get_weather, stream=True):
|
||||
if chunk.text:
|
||||
print(chunk.text, end="")
|
||||
print("")
|
||||
|
||||
@@ -7,7 +7,6 @@ from typing import TYPE_CHECKING, Annotated
|
||||
from agent_framework import Message, tool
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
from agent_framework.observability import get_tracer
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
from opentelemetry.trace import SpanKind
|
||||
from opentelemetry.trace.span import format_trace_id
|
||||
@@ -91,19 +90,12 @@ async def run_chat_client(client: "SupportsChatGetResponse", stream: bool = Fals
|
||||
print(f"User: {message}")
|
||||
if stream:
|
||||
print("Assistant: ", end="")
|
||||
async for chunk in client.get_response(
|
||||
[Message(role="user", text=message)],
|
||||
stream=True,
|
||||
options={"tools": [get_weather]},
|
||||
):
|
||||
async for chunk in client.get_response([Message(role="user", text=message)], tools=get_weather, stream=True):
|
||||
if chunk.text:
|
||||
print(chunk.text, end="")
|
||||
print("")
|
||||
else:
|
||||
response = await client.get_response(
|
||||
[Message(role="user", text=message)],
|
||||
options={"tools": [get_weather]},
|
||||
)
|
||||
response = await client.get_response([Message(role="user", text=message)], tools=get_weather)
|
||||
print(f"Assistant: {response}")
|
||||
|
||||
|
||||
@@ -111,7 +103,7 @@ async def main() -> None:
|
||||
with get_tracer().start_as_current_span("Zero Code", kind=SpanKind.CLIENT) as current_span:
|
||||
print(f"Trace ID: {format_trace_id(current_span.get_span_context().trace_id)}")
|
||||
|
||||
client = FoundryChatClient(credential=AzureCliCredential())
|
||||
client = FoundryChatClient()
|
||||
|
||||
await run_chat_client(client, stream=True)
|
||||
await run_chat_client(client, stream=False)
|
||||
|
||||
@@ -7,7 +7,6 @@ from typing import Annotated
|
||||
from agent_framework import Agent, tool
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
from agent_framework.observability import configure_otel_providers, get_tracer
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
from opentelemetry.trace import SpanKind
|
||||
from opentelemetry.trace.span import format_trace_id
|
||||
@@ -19,12 +18,6 @@ load_dotenv()
|
||||
"""
|
||||
This sample shows how you can observe an agent in Agent Framework by using the
|
||||
same observability setup function.
|
||||
|
||||
Pre-requisites:
|
||||
- A Foundry project
|
||||
- An observability backend to receive traces and metrics (for example, a local or remote
|
||||
OpenTelemetry Collector, another OTLP-compatible backend, or console exporters enabled
|
||||
via environment variables).
|
||||
"""
|
||||
|
||||
|
||||
@@ -54,7 +47,7 @@ async def main():
|
||||
print(f"Trace ID: {format_trace_id(current_span.get_span_context().trace_id)}")
|
||||
|
||||
agent = Agent(
|
||||
client=FoundryChatClient(credential=AzureCliCredential()),
|
||||
client=FoundryChatClient(),
|
||||
tools=get_weather,
|
||||
name="WeatherAgent",
|
||||
instructions="You are a weather assistant.",
|
||||
|
||||
@@ -9,7 +9,6 @@ from typing import TYPE_CHECKING, Annotated, Literal
|
||||
from agent_framework import Message, tool
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
from agent_framework.observability import configure_otel_providers, get_tracer
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
from opentelemetry import trace
|
||||
from opentelemetry.trace.span import format_trace_id
|
||||
@@ -25,9 +24,8 @@ This sample shows how you can configure observability of an application via the
|
||||
When you run this sample with an OTLP endpoint or an Application Insights connection string,
|
||||
you should see traces, logs, and metrics in the configured backend.
|
||||
|
||||
Pre-requisites:
|
||||
- A Foundry project
|
||||
- A local OpenTelemetry Collector instance to receive the traces and metrics.
|
||||
If no OTLP endpoint or Application Insights connection string is configured, the sample will
|
||||
output traces, logs, and metrics to the console.
|
||||
"""
|
||||
|
||||
# Load environment variables from .env file
|
||||
@@ -80,18 +78,13 @@ async def run_chat_client(client: "SupportsChatGetResponse", stream: bool = Fals
|
||||
if stream:
|
||||
print("Assistant: ", end="")
|
||||
async for chunk in client.get_response(
|
||||
[Message(role="user", text=message)],
|
||||
stream=True,
|
||||
options={"tools": [get_weather]},
|
||||
[Message(role="user", text=message)], tools=get_weather, stream=True
|
||||
):
|
||||
if chunk.text:
|
||||
print(chunk.text, end="")
|
||||
print("")
|
||||
else:
|
||||
response = await client.get_response(
|
||||
[Message(role="user", text=message)],
|
||||
options={"tools": [get_weather]},
|
||||
)
|
||||
response = await client.get_response([Message(role="user", text=message)], tools=get_weather)
|
||||
print(f"Assistant: {response}")
|
||||
|
||||
|
||||
@@ -108,7 +101,7 @@ async def run_tool() -> None:
|
||||
with get_tracer().start_as_current_span("Scenario: AI Function", kind=trace.SpanKind.CLIENT):
|
||||
print("Running scenario: AI Function")
|
||||
weather = await get_weather.invoke(location="Amsterdam")
|
||||
print(f"Weather in Amsterdam:\n{weather[-1]}")
|
||||
print(f"Weather in Amsterdam:\n{weather}")
|
||||
|
||||
|
||||
async def main(scenario: Literal["client", "client_stream", "tool", "all"] = "all"):
|
||||
@@ -121,7 +114,7 @@ async def main(scenario: Literal["client", "client_stream", "tool", "all"] = "al
|
||||
with get_tracer().start_as_current_span("Sample Scenarios", kind=trace.SpanKind.CLIENT) as current_span:
|
||||
print(f"Trace ID: {format_trace_id(current_span.get_span_context().trace_id)}")
|
||||
|
||||
client = FoundryChatClient(credential=AzureCliCredential())
|
||||
client = FoundryChatClient()
|
||||
|
||||
# Scenarios where telemetry is collected in the SDK, from the most basic to the most complex.
|
||||
if scenario == "tool" or scenario == "all":
|
||||
|
||||
@@ -10,7 +10,6 @@ from typing import TYPE_CHECKING, Annotated, Literal
|
||||
from agent_framework import Message, tool
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
from agent_framework.observability import configure_otel_providers, get_tracer
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
from opentelemetry import trace
|
||||
from opentelemetry.trace.span import format_trace_id
|
||||
@@ -28,10 +27,6 @@ and allows you to add multiple exporters programmatically.
|
||||
|
||||
For standard OTLP setup, it's recommended to use environment variables (see configure_otel_providers_with_env_var.py).
|
||||
Use this approach when you need custom exporter configuration beyond what environment variables provide.
|
||||
|
||||
Pre-requisites:
|
||||
- A Foundry project
|
||||
- A local OpenTelemetry Collector instance to receive the traces and metrics.
|
||||
"""
|
||||
|
||||
# Load environment variables from .env file
|
||||
@@ -84,18 +79,13 @@ async def run_chat_client(client: "SupportsChatGetResponse", stream: bool = Fals
|
||||
if stream:
|
||||
print("Assistant: ", end="")
|
||||
async for chunk in client.get_response(
|
||||
[Message(role="user", text=message)],
|
||||
stream=True,
|
||||
options={"tools": [get_weather]},
|
||||
[Message(role="user", text=message)], stream=True, tools=get_weather
|
||||
):
|
||||
if chunk.text:
|
||||
print(chunk.text, end="")
|
||||
print("")
|
||||
else:
|
||||
response = await client.get_response(
|
||||
[Message(role="user", text=message)],
|
||||
options={"tools": [get_weather]},
|
||||
)
|
||||
response = await client.get_response([Message(role="user", text=message)], tools=get_weather)
|
||||
print(f"Assistant: {response}")
|
||||
|
||||
|
||||
@@ -112,7 +102,7 @@ async def run_tool() -> None:
|
||||
with get_tracer().start_as_current_span("Scenario: AI Function", kind=trace.SpanKind.CLIENT):
|
||||
print("Running scenario: AI Function")
|
||||
weather = await get_weather.invoke(location="Amsterdam")
|
||||
print(f"Weather in Amsterdam:\n{weather[-1]}")
|
||||
print(f"Weather in Amsterdam:\n{weather}")
|
||||
|
||||
|
||||
async def main(scenario: Literal["client", "client_stream", "tool", "all"] = "all"):
|
||||
@@ -163,7 +153,7 @@ async def main(scenario: Literal["client", "client_stream", "tool", "all"] = "al
|
||||
with get_tracer().start_as_current_span("Sample Scenarios", kind=trace.SpanKind.CLIENT) as current_span:
|
||||
print(f"Trace ID: {format_trace_id(current_span.get_span_context().trace_id)}")
|
||||
|
||||
client = FoundryChatClient(credential=AzureCliCredential())
|
||||
client = FoundryChatClient()
|
||||
|
||||
# Scenarios where telemetry is collected in the SDK, from the most basic to the most complex.
|
||||
if scenario == "tool" or scenario == "all":
|
||||
|
||||
Reference in New Issue
Block a user