关于 send_message_to_agent 的一点建议
Pre-checks
- [x] I have searched existing issues and this is not a duplicate.
What problem does this solve?
当智能体A send_message_to_agent 智能体B去做某件事时,智能体B会把事情做了再回复A,若智能体B所做的事比较复杂时,等待时间太长了,常常导致超时 异常中断。能不能让B收到消息后先回复,表示知晓任务,等完成后再回复智能体A?或者有人提供更好的方法吗?确保智能体之间的对话流畅。
Proposed solution
No response
Willing to contribute?
- [ ] I'd be interested in working on this.
Great suggestion! After analyzing the current architecture, I think this is not only feasible but the infrastructure is already largely in place. Here is a concrete implementation plan.
Current Problem
For native agents, send_message_to_agent is synchronous and blocking: Agent A calls the tool, which invokes Agent B's LLM inline (with up to 50 tool-call rounds), and waits for the full response before returning. The default LLM timeout is only 120 seconds with 3 retries, so complex tasks easily time out.
Proposed Solution: Differentiate by msg_type
The tool already defines three msg_type values (notify, consult, task_delegate) but the actual code does not differentiate — all types go through the same synchronous path. We can leverage this existing enum:
1. notify → Fire-and-forget (async, no reply expected)
Agent A sends a message and immediately gets back a confirmation. Agent B is woken asynchronously via the existing Trigger mechanism.
Flow:
A → send_message_to_agent(B, "...", msg_type="notify")
→ Save message to shared ChatSession
→ Create an on_message trigger on Agent B (from_agent_name=A)
→ Return immediately: "✅ Notification sent to B"
Agent B wakes up via the trigger daemon, reads the message from the session history, and acts on it. No reply back to A is expected.
2. task_delegate → Async with callback (B replies when done)
This is exactly the pattern you described: B acknowledges receipt and replies later when finished.
Flow:
A → send_message_to_agent(B, "Please prepare the Q3 report", msg_type="task_delegate")
→ Save message to shared ChatSession
→ Write focus item: - [ ] wait_b_report: Waiting for B to complete Q3 report
→ Create on_message trigger on A: from_agent_name=B
→ Wake B asynchronously (via trigger or direct LLM call in background)
→ Return immediately: "✅ Task delegated to B, you will be notified when complete"
B completes the task:
B → send_message_to_agent(A, "Q3 report is done...", msg_type="notify")
→ A's on_message trigger fires
→ A wakes up, sees focus item + B's message
→ A processes result and notifies the user
3. consult → Synchronous (current behavior, unchanged)
Keep the existing request-response pattern for quick questions where a real-time reply is needed.
Why This Works — Existing Infrastructure
The architecture already has the key building blocks:
-
Focus mechanism (
focus.md): Agent A writes a pending focus item tracking the delegated task. When A is woken later, it readsfocus.mdin its system prompt and knows what it was waiting for. -
Trigger system (
on_messagetype): The trigger daemon already evaluateson_messagetriggers every 15 seconds, checking for new messages from specific agents or users. It can wake Agent A when B replies. -
Native agents can initiate A2A: When an agent is woken by a trigger, it has the full tool set available (including
send_message_to_agent), so B can proactively message A back after completing its task — exactly like real-world delegation. -
OpenClaw async pattern: The async queue-based pattern for OpenClaw agents (
GatewayMessage+ poll/report) already proves the architecture supports non-blocking A2A. -
Chain depth protection:
MAX_AGENT_CHAIN_DEPTH = 5already prevents infinite A→B→A→B loops.
Implementation Scope
The main change is in _send_message_to_agent() to branch by msg_type:
notify: Save message → create trigger on target → return immediatelytask_delegate: Save message → write focus → createon_messagetrigger → wake target async → return immediatelyconsult: Keep current synchronous behavior
This is a moderate-scope change concentrated in one function, with the rest of the infrastructure already in place.
Phased Rollout Suggestion
- Phase 1: Make
notifytruly fire-and-forget (simplest, solves many timeout issues) - Phase 2: Implement
task_delegatewith async callback via focus + triggers - Phase 3: Optional UX enhancements (progress indicators in the UI, task status tracking)
Would love to hear thoughts on this approach. The key insight from your suggestion — letting B reply asynchronously — aligns perfectly with how the Focus + Trigger system already manages context across agent wake-ups.
@wisdomqin