feat(telemetry): add system_prompt attribute to agent spans#1455
feat(telemetry): add system_prompt attribute to agent spans#1455cagataycali wants to merge 0 commit intostrands-agents:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
CI Failure Analysis 🔍The failing integration test Evidence
Root Cause: Flaky TestThe test assumes deterministic model behavior: expected_hook_events = [
AgentInitializedEvent,
BeforeInvocationEvent,
MessageAddedEvent,
BeforeModelCallEvent, # Expects exactly 1
AfterModelCallEvent,
MessageAddedEvent,
AfterInvocationEvent,
]But LLMs are non-deterministic - sometimes image analysis requires multiple model calls. RequestCould a maintainer:
The actual telemetry changes work correctly - all 70 unit telemetry tests pass. Strands-Coder 🦆 |
|
Actually, let me reconsider this. After deeper investigation, I found that:
@pgrayy - excellent catch on the semantic conventions! @cagataycali - Since this is your PR, could you clarify:
I don't want to suggest changes without understanding the intent. 🎯 🦆 🤖 This is an experimental AI agent response from the Strands team, powered by Strands Agents. We're exploring how AI agents can help with community support and development. Your feedback helps us improve! If you'd prefer human assistance, please let us know. |
|
It looks good to me, I provided a reasoning for it in #1452 |
004e72a to
e4bd3bc
Compare
Description
Adds explicit
system_promptparameter tostart_agent_span()method to include agent system prompts in OpenTelemetry traces. This is particularly useful for Swarm/multi-agent scenarios where each agent has its own system prompt that needs to be visible in Langfuse/OTEL traces.Changes
system_prompt: Optional[str]parameter tostart_agent_span()methodgen_ai.agent.system_promptin span attributes (following OpenTelemetry semantic conventions)Before
In Swarm scenarios, the system_prompt was passed via **kwargs but wasn't explicitly mapped to a semantic attribute, so it appeared in traces with its raw key name.
After
The system_prompt is now properly included as
gen_ai.agent.system_promptin the span attributes, making it visible in Langfuse traces.Related Issues
Fixes #1452 - System prompts are omitted in Swarm with Strands Agents
Documentation PR
No documentation changes required - this is an internal telemetry improvement.
Type of Change
Testing
test_start_agent_span_with_system_prompt- verifies system_prompt is included in attributestest_start_agent_span_without_system_prompt- verifies no attribute when not providedtest_start_agent_span_with_empty_system_prompt- verifies no attribute for empty stringshatch fmt --formatter✅hatch fmt --linter✅Checklist
🦆 Strands-Coder - Autonomous GitHub Agent