fix: per-message agent attribution broken when snapshotting#68
Open
scmmishra wants to merge 4 commits into
Open
fix: per-message agent attribution broken when snapshotting#68scmmishra wants to merge 4 commits into
scmmishra wants to merge 4 commits into
Conversation
✅ Deploy Preview for ruby-ai-agents canceled.
|
Member
Author
|
@codex please review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In multi-agent conversations,
MessageExtractor.extract_messagesstamps every assistant message with the currently active agent's name. After a handoff, the chat contains assistant messages produced by earlier agents, but snapshotting the chat under the final agent re-attributes all of them to that final agent.That polluted snapshot then leaks into
AgentRunner#determine_conversation_agent, which picks the next active agent from the last assistant message'sagent_name— so subsequent runs can start with the wrong specialist.Example of the broken snapshot after a
Triage → Billinghandoff:Fixes #67.
Fix
Attach agent ownership to each assistant message at the moment it is produced, then read that per-message attribution at extraction time instead of inferring it from
current_agent.RubyLLM::Messagehas no metadata/extension API, so attribution is stored as an SDK-namespaced instance variable (:@agents_authoring_agent) on the message object. Two new module functions onMessageExtractorencapsulate this storage:assign_agent_name(message, agent_name)— stamp a message.attributed_agent_name_for(message)— read the stamp back.Runnercallsassign_agent_namein two places:chat.ask/chat.completeround trip, on the assistant messages appended during that turn (assign_agent_name_to_new_assistant_messages).context[:conversation_history], preserving any prioragent_name(assign_restored_agent_name).MessageExtractor.extract_user_or_assistant_messagenow readsattributed_agent_name_for(msg)first and falls back tocurrent_agent.nameonly when no per-message attribution exists. This keeps legacy/un-tagged history backwards compatible.Result