Add message_id to LLM events to differentiate stream chunks #3846
+212
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add message_id to LLM events to differentiate stream chunks
Summary
This PR fixes issue #3845 by adding a unique
message_idfield to all LLM events. Previously, when an agent made multiple LLM calls within the same task, allLLMStreamChunkEventchunks shared the sametask_idandagent_id, making it impossible to differentiate which chunks belonged to which LLM call.Changes:
message_id: str | None = Nonefield toLLMEventBase(maintains backward compatibility)message_id(UUID) at the start of eachLLM.call()message_idthrough all code paths (streaming, non-streaming, tool calls, error handling)message_idfor events from the same callReview & Testing Checklist for Human
uv run pytest lib/crewai/tests/test_llm_message_id.py -vvto verify they passmessage_idvaluesmessage_idmessage_idstill work correctlyTest Plan
LLMCallStartedEventandLLMStreamChunkEventmessage_idmessage_idNotes
message_idfield is optional (defaults to None) for backward compatibility