[BUG] Responses chaining ignores agent session ids when Langfuse is disabled
## Summary
When CAMEL runs response-mode backends without Langfuse enabled, response chaining falls back to the shared `"__default__"` session key even when `ChatAgent` has already set an agent session id.
This means two different agent sessions can reuse the same `previous_response_id` if they share one backend instance.
## Why this is a real bug
CAMEL is a stateful multi-agent framework. Session isolation should not depend on whether Langfuse tracing happens to be enabled.
Today:
- `ChatAgent` calls `set_current_agent_session_id(self.agent_id)`
- but `get_current_agent_session_id()` returns `None` unless Langfuse is configured
- so `OpenAIModel` / `OpenAICompatibleModel` collapse to `"__default__"`
That makes response chaining reuse state across unrelated agent sessions.
## Affected code
- `camel/utils/langfuse.py`
- `camel/models/openai_model.py`
- `camel/models/openai_compatible_model.py`
## Minimal reproduction
I validated this locally on current `master` by:
1. creating one response-mode backend instance,
2. saving chain state under agent A,
3. switching to agent B,
4. calling `_prepare_responses_input_and_chain(...)`.
Observed result:
- session key stayed effectively shared,
- `previous_response_id` from agent A was reused for agent B.
## Expected behavior
Agent/session scoping for response chaining should work even when Langfuse is disabled.
## Actual behavior
Session scoping currently depends on Langfuse availability, which causes cross-session state bleed in normal non-Langfuse deployments.
## Suggested fix direction
Decouple `get_current_agent_session_id()` from Langfuse tracing availability, or otherwise keep a separate always-on context-local session key for model backends.
关闭于 2026-04-24 0 条评论