openclaw - 💡(How to fix) Fix [Feature]: Add an optional result-return mode for /hooks/agent [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#49019Fetched 2026-04-08 00:49:38
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Add an opt-in, machine-friendly result-return mode for POST /hooks/agent, so external automations can submit work and receive a deterministic result without relying on sessions_history polling or reopening sessions_send over HTTP.

Root Cause

Add an opt-in, machine-friendly result-return mode for POST /hooks/agent, so external automations can submit work and receive a deterministic result without relying on sessions_history polling or reopening sessions_send over HTTP.

Fix Action

Fix / Workaround

Today the best official workaround is:

Code Example

{
  "message": "Run this protocol task",
  "agentId": "bridge-protocol",
  "sessionKey": "hook:bridge:run-123",
  "deliver": false,
  "waitForResult": true,
  "timeoutSeconds": 30,
  "resultMode": "assistant_text",
  "announceToMain": false
}

---

{
  "ok": true,
  "status": "completed",
  "runId": "run_123",
  "sessionKey": "agent:bridge-protocol:hook:bridge:run-123",
  "result": "{\"type\":\"run_handoff_result\",\"status\":\"ok\"}"
}
RAW_BUFFERClick to expand / collapse

Summary

Add an opt-in, machine-friendly result-return mode for POST /hooks/agent, so external automations can submit work and receive a deterministic result without relying on sessions_history polling or reopening sessions_send over HTTP.

Problem to solve

OpenClaw currently has two nearby primitives, but neither is a clean fit for callback / handoff workflows:

  • /hooks/agent is good for authenticated external triggers, but it is async-oriented and posts a summary into the main session.
  • sessions_send is good for agent-to-agent messaging, but it is intentionally blocked from HTTP /tools/invoke by default, and its semantics are broader than a narrow machine callback.

This leaves a gap for workflows like:

  • runner completion callbacks
  • long-running bot-task completion callbacks
  • protocol-style continuation handoff (run_handoff -> run_handoff_result)

Today the best official workaround is:

  1. send work via POST /hooks/agent
  2. later recover the result with sessions_history

That works for simple experiments, but it is awkward as a product surface:

  • requires stitching together two APIs
  • encourages polling/readback flows
  • is not a first-class machine callback primitive

Proposed solution

Extend POST /hooks/agent with an optional wait/result mode.

Example request:

{
  "message": "Run this protocol task",
  "agentId": "bridge-protocol",
  "sessionKey": "hook:bridge:run-123",
  "deliver": false,
  "waitForResult": true,
  "timeoutSeconds": 30,
  "resultMode": "assistant_text",
  "announceToMain": false
}

Example response:

{
  "ok": true,
  "status": "completed",
  "runId": "run_123",
  "sessionKey": "agent:bridge-protocol:hook:bridge:run-123",
  "result": "{\"type\":\"run_handoff_result\",\"status\":\"ok\"}"
}

Suggested behavior:

  • waitForResult=false → keep current async behavior
  • waitForResult=true → wait for completion and return a narrow machine-readable result
  • announceToMain=false → suppress the current summary-to-main behavior for machine-callback use cases

This request is not asking to default-enable sessions_send over HTTP.

Alternatives considered

  1. /hooks/agent + sessions_history

    • works, but awkward and polling-oriented
  2. Re-enable sessions_send over HTTP

    • possible locally, but works against the current security posture
    • also exposes broader semantics than needed
  3. Custom plugin / local fork

    • possible, but this seems generic enough to deserve a first-class API

Impact

Affected users:

  • automation-heavy deployments
  • external runner integrations
  • orchestration / callback workflows

Severity:

  • medium to high for these use cases

Consequence:

  • extra glue code
  • noisy main-session summaries for machine-only flows
  • pressure to use stitched-together polling or local security exceptions

Evidence/examples

Relevant current behavior:

  • /hooks/agent already provides authenticated isolated agent ingress
  • /tools/invoke intentionally blocks sessions_send by default
  • simple protocol-style responses can already be recovered via sessions_history
  • what is missing is a first-class machine result path

Related, but not identical:

  • #18237
  • #43454

Additional information

A minimal solution would be to add this as an opt-in extension to /hooks/agent, while keeping the existing hook security model unchanged:

  • hooks.token
  • hooks.allowedAgentIds
  • hooks.defaultSessionKey
  • hooks.allowedSessionKeyPrefixes

I’d be happy to help test or refine the API shape if this direction makes sense.

extent analysis

Fix Plan

To implement the proposed solution, follow these steps:

  • Update the /hooks/agent endpoint to accept the new optional parameters:
    • waitForResult
    • timeoutSeconds
    • resultMode
    • announceToMain
  • Modify the endpoint logic to handle the new parameters:
    • If waitForResult is true, wait for the task completion and return the result
    • If waitForResult is false or not provided, keep the current async behavior
  • Implement the result mode handling:
    • resultMode can be set to assistant_text or other supported modes
    • Return the result in the specified format
  • Update the response format to include the result:
    • Add a result field to the response JSON
    • Include the task status and other relevant information

Example code snippet (in Python):

from flask import request, jsonify

@app.route('/hooks/agent', methods=['POST'])
def agent_hook():
    data = request.get_json()
    wait_for_result = data.get('waitForResult', False)
    timeout_seconds = data.get('timeoutSeconds', 30)
    result_mode = data.get('resultMode', 'assistant_text')
    announce_to_main = data.get('announceToMain', True)

    # Process the task
    task_id = process_task(data)

    if wait_for_result:
        # Wait for task completion and return the result
        result = wait_for_task_completion(task_id, timeout_seconds)
        return jsonify({
            'ok': True,
            'status': 'completed',
            'runId': task_id,
            'sessionKey': data['sessionKey'],
            'result': format_result(result, result_mode)
        })
    else:
        # Keep the current async behavior
        return jsonify({
            'ok': True,
            'status': 'accepted'
        })

def format_result(result, result_mode):
    if result_mode == 'assistant_text':
        return {'type': 'run_handoff_result', 'status': 'ok'}
    # Add support for other result modes as needed

Verification

To verify the fix, test the /hooks/agent endpoint with different scenarios:

  • Send a request with waitForResult set to true and verify that the response includes the result
  • Send a request with waitForResult set to false and verify that the response is async
  • Test the different result modes and verify that the response format is correct

Extra Tips

  • Make sure to update the API documentation to reflect the new parameters and behavior
  • Consider adding error handling for cases where the task completion times out or fails
  • Test the fix thoroughly to ensure that it works correctly in different scenarios and edge cases.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING