docs: add external task trigger integration example - #1170
Conversation
- Add scripts/external-task-trigger.py: adapter that bridges structured JSON tasks into AgentTeams via the existing Matrix-based Manager submission path (reuses scripts/replay-task.sh) - Generate task_id and trace_id for per-submission correlation - Preserve external_job_id from input metadata through to output - Support --dry-run mode for testing without Matrix/LLM - Add scripts/example-task.json: example structured task input - Add tests/test_external_task_trigger.py: 25 deterministic tests covering validation, ID generation, message building, dry-run, error handling, and traceability - Add docs/usage/integrations/external-task-trigger.md: documentation explaining the integration pattern, usage, schema, and limitations This is a documentation and example contribution only; it does not modify AgentTeams core runtime, Matrix protocol, or Manager semantics.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Adds a documented example + Python adapter (scripts/external-task-trigger.py) that bridges structured external job envelopes into AgentTeams via the existing Matrix/replay-task.sh Manager submission path, with task/trace IDs, validation, dry-run, and tests. Scope and structure are good and there are no credential issues, but there are a few correctness/accuracy items worth addressing before merge (see inline comments).
Findings
- [Warning] scripts/external-task-trigger.py:85 — dry-run returns a JSON-encoded string, so the output
resultfield becomes nested JSON instead of the documented plain text. - [Warning] scripts/external-task-trigger.py:205 —
main()'sexceptis effectively unreachable; unexpected exceptions escape as a raw traceback, breaking the JSON output contract. - [Warning] docs/.../external-task-trigger.md:60 — live mode depends on
replay-task.sh, whose hardcodedopenclaw gateway healthcheck only works with the OpenClaw Manager runtime. - [Info] docs/.../external-task-trigger.md:129 —
[EXTERNAL_TASK]is a text convention, not a Manager protocol; worth stating explicitly. - [Warning] docs/.../external-task-trigger.md:155 — docs claim 'Shell syntax and Python compilation checks' coverage that doesn't exist; subprocess/
--no-waitpaths are untested.
Suggestions
Return dry-run text directly from run_replay(); catch Exception in main() and emit a JSON error; add a runtime note (or runtime-aware readiness check) for live mode; soften the [EXTERNAL_TASK] wording to 'convention'; and align the 'Tests cover' list with what tests/test_external_task_trigger.py actually exercises.
Automated review by github-manager-bot
|
|
||
| def run_replay(message, dry_run=False, no_wait=False): | ||
| if dry_run: | ||
| return json.dumps({ |
There was a problem hiding this comment.
Dry-run mode returns a JSON-encoded string from run_replay(), so in run_task() (line ~148-150) the output's result field ends up containing a nested JSON string instead of the plain text shown in the documented output schema. Consider returning the dry-run text directly and letting run_task set the status.
| dry_run=args.dry_run, | ||
| no_wait=args.no_wait, | ||
| ) | ||
| except (ValueError, FileNotFoundError) as e: |
There was a problem hiding this comment.
run_task() already catches ValueError/FileNotFoundError/JSONDecodeError (line ~121) and the replay call is wrapped in a generic except Exception (line ~135), so this except block in main() is effectively unreachable for those types, while any other unexpected exception would surface as a raw Python traceback and break the script's JSON-output contract. Consider catching Exception here and emitting a JSON error object.
| python3 scripts/external-task-trigger.py --task scripts/example-task.json | ||
| ``` | ||
|
|
||
| This uses `scripts/replay-task.sh` to authenticate via Matrix, find or create the DM room with the Manager, send the task, and wait for the Manager's reply. |
There was a problem hiding this comment.
Live mode relies on scripts/replay-task.sh, which hardcodes an openclaw gateway health readiness check (see replay-task.sh line ~328), so it only works when the Manager runs the OpenClaw runtime. Since other Manager runtimes (qwenpaw/copaw) are common, the documented live mode may fail out of the box. Suggest adding a note about this limitation or making the readiness check runtime-aware.
| The adapter script converts the structured task into a deterministic, parseable message for the Manager: | ||
|
|
||
| ``` | ||
| [EXTERNAL_TASK] |
There was a problem hiding this comment.
The [EXTERNAL_TASK] envelope could be read as a Manager-understandable protocol, but the Manager has no special parser for this tag — it is a plain Matrix text message (as line 143 notes). Worth clarifying explicitly that this is a suggested human/LLM-readable convention, not a core AgentTeams protocol.
| python3 -m unittest tests.test_external_task_trigger -v | ||
| ``` | ||
|
|
||
| Tests cover: |
There was a problem hiding this comment.
The docs claim the tests cover 'Shell syntax and Python compilation checks', but no such tests exist in tests/test_external_task_trigger.py. The suite also does not exercise the subprocess invocation of replay-task.sh or the --no-wait code path, leaving the integration boundary untested. Suggest updating the claims and/or adding coverage for those paths.
Summary
Changes
scripts/external-task-trigger.py(~160 lines)scripts/replay-task.shfor Matrix transport — no new Matrix client--dry-runmode (no Matrix/LLM needed)--no-waitmode for fire-and-forget submission{task_id, trace_id, status, result, external_job_id, submitted_at}scripts/example-task.jsontests/test_external_task_trigger.py(25 tests)docs/usage/integrations/external-task-trigger.mdArchitecture
Testing
Scope
This is a documentation and example-only contribution. It does NOT modify:
It demonstrates how an external backend (CRM, ticket system, workflow engine) can bridge structured jobs into the existing Manager-centered Matrix workflow.
Issue Reference
Addresses one item from Issue #1132: "Enterprise workflow feedback — programmable Manager dispatch, external trigger API, and governance primitives".