Track conversational flow turn usage in telemetry#6324
Conversation
There was a problem hiding this comment.
Summary: This PR adds a new conversational flow turn-start event and telemetry usage tracking for conversational flows; no exploitable security vulnerabilities were identified.
Risk: Low risk. The changes are limited to internal event emission and telemetry counting, with no new authentication, authorization, data access, external request, or user-facing execution surface.
📝 WalkthroughWalkthroughThe PR adds conversation turn started, completed, and failed events, exports them through the events API, emits them during conversational turn handling, records telemetry when completed turn events are observed, and initializes the event listener before the conversational TUI runs. ChangesConversation turn lifecycle events
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…track-conversational-flow-usage
lucasgomide
left a comment
There was a problem hiding this comment.
LGTM
I took a quick look here and I'm missing a ConversationTurnCompletedEvent . OTel spans has start/end fields, without an event like taht I would need to guess when the span close. Nothing blocker I would add it later, but would be great to have it from day 0
Also add the following attributes to ConversationTurnCompleted (status: success/error , error: error detail) + the same ConversationTurnStarted
….com:crewAIInc/crewAI into lorenze/feat/track-conversational-flow-usage
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 06db116. Configure here.
…track-conversational-flow-usage
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/crewai/src/crewai/experimental/conversational_mixin.py`:
- Around line 345-350: The terminal event dispatch in the conversational mixin
can still escape if crewai_event_bus.emit(self, event) raises before the guarded
future.result() call. Update the event dispatch flow in the relevant method on
ConversationalMixin so both emit and future.result(timeout=30) are wrapped in
the same try/except, with a None check still short-circuiting safely. Keep the
existing failure handling so kickoff/turn completion and the surrounding finally
logic are not disrupted by dispatch errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f2a7aefd-14da-4290-8fcf-b072845e9689
📒 Files selected for processing (4)
lib/cli/src/crewai_cli/kickoff_flow.pylib/cli/tests/test_kickoff_flow.pylib/crewai/src/crewai/experimental/conversational_mixin.pylib/crewai/tests/test_flow_conversation.py
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/crewai/tests/test_flow_conversation.py

Note
Low Risk
Observability and experimental conversational API changes only; no auth or data-path changes, with behavior guarded by tests.
Overview
Adds conversation turn lifecycle events (
conversation_turn_started,conversation_turn_completed,conversation_turn_failedwithsession_id) and wires them through the public events surface andEventTypes.handle_turnnow emitsConversationTurnStartedEventat turn start; on success it emits completed (after awaiting handler completion via_emit_terminal_conversation_turn_event); on failure it emits failed instead of completed, with errors serialized on the failed event. Terminal emissions block up to 30s on handler futures so telemetry/listeners finish before the turn returns.Telemetry:
EventListenerrecordsfeature_usage_span("flow:conversation_turn")onConversationTurnCompletedEvent.CLI:
_run_conversational_flow_tuiinstantiatesEventListener()beforeCrewRunAppso the TUI receives these events.Tests cover turn pairing, failure path, telemetry, and TUI listener initialization.
Reviewed by Cursor Bugbot for commit 9371ec5. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
session_id).session_id), failure-path behavior, telemetry on completed turns, and TUI event listener initialization.