agent-runtime-hooks

Register lifecycle hooks to observe and intercept agent execution phases.

1|Updated May 20, 2026
One-click install
npx skills add https://github.com/mDevsLabs/mAI --skill agent-runtime-hooks-mdevslabs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: agent-runtime-hooks
Source: https://github.com/mDevsLabs/mAI/tree/main/.agents/skills/agent-runtime-hooks
Command: npx skills add https://github.com/mDevsLabs/mAI --skill agent-runtime-hooks-mdevslabs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Observability and control over agent execution by providing lifecycle hooks that run before and after steps, tool calls, human interventions, context compression, sub-agent calls, and other lifecycle events.

Core Features & Use Cases

  • Hook types across categories: beforeStep, afterStep, onComplete, onError; beforeToolCall supports mocking; afterToolCall; onToolCallError; beforeHumanIntervention; afterHumanIntervention; onStopByHumanIntervention; beforeCompact; afterCompact; onCompactError; beforeCallAgent; afterCallAgent; onCallAgentError.
  • Use cases include instrumentation, auditing, dynamic behavior modification, graceful error handling and orchestration of complex multi-agent workflows.

Quick Start

Register hooks on an agent by calling aiAgentService.execAgent({ agentId, prompt, hooks }) to attach your observers and handlers and begin monitoring execution.

Frequently Asked Questions about agent-runtime-hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I monitor agent execution lifecycles during runtime?

Agent runtime hooks provide structured lifecycle monitoring by attaching observers to events like beforeStep, afterStep, onComplete, and onError to track execution phases. You register these hooks to intercept and audit agent operations dynamically.

Can I intercept and mock tool calls in an agent workflow?

Yes, tool call interception is supported through beforeToolCall, afterToolCall, and onToolCallError hooks. The beforeToolCall hook specifically supports mocking, allowing you to modify tool behavior dynamically for testing or safe orchestration.

What is the best way to audit sub-agent calls and context compression?

Auditing sub-agent calls and context compression is handled by attaching hooks to beforeCallAgent, afterCallAgent, beforeCompact, and afterCompact events. This enables per-operation monitoring and structured observability for complex multi-agent workflows.

How do you handle human intervention events in agent operations?

Human intervention events are managed using beforeHumanIntervention, afterHumanIntervention, and onStopByHumanIntervention hooks. These lifecycle hooks intercept and log manual overrides, ensuring safe and auditable workflows during agent execution.

Does this agent runtime hook system require external dependencies?

No external dependencies are required to implement agent runtime hooks. The system uses a HookDispatcher to support registration, per-operation scoping, and dispatch, functioning independently to provide extensible instrumentation.

Why do I need lifecycle hooks for multi-agent orchestration?

Lifecycle hooks are needed for multi-agent orchestration to provide graceful error handling, dynamic behavior modification, and structured auditing. They intercept execution across operational phases to ensure safe and controllable workflows.