#21035: feat: agent hardening — modifying after_tool_call hook, cron context & quality gate, subagent verify/poll tools
docs
agents
size: L
Cluster:
Subagent Enhancements and Features
## 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
#18860: feat(agents): expose tools and their schemas via new after_tools_re...
by lan17 · 2026-02-17
78.5%
#18889: feat(hooks): add agent and tool lifecycle boundaries
by vincentkoc · 2026-02-17
75.2%
#16565: feat: Add tool_invocation provenance for A2A tool calls
by mdlmarkham · 2026-02-14
75.1%
#19422: fix: pass session context to plugin tool hooks in toToolDefinitions
by namabile · 2026-02-17
74.7%
#21136: fix(security): harden agent autonomy controls
by novalis133 · 2026-02-19
74.5%
#9049: fix: prevent subagent stuck loops and ensure user feedback
by maxtongwang · 2026-02-04
74.4%
#16028: feat/before-tool-result
by ambushalgorithm · 2026-02-14
73.4%
#14873: [Feature]: Extend before_agent_start hook context with Model, Tools...
by akv2011 · 2026-02-12
73.2%
#7525: Agents: skip errored tool calls during pairing
by justinhuangcode · 2026-02-02
72.8%
#22624: feat(plugins): add before_context_send hook and model routing via b...
by davidrudduck · 2026-02-21
72.7%