Skip to content

Conversation

@GeLi2001
Copy link
Contributor

@GeLi2001 GeLi2001 commented Oct 5, 2025

resolves #2265


Note

Ensure session_id is reliably captured (from args or session object) during streaming runs and add regression coverage with VCR cassette.

  • Instrumentation (Agno):
    • Add '_extract_session_id' with fallback to arguments['session'].session_id for Agno v2 compatibility.
    • Use '_extract_session_id' in '_run_arguments', '_RunWrapper.run_stream', and '_RunWrapper.arun_stream' to set session.id and fetch agent.get_last_run_output(session_id=...).
  • Tests:
    • Add regression test test_session_id_streaming_regression validating session.id is captured for stream=True runs.
    • Add VCR cassette tests/openinference/instrumentation/agno/fixtures/agent_run_stream.yaml for streaming responses.

Written by Cursor Bugbot for commit 7b44140. This will update automatically on new commits. Configure here.

@GeLi2001 GeLi2001 requested a review from a team as a code owner October 5, 2025 09:05
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 5, 2025
# Mock agent with get_last_run_output method that raises exception when session_id is None
mock_agent = Mock()

def mock_get_last_run_output(session_id: str = None) -> Mock:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint for session_id should be Optional[str] since it has a default value of None. This would make the type annotation consistent with the parameter's actual behavior:

def mock_get_last_run_output(session_id: Optional[str] = None) -> Mock:

This change would also require adding Optional to the imports from typing at the top of the file, though it's already imported in the diff.

Suggested change
def mock_get_last_run_output(session_id: str = None) -> Mock:
def mock_get_last_run_output(session_id: Optional[str] = None) -> Mock:

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here.

mock_agent.name = "Test Agent"

# Mock the internal _run_stream method with proper signature
def mock_run_stream(message: str, session_id: str = None, **kwargs: Any) -> Iterator[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint for session_id should be Optional[str] since it has a default value of None. This would make the type annotation consistent with the parameter's actual behavior:

def mock_run_stream(message: str, session_id: Optional[str] = None, **kwargs: Any) -> Iterator[str]:

This change would align with Python's type hinting best practices and improve static type checking.

Suggested change
def mock_run_stream(message: str, session_id: str = None, **kwargs: Any) -> Iterator[str]:
def mock_run_stream(message: str, session_id: Optional[str] = None, **kwargs: Any) -> Iterator[str]:

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here.

setup_agno_instrumentation: Any,
) -> None:
"""Regression test: ensure session_id is properly extracted in streaming methods."""
from unittest.mock import Mock
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer vcr over mock - see LN69, and LN126 above for setup

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 7, 2025
@JasonLovesDoggo
Copy link

Any shot this can be merged soon? currently breaking telemetry

@nate-mar
Copy link
Contributor

nate-mar commented Oct 9, 2025

@JasonLovesDoggo Yep! we'll push this out today!

@nate-mar
Copy link
Contributor

@JasonLovesDoggo Sorry! spoke a bit too soon; this should be out by tomorrow!

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Oct 10, 2025
@nate-mar
Copy link
Contributor

Hey @GeLi2001 any update on this one? Dirk mentioned it is solved in their PR. Let's get that one across the line for @JasonLovesDoggo since Agno's PR should fix it. Let me know if you have any issues.

@nate-mar
Copy link
Contributor

@JasonLovesDoggo should be fixed now via #2262! I just released a new version of the agno instrumentation as well. Thanks for your patience on this!

@nate-mar
Copy link
Contributor

closing this PR in favor of #2262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[bug] Inconsistent Session ID Handling [Agno]

4 participants