Skip to content

Conversation

@awsarron
Copy link
Member

Description

Fix agent span start and end when using Agent.stream_async()

Related Issues

#118

Documentation PR

N/A

Type of Change

  • Bug fix

Testing

#!/usr/bin/env python

import asyncio
import logging
import os
from strands import Agent, tool
from strands_tools import calculator, http_request, image_reader

logging.getLogger("strands.telemetry.tracer").setLevel(logging.DEBUG)
logging.basicConfig(
    format="%(levelname)s | %(name)s | %(message)s",
    handlers=[logging.StreamHandler()]
)

os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://us.cloud.langfuse.com/api/public/otel"
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = "Authorization=Basic <REDACTED>"

agent = Agent(
    system_prompt="You are a helpful assistant that provides concise responses.",
    tools=[http_request, calculator, image_reader],
    trace_attributes={
        "session.id": "abc-1234",
        "user.id": "[email protected]",
        "langfuse.tags": [
            "Agent-SDK",
            "Okatank-Project",
            "Observability-Tags",
        ]
    },
    callback_handler=None,
)

async def process_streaming_response():
    agent_stream = agent.stream_async("\u30d5\u30a9\u30fc Describe the image at /Users/arron/strands-samples/01-getting-started/00-first-agent/images/architecture.png")
    async for event in agent_stream:
        print(event)

# Run the agent
asyncio.run(process_streaming_response())

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective or my feature works
  • [-] I have updated the documentation accordingly
  • [-] I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@awsarron awsarron merged commit bd60f90 into strands-agents:main May 26, 2025
10 checks passed
@awsarron awsarron deleted the fix-telemetry-stream-async branch May 26, 2025 17:06
awsarron added a commit to awsarron/sdk-python that referenced this pull request May 26, 2025
awsarron added a commit that referenced this pull request May 26, 2025
* models - openai - argument none (#97)

* docs(readme): add open PRs badge + link to samples repo + change 'Docs' to 'Documentation' (#100)

* docs(readme): add logo (#101)

* docs(readme): add logo, title, badges, links to other repos, standardize headings (#102)

* style(readme): use dark logo for clearer visibility when system is using light color scheme (#104)

* fix(readme): use logo that changes color automatically depending on user's color preference scheme (#105)

* feat(handlers): add reasoning text to callback handler and related tests (#109)

* feat(handlers): add reasoning text to callback handler and related tests

* feat(handlers): removed redundant comment in .gitignore file

* feat(handlers): Updated reasoningText type as (Optional[str]

* feat: Add dynamic system prompt override functionality (#108)

* Modularizing Event Loop (#106)

* fix(telemetry): fix agent span start and end when using Agent.stream_async() (#119)

* feat: Update SlidingWindowConversationManager (#120)

* v0.1.5

---------

Co-authored-by: Patrick Gray <[email protected]>
Co-authored-by: Gokhan (Joe) Gultekin <[email protected]>
Co-authored-by: Shubham Raut <[email protected]>
Co-authored-by: fede-dash <[email protected]>
Co-authored-by: Nick Clegg <[email protected]>
@Unshure Unshure mentioned this pull request May 27, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants