Add user orchestrator for agent messaging and observation - #207
Merged
Conversation
This was referenced Jun 18, 2026
sethkarten
marked this pull request as ready for review
June 18, 2026 21:37
kevinjosethomas
requested changes
Jun 29, 2026
Contributor
Author
|
@kevinjosethomas addressed the agent-message queue and startup-race comments. Changes pushed to
GitHub CI is running on the pushed head now. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 14 total unresolved issues (including 13 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c6c4ad9. Configure here.
zhengr
pushed a commit
to zhengr/prime-agent
that referenced
this pull request
Aug 8, 2026
…lect-ai#207) * Add user orchestrator agent messaging and observe * Add orchestration heartbeat skill * Address user orchestrator PR review comments * Tighten agent message rate limiting * Harden agent message queue safety * Preserve agent message reservations on queue clear * Serialize agent messages per target * Handle queued agent message edge cases * Preserve orchestration heartbeat schedule on refresh * Fix agent message queue handling * Fix agent message review issues * Defer agent message acknowledgment past stream start * Fix agent message acceptance race * Avoid blocking agent message send on pre-prompt work * Avoid blocking agent messages on pre-prompt hooks * Hide daemon prompt fast path from public options * fix(coding-agent): harden agent message delivery * fix(coding-agent): keep failed agent messages from consuming limits * fix(coding-agent): address agent orchestrator review issues * fix(coding-agent): address agent orchestrator review issues * fix(coding-agent): queue sends during accepted retries * fix(coding-agent): address remaining orchestrator bot findings * test(coding-agent): update streaming prompt guard expectation * test(coding-agent): remove duplicate daemon queue case * fix(coding-agent): harden prompt acceptance races * fix(coding-agent): serialize agent message clearing * fix(coding-agent): lock agent message safety controls * fix(coding-agent): harden agent message pause * fix(coding-agent): queue agent messages internally * fix(coding-agent): release prompt lock when streaming starts * fix(coding-agent): reject messages paused while locked * fix(coding-agent): reject messages after session switch * fix(coding-agent): serialize session close with messages * fix(coding-agent): reject messages for closing sessions * fix(coding-agent): queue messages during compaction * fix(coding-agent): avoid blocking messages during prompt prep * fix(coding-agent): track queued agent messages * fix(coding-agent): preserve agent message queue identity Fixes PrimeIntellect-ai#207 * fix(coding-agent): parse canonical agent message ids Fixes PrimeIntellect-ai#207 * fix(coding-agent): clear accepted agent messages Fixes PrimeIntellect-ai#207 * fix(coding-agent): sanitize agent message metadata Fixes PrimeIntellect-ai#207 * fix(coding-agent): suppress cleared accepted messages Fixes PrimeIntellect-ai#207 * fix(coding-agent): clear accepted prompt state on failure Fixes PrimeIntellect-ai#207 * fix(coding-agent): account for accepted message delivery Fixes PrimeIntellect-ai#207 * fix(coding-agent): close accepted prompt busy gap Fixes PrimeIntellect-ai#207 * fix(coding-agent): harden accepted message cleanup Fixes PrimeIntellect-ai#207 * fix(coding-agent): report accepted messages as pending Fixes PrimeIntellect-ai#207 * fix(coding-agent): wait for accepted message delivery Fixes PrimeIntellect-ai#207 * fix(coding-agent): report duplicate follow-up preflight Fixes PrimeIntellect-ai#207 * fix(coding-agent): reject cleared accepted messages Fixes PrimeIntellect-ai#207 * fix(coding-agent): reject failed agent message delivery Fixes PrimeIntellect-ai#207 * fix(coding-agent): emit cleared accepted agent end Fixes PrimeIntellect-ai#207 * fix(coding-agent): unblock idle prompts after agent delivery Fixes PrimeIntellect-ai#207 * fix(coding-agent): wait for agent message delivery Fixes PrimeIntellect-ai#207 * fix(coding-agent): avoid direct delivery waiter hang Fixes PrimeIntellect-ai#207 * fix(coding-agent): settle late agent message waits Fixes PrimeIntellect-ai#207 * fix(coding-agent): reject delivery waits on dispose Fixes PrimeIntellect-ai#207 * fix(coding-agent): acknowledge queued agent messages * fix(coding-agent): review fixes for agent messaging admission, capacity, lifecycle, and CLI parsing * fix(coding-agent): drain agent messages after bash * fix(coding-agent): preserve queued message order after bash * fix(coding-agent): resolve queued agent-message sends without blocking on delivery; settle waiters on abort * fix(coding-agent): report busy observed sessions * fix(coding-agent): settle agent-message lifecycle edge cases * fix(coding-agent): keep deferred agent messages ordered * fix(coding-agent): harden queued message cleanup * fix(coding-agent): report queued direct accepts * fix(coding-agent): harden agent message delivery state * fix(coding-agent): restore next-turn context after failed accept * fix(coding-agent): defer cron while agent accepts messages * fix(coding-agent): queue cron during agent-message accept * fix(coding-agent): normalize orchestration heartbeat intervals * fix(coding-agent): recheck busy state before direct accept * fix(coding-agent): preserve next-turn context in queued accepts * fix(coding-agent): settle queued accept edge cases * fix(coding-agent): serialize daemon prompts with agent messages --------- Co-authored-by: Kevin Thomas <kevin.jt2007@gmail.com>
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.

Summary
This combines #164 and #173 into one user orchestrator surface for supervising multi-agent Prime Agent workflows:
agent-messageskill and daemon-backed direct session messagingagent-observeskill for read-only inspection of active agent sessionsorchestration-heartbeatskill to initialize or refresh an internal orchestrator RLM heartbeatThe design is based on the same constraint structure as cognitive load theory and the multi-agent communication framing in Interpretable Learned Emergent Communication for Human-Agent Teams: keep coordination channels sparse, bounded, interpretable, and directly relevant to the user/operator task. The orchestrator should reduce the need to manually track session state across tmux panes, files, and memory while avoiding an unbounded chat fabric between agents.
Orchestration heartbeat
orchestration_heartbeat.initialize()creates or updates a labeled internal RLM heartbeat for the current orchestrator session. The heartbeat prompt tells the orchestrator to:agent_observeactive,waiting,blocked,error, orcompletedThis is intentionally layered on RLM heartbeats, not the user-visible
/heartbeat, so the model cannot mutate the user-level heartbeat while managing orchestration checks.Safety model
MAX_AGENT_MESSAGE_CHARS.MAX_PENDING_AGENT_MESSAGES.Combined PRs
Validation
npm run buildnpx vitest --run packages/coding-agent/test/agent-observe.test.ts packages/coding-agent/test/agent-session-bus.test.ts packages/coding-agent/test/agent-session-services.test.ts packages/coding-agent/test/kernel-agent-message-skill.test.ts packages/coding-agent/test/kernel-agent-observe-skill.test.ts packages/coding-agent/test/kernel-orchestration-heartbeat-skill.test.ts packages/coding-agent/test/kernel-rlm-heartbeat-skill.test.ts packages/coding-agent/test/suite/agent-session-observe.test.ts packages/coding-agent/test/builtin-skills.test.ts packages/coding-agent/test/daemon-command.test.ts packages/coding-agent/test/daemon-mode.test.tsnpm run checknpm run checkNote
High Risk
Large changes to
AgentSessionprompt/queue lifecycle and concurrent delivery in the daemon; bugs could mis-route messages, deadlock busy sessions, or leak bounded observe previews across sessions.Overview
Adds daemon-backed multi-session orchestration: active Prime Agent sessions can message each other, inspect peers read-only, and run a recurring internal orchestrator heartbeat.
Agent messaging routes direct text to one live session via new daemon RPC (
send_message) and CLI (daemon send,daemon agent-messages). Delivery uses daemon-derived sender identity, no broadcast, size/queue/rate limits, per-target locking, and pause/resume/clear controls.AgentSessiongainsacceptAgentMessagePrompt/queueAgentMessagePromptand a refactored_promptpath (skip extensions,queueIfBusy, delivery receipts) so cross-session prompts do not race normal user prompts.Agent observe exposes bounded list/get/recent-message previews through host handlers and the
agent-observePython skill; observation cannot mutate other sessions.Orchestration heartbeat (
orchestration-heartbeatskill) composesagent_observeandrlm_heartbeatto create or refresh a labeled internal RLM heartbeat with compact progress/blocker/action instructions (separate from user/heartbeat).Kernel bootstrap now discovers sibling Python skill dependencies from
pyproject.tomland installs them in topological order. Orchestration-related skills are hidden unless the matching daemon controllers are wired on the session.Reviewed by Cursor Bugbot for commit 9454cba. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add agent-to-agent messaging, observation, and orchestration heartbeat skill to daemon
AgentSession.acceptAgentMessagePrompt/queueAgentMessagePromptand a daemonsendAgentSessionMessagemethod with per-target locking, rate limiting, queue capacity guards, and pause/resume controls.agent-message(list agents, send messages) andagent-observe(list/get agents, fetch recent messages), each bridged to host handlers inAgentSession.orchestration-heartbeatPython skill that generates recurring heartbeat instructions by observing active sessions and managing labeled RLM heartbeats.daemon-mode.tswith new RPC commands (send_message,agent_messages_status/pause/resume/clear) andAgentObserveControllerwiring; addsdaemon sendanddaemon agent-messagesCLI subcommands.bootstrap.tsto auto-discover sibling Python skill dependencies frompyproject.tomland install them in topological order._promptinAgentSessionis significantly refactored with new accepted-prompt lifecycle tracking; existing callers relying on preflight callback shape receive a newqueuedflag parameter.Changes since #207 opened
AgentSession.acceptAgentMessagePromptto defer and queue accepted agent messages when the session becomes busy between preflight validation and prompt handoff [7ca681b]AgentSession.acceptAgentMessagePromptto fold pending next-turn messages into queued agent message prompts when the session is busy or becomes busy at handoff [7bed563]AgentSession._queuePromptWithPendingNextTurnMessageshelper method andAgentSession._buildPromptContentutility to construct combined prompt content arrays [7bed563]AgentSession._queueSteerandAgentSession._queueFollowUpto accept optional prebuilt content arrays [7bed563]AgentSession.acceptAgentMessagePromptwhen handoff busy rejection occurs withoutstreamingBehavior[c6c4ad9]AgentSession._queueSteerandAgentSession._queueFollowUp[c6c4ad9]agent-session-prompt.test.ts[c6c4ad9]queue_updatelisteners inagent-session-queue.test.ts[c6c4ad9]AgentDaemonprompt handler to await in-flight agent-message accept operations before starting daemon-originating prompts [9454cba]Macroscope summarized 009ef1c.