feat: Multi-Chat Awareness & Cross-Thread State Sharing#1610
Open
gdeyoung wants to merge 1 commit into
Open
Conversation
Adds cross-thread state sharing for multi-chat deployments: 1. source_chat field in BaseTask (task provenance) - Optional[str] field records which chat created each task - Captured automatically in all 3 task creation methods 2. Three framework extensions for automatic state sharing: - agent_init: registers chat thread in shared state - message_loop_start: injects other threads' state into context - message_loop_end: logs turn activity for cross-thread visibility 3. Thread-safe file-based state with flock for concurrent access All changes are backward-compatible. New fields default to None. Extensions use file-based state with flock for thread safety.
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.
Multi-Chat Awareness & Cross-Thread State Sharing
Problem
When running multiple concurrent chat threads in Agent Zero, agents have no visibility into what other threads are doing. This leads to:
Solution
This PR adds automatic cross-thread state sharing with minimal surface area:
1. Task Source Chat (Core: 7 lines across 2 files)
2. Three Framework Extensions (208 lines across 3 files)
3. Thread-Safe State File
Extensions use ~/.a0_cross_thread_state.json with fcntl.flock for atomic reads/writes. No external dependencies — pure stdlib.
Architecture
NEW CHAT THREAD STARTS
└── agent_init extension → registers chat in shared state
EVERY MESSAGE LOOP TURN
├── message_loop_start → reads shared state, injects summary
│ Shows: active chats, recent changes, open issues
└── message_loop_end → logs turn activity to shared state
Records: chat_id, action summary, timestamp
SCHEDULER CREATES TASK
└── task.source_chat = agent.context.id
Every task knows its originating chat
Backward Compatibility
Testing
Running in production with 19 concurrent scheduled tasks and 34 active chat threads:
Files Changed
helpers/task_scheduler.py | 1 +
tools/scheduler.py | 6 ++
extensions/python/agent_init/_20_register_chat_state.py | 73 +++++++++
extensions/python/message_loop_start/_20_inject_cross_thread_state.py | 52 ++++++
extensions/python/message_loop_end/_20_log_cross_thread_turn.py | 83 ++++++++++
5 files changed, 215 insertions(+)