fix: children subagents couldn't properly send messages to parent inboxes
This commit is contained in:
6 files changed
+188
-43
No files matched your search
@@ -69,6 +69,7 @@ pub async fn macro_execute(
|
||||
macro_ctx.parent_supervisor = ctx.parent_supervisor.clone();
|
||||
macro_ctx.self_agent_id = ctx.self_agent_id.clone();
|
||||
macro_ctx.inbox = ctx.inbox.clone();
|
||||
macro_ctx.parent_inbox = ctx.parent_inbox.clone();
|
||||
macro_ctx.escalation_queue = ctx.escalation_queue.clone();
|
||||
macro_ctx.current_depth = ctx.current_depth;
|
||||
macro_ctx.auto_continue_count = ctx.auto_continue_count;
|
||||
|
||||
@@ -212,7 +212,7 @@ pub(in crate::config) const DEFAULT_TEAMMATE_INSTRUCTIONS: &str = indoc! {"
|
||||
## Teammate Messaging
|
||||
|
||||
You have tools to communicate with other agents running alongside you:
|
||||
- `agent__send_message --id <agent_id> --message \"...\"`: Send a message to a sibling or parent agent.
|
||||
- `agent__send_message --id <agent_id> --message \"...\"`: Send a message to a child or sibling agent by its id, or to your parent with the reserved id `parent`.
|
||||
- `agent__check_inbox`: Check for messages sent to you by other agents.
|
||||
|
||||
If you are working alongside other agents (e.g. reviewing different files, exploring different areas):
|
||||
|
||||
@@ -327,6 +327,7 @@ pub struct RequestContext {
|
||||
pub parent_supervisor: Option<Arc<RwLock<Supervisor>>>,
|
||||
pub self_agent_id: Option<String>,
|
||||
pub inbox: Option<Arc<Inbox>>,
|
||||
pub parent_inbox: Option<Arc<Inbox>>,
|
||||
pub escalation_queue: Option<Arc<EscalationQueue>>,
|
||||
pub notification_queue: Arc<NotificationQueue>,
|
||||
pub current_depth: usize,
|
||||
@@ -364,6 +365,7 @@ impl RequestContext {
|
||||
parent_supervisor: None,
|
||||
self_agent_id: None,
|
||||
inbox: None,
|
||||
parent_inbox: None,
|
||||
escalation_queue: None,
|
||||
notification_queue: Arc::new(NotificationQueue::new()),
|
||||
current_depth: 0,
|
||||
@@ -427,6 +429,7 @@ impl RequestContext {
|
||||
parent_supervisor: None,
|
||||
self_agent_id: None,
|
||||
inbox: None,
|
||||
parent_inbox: None,
|
||||
escalation_queue: None,
|
||||
notification_queue: Arc::new(NotificationQueue::new()),
|
||||
current_depth: 0,
|
||||
@@ -479,6 +482,7 @@ impl RequestContext {
|
||||
parent_supervisor: self.parent_supervisor.clone(),
|
||||
self_agent_id: self.self_agent_id.clone(),
|
||||
inbox: self.inbox.clone(),
|
||||
parent_inbox: self.parent_inbox.clone(),
|
||||
escalation_queue: self.escalation_queue.clone(),
|
||||
notification_queue: self.notification_queue.clone(),
|
||||
current_depth: self.current_depth,
|
||||
@@ -527,6 +531,7 @@ impl RequestContext {
|
||||
parent_supervisor: parent.supervisor.clone(),
|
||||
self_agent_id: Some(self_agent_id),
|
||||
inbox: Some(inbox),
|
||||
parent_inbox: parent.inbox.clone(),
|
||||
escalation_queue: parent.escalation_queue.clone(),
|
||||
notification_queue: Arc::new(NotificationQueue::new()),
|
||||
current_depth,
|
||||
@@ -559,6 +564,12 @@ impl RequestContext {
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub fn ensure_inbox(&mut self) -> Arc<Inbox> {
|
||||
self.inbox
|
||||
.get_or_insert_with(|| Arc::new(Inbox::new()))
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub fn rag_cache(&self) -> &Arc<RagCache> {
|
||||
&self.app.rag_cache
|
||||
}
|
||||
@@ -4651,6 +4662,7 @@ impl RequestContext {
|
||||
}
|
||||
self.supervisor = supervisor;
|
||||
self.inbox = None;
|
||||
self.parent_inbox = None;
|
||||
self.escalation_queue = None;
|
||||
self.notification_queue = Arc::new(NotificationQueue::new());
|
||||
self.self_agent_id = None;
|
||||
@@ -4694,6 +4706,7 @@ impl RequestContext {
|
||||
self.parent_supervisor = None;
|
||||
self.self_agent_id = None;
|
||||
self.inbox = None;
|
||||
self.parent_inbox = None;
|
||||
self.escalation_queue = None;
|
||||
self.notification_queue = Arc::new(NotificationQueue::new());
|
||||
self.current_depth = 0;
|
||||
@@ -5958,6 +5971,40 @@ mod tests {
|
||||
assert!(ctx.inbox.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parent_inbox_defaults_to_none() {
|
||||
let ctx = create_test_ctx();
|
||||
|
||||
assert!(ctx.parent_inbox.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_inbox_allocates_once_and_is_stable() {
|
||||
let mut ctx = create_test_ctx();
|
||||
let first = ctx.ensure_inbox();
|
||||
let second = ctx.ensure_inbox();
|
||||
|
||||
assert!(Arc::ptr_eq(&first, &second));
|
||||
assert!(ctx.inbox.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_for_child_inherits_parent_inbox() {
|
||||
let mut parent = create_test_ctx();
|
||||
let parent_inbox = parent.ensure_inbox();
|
||||
let child = RequestContext::new_for_child(
|
||||
Arc::clone(&parent.app),
|
||||
&parent,
|
||||
1,
|
||||
Arc::new(Inbox::new()),
|
||||
"agent_test_1".to_string(),
|
||||
);
|
||||
|
||||
let child_parent_inbox = child.parent_inbox.expect("child should see parent's inbox");
|
||||
|
||||
assert!(Arc::ptr_eq(&parent_inbox, &child_parent_inbox));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escalation_queue_defaults_to_none() {
|
||||
let ctx = create_test_ctx();
|
||||
|
||||
Reference in new issue
Block a user