← Back to PRs

#21035: feat: agent hardening — modifying after_tool_call hook, cron context & quality gate, subagent verify/poll tools

by roelven open 2026-02-19 15:46 View on GitHub →
docs agents size: L
## Summary This PR improves agent reliability across three areas: - **Modifying `after_tool_call` hook** — The hook now supports returning `{ appendContent }` so plugins can inject extra text into tool results the LLM sees (without mutating persisted messages). This is the foundation for plugins like [verify-tool-output](https://github.com/roelven/openclaw-agent-plugins/tree/main/verify-tool-output) that nudge agents to verify their work. - **Cron self-contained context & output quality gate** — Cron jobs now inject a `[CRON_JOB_SPEC]` block with full job metadata (schedule, last run, delivery target, task) so the agent has context even after compaction. A configurable quality gate checks output before delivery — blocks too-short, too-long, or degraded responses (e.g. "I don't have enough context"). - **Subagent verification tools** — New `sessions_verify` and `sessions_poll` tools let the parent agent check subagent completion, artifacts, and transcript patterns. ## Changes | File | What | |------|------| | `src/plugins/types.ts` | New `PluginHookAfterToolCallResult` type with `appendContent` | | `src/plugins/hooks.ts` | `runAfterToolCall` now uses `runModifyingHook` and merges `appendContent` | | `src/agents/pi-tool-definition-adapter.ts` | Consumes hook result, appends content to tool result | | `src/config/types.cron.ts` | New `CronQualityCheckConfig` type | | `src/cron/isolated-agent/run.ts` | `buildCronJobSpec()`, `formatSchedule()`, `checkCronOutputQuality()`, quality gate integration | | `src/agents/tools/sessions-verify-tool.ts` | New tool — completion + artifact + transcript checks | | `src/agents/tools/sessions-poll-tool.ts` | New tool — lightweight in-memory status poll | | `src/agents/openclaw-tools.ts` | Register new tools | | `src/agents/tools/cron-tool.test-harness.ts` | Add explicit MockFn type annotation | ## Companion plugins These core changes enable a set of community plugins published separately: [openclaw-agent-plugins](https://github.com/roelven/openclaw-agent-plugins) - **sanitize-tool-results** — Fixes malformed tool blocks, truncates oversized results, strips ANSI - **verify-tool-output** — Injects `[VERIFY]` hints after exec/write/cron calls (uses the `appendContent` hook from this PR) - **session-scorer** — Scores sessions on accuracy, completeness, autonomy, consistency - **event-stream** — Streams JSON events over Unix socket for monitoring ## Test plan - [x] All existing tests pass (`pnpm test:fast`) - [x] Build passes (`pnpm build`) - [x] Linting passes (`oxlint && oxfmt --check`) - [ ] Cron jobs include `[CRON_JOB_SPEC]` block in transcript (manual testing) - [ ] Quality gate blocks degraded cron output, allows heartbeats through (manual testing) - [ ] `sessions_poll` returns status for running/completed subagents (manual testing) - [ ] `sessions_verify` checks artifacts and transcript patterns (manual testing) - [ ] `verify-tool-output` plugin appends hints via `appendContent` (manual testing) ## AI Assistance This PR was developed with Claude Code assistance. Testing degree: **lightly tested** — core functionality is unit tested and all existing tests pass, but end-to-end integration testing with actual agent runs is pending. 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Most Similar PRs