mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* Fix #3613 message typing across chat and agents * Address #3613 review feedback and sample input style * refactor: use shared AgentRunMessages aliases (#3613) * refactor: rename agent run input aliases for #3613 * samples: inline image content in run calls * core: export AgentRunInputs from package init * core: use explicit init re-exports without __all__ * updated logging and inits * Fix core mypy export and samples XML note * Remove AgentRunInputsOrNone and dedupe loggers * Remove prepare_messages helper * fix integration tests
This commit is contained in:
committed by
GitHub
Unverified
parent
503eb10fdd
commit
dc9439a75a
@@ -178,12 +178,15 @@ The `configure_otel_providers()` function automatically reads **standard OpenTel
|
||||
> **Note**: These are standard OpenTelemetry environment variables. See the [OpenTelemetry spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/) for more details.
|
||||
|
||||
#### Logging
|
||||
Agent Framework has a built-in logging configuration that works well with telemetry. It sets the format to a standard format that includes timestamp, pathname, line number, and log level. You can use that by calling the `setup_logging()` function from the `agent_framework` module.
|
||||
Use standard Python logging configuration to align logs with telemetry output.
|
||||
|
||||
```python
|
||||
from agent_framework import setup_logging
|
||||
import logging
|
||||
|
||||
setup_logging()
|
||||
logging.basicConfig(
|
||||
format="[%(asctime)s - %(pathname)s:%(lineno)d - %(levelname)s] %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
```
|
||||
You can control at what level logging happens and thus what logs get exported, you can do this, by adding this:
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
from contextlib import suppress
|
||||
from random import randint
|
||||
from typing import TYPE_CHECKING, Annotated, Literal
|
||||
|
||||
from agent_framework import setup_logging, tool
|
||||
from agent_framework import tool
|
||||
from agent_framework.observability import configure_otel_providers, get_tracer
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
from opentelemetry import trace
|
||||
@@ -31,7 +32,9 @@ Use this approach when you need custom exporter configuration beyond what enviro
|
||||
SCENARIOS = ["client", "client_stream", "tool", "all"]
|
||||
|
||||
|
||||
# NOTE: approval_mode="never_require" is for sample brevity. Use "always_require" in production; see samples/02-agents/tools/function_tool_with_approval.py and samples/02-agents/tools/function_tool_with_approval_and_sessions.py.
|
||||
# NOTE: approval_mode="never_require" is for sample brevity.
|
||||
# Use "always_require" in production; see samples/02-agents/tools/function_tool_with_approval.py
|
||||
# and samples/02-agents/tools/function_tool_with_approval_and_sessions.py.
|
||||
@tool(approval_mode="never_require")
|
||||
async def get_weather(
|
||||
location: Annotated[str, Field(description="The location to get the weather for.")],
|
||||
@@ -101,7 +104,10 @@ async def main(scenario: Literal["client", "client_stream", "tool", "all"] = "al
|
||||
"""Run the selected scenario(s)."""
|
||||
|
||||
# Setup the logging with the more complete format
|
||||
setup_logging()
|
||||
logging.basicConfig(
|
||||
format="[%(asctime)s - %(pathname)s:%(lineno)d - %(levelname)s] %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
|
||||
# Create custom OTLP exporters with specific configuration
|
||||
# Note: You need to install opentelemetry-exporter-otlp-proto-grpc or -http separately
|
||||
|
||||
+9
-16
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import Content, Message
|
||||
from agent_framework import Content
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
@@ -20,24 +20,17 @@ async def main():
|
||||
# 1. Create an Azure Responses agent with vision capabilities
|
||||
agent = AzureOpenAIResponsesClient(credential=AzureCliCredential()).as_agent(
|
||||
name="VisionAgent",
|
||||
instructions="You are a helpful agent that can analyze images.",
|
||||
instructions="You are a image analysist, you get a image and need to respond with what you see in the picture.",
|
||||
)
|
||||
|
||||
# 2. Create a simple message with both text and image content
|
||||
user_message = Message(
|
||||
role="user",
|
||||
contents=[
|
||||
Content.from_text("What do you see in this image?"),
|
||||
Content.from_uri(
|
||||
uri="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800",
|
||||
media_type="image/jpeg",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# 3. Get the agent's response
|
||||
# 2. Get the agent's response
|
||||
print("User: What do you see in this image? [Image provided]")
|
||||
result = await agent.run(user_message)
|
||||
result = await agent.run(
|
||||
Content.from_uri(
|
||||
uri="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800",
|
||||
media_type="image/jpeg",
|
||||
)
|
||||
)
|
||||
print(f"Agent: {result.text}")
|
||||
print()
|
||||
|
||||
|
||||
+9
-16
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import Content, Message
|
||||
from agent_framework import Content
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
|
||||
"""
|
||||
@@ -19,24 +19,17 @@ async def main():
|
||||
# 1. Create an OpenAI Responses agent with vision capabilities
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="VisionAgent",
|
||||
instructions="You are a helpful agent that can analyze images.",
|
||||
instructions="You are a image analysist, you get a image and need to respond with what you see in the picture.",
|
||||
)
|
||||
|
||||
# 2. Create a simple message with both text and image content
|
||||
user_message = Message(
|
||||
role="user",
|
||||
contents=[
|
||||
Content.from_text(text="What do you see in this image?"),
|
||||
Content.from_uri(
|
||||
uri="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800",
|
||||
media_type="image/jpeg",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
# 3. Get the agent's response
|
||||
# 2. Get the agent's response
|
||||
print("User: What do you see in this image? [Image provided]")
|
||||
result = await agent.run(user_message)
|
||||
result = await agent.run(
|
||||
Content.from_uri(
|
||||
uri="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800",
|
||||
media_type="image/jpeg",
|
||||
)
|
||||
)
|
||||
print(f"Agent: {result.text}")
|
||||
print()
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ export AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o"
|
||||
|
||||
For Azure authentication, run `az login` before running samples.
|
||||
|
||||
## Note on XML tags
|
||||
|
||||
Some sample files include XML-style snippet tags (for example `<snippet_name>` and `</snippet_name>`). These are used by our documentation tooling and can be ignored or removed when you use the samples outside this repository.
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- [Agent Framework Documentation](https://learn.microsoft.com/agent-framework/)
|
||||
|
||||
Reference in New Issue
Block a user