-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathagent_with_content_capture.py
More file actions
65 lines (48 loc) · 1.99 KB
/
agent_with_content_capture.py
File metadata and controls
65 lines (48 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Example: Agent with content capture enabled.
This example demonstrates opt-in content capture for debugging.
WARNING: Prompts and completions may contain sensitive information.
Only enable in development/debugging scenarios.
"""
import os
# Enable OpenTelemetry with content capture
os.environ["PICOAGENTS_ENABLE_OTEL"] = "true"
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "http://localhost:4318"
os.environ["OTEL_SERVICE_NAME"] = "picoagents-debug"
# OPT-IN: Capture prompts, completions, tool parameters and results
os.environ["PICOAGENTS_OTEL_CAPTURE_CONTENT"] = "true"
from picoagents import Agent # noqa: E402
from picoagents.llm import OpenAIChatCompletionClient # noqa: E402
from picoagents.tools import FunctionTool # noqa: E402
def get_weather(location: str) -> str:
"""Get the weather for a location."""
return f"The weather in {location} is sunny and 72°F"
async def main():
"""Run agent with content capture enabled."""
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
print("Please set OPENAI_API_KEY environment variable")
return
model = OpenAIChatCompletionClient(model="gpt-4.1-mini", api_key=api_key)
agent = Agent(
name="weather_debug",
description="Weather assistant with full content logging",
instructions="You are a helpful assistant. Use tools to answer questions.",
model_client=model,
tools=[FunctionTool(get_weather)],
)
# Single query for debugging
query = "What's the weather in Paris?"
print(f"\n{'='*60}")
print(f"Query: {query}")
print(f"{'='*60}\n")
response = await agent.run(query)
print(f"Response: {response.messages[-1].content}")
print(f"\n{'='*60}")
print("✅ Done! View traces at: http://localhost:16686")
print(" Search for service: picoagents-debug")
print(" Check span attributes for gen_ai.input.messages and gen_ai.output.messages")
print(f"{'='*60}\n")
if __name__ == "__main__":
import asyncio
asyncio.run(main())