Skip to content

fix: preserve response-mode session scoping without Langfuse#4016

Open
shaun0927 wants to merge 2 commits intocamel-ai:masterfrom
shaun0927:fix/responses-session-scope
Open

fix: preserve response-mode session scoping without Langfuse#4016
shaun0927 wants to merge 2 commits intocamel-ai:masterfrom
shaun0927:fix/responses-session-scope

Conversation

@shaun0927
Copy link
Copy Markdown

Related Issue

Fixes #4012

Description

Response-mode chaining currently reuses the shared "__default__" key whenever Langfuse is disabled, even though ChatAgent already sets an agent session id.

This change keeps the context-local agent session id available regardless of tracing configuration so response chaining remains scoped per agent session.

Changes:

  • return the current agent session id from camel.utils.langfuse.get_current_agent_session_id() without gating it on Langfuse enablement
  • add a regression test for OpenAIModel
  • add a regression test for OpenAICompatibleModel

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Checklist

  • I have read and agree to the AI-Generated Code Policy (required)
  • I have linked this PR to an issue (required)
  • I have checked if any dependencies need to be added or updated in pyproject.toml and run uv lock
  • I have updated the tests accordingly (required for a bug fix or a new feature)
  • I have updated the documentation if needed
  • I have added examples if this is a new feature

Test evidence

pytest -q test/models/test_openai_model.py test/models/test_openai_compatible_model.py -k 'responses_mode_uses_agent_session_scope_when_langfuse_is_disabled or openai_compatible_responses_uses_agent_session_scope_when_langfuse_is_disabled'

Passed locally:

  • 2 passed, 38 deselected

Response-mode backends were reusing the shared "__default__" chain key whenever Langfuse was disabled, even though ChatAgent already records an agent session id. This keeps the context-local session id available for backend scoping regardless of tracing configuration and adds focused regression tests for both OpenAIModel and OpenAICompatibleModel.

Constraint: Must not change external response API behavior beyond session scoping
Rejected: Keep gating session lookup on Langfuse availability | causes cross-agent chain reuse in normal deployments
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Session scoping for model backends should not depend on observability providers
Tested: pytest -q test/models/test_openai_model.py test/models/test_openai_compatible_model.py -k 'responses_mode_uses_agent_session_scope_when_langfuse_is_disabled or openai_compatible_responses_uses_agent_session_scope_when_langfuse_is_disabled'
Not-tested: Full OpenAI/OpenAI-compatible model suites without API credential fixtures
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a1935241-1592-431d-8a94-3ca81dfe7ced

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Constraint: Keep the original fix unchanged while making the branch pass repository formatting rules
Rejected: Leave pre-commit failure for maintainers to fix | blocks review on a formatting-only issue
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: New regression tests should stay within the repo's line-length/style constraints to avoid noisy CI failures
Tested: ruff check camel/utils/langfuse.py test/models/test_openai_model.py test/models/test_openai_compatible_model.py; pytest -q test/models/test_openai_model.py test/models/test_openai_compatible_model.py -k 'responses_mode_uses_agent_session_scope_when_langfuse_is_disabled or openai_compatible_responses_use_agent_session_scope_without_langfuse'
Not-tested: Full model test suites with CI secrets
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.

[BUG] Responses chaining ignores agent session ids when Langfuse is disabled

1 participant