agent-runtime-hooks

Execute arbitrary code before or after AI agent lifecycle events.

Updated Jul 5, 2026
One-click install
npx skills add https://github.com/xkl2013/lobe --skill agent-runtime-hooks-xkl2013
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: agent-runtime-hooks
Source: https://github.com/xkl2013/lobe/tree/main/.agents/skills/agent-runtime-hooks
Command: npx skills add https://github.com/xkl2013/lobe --skill agent-runtime-hooks-xkl2013

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides fine-grained control over the lifecycle of AI agents, allowing users to hook into key points during execution to perform various operations like tool execution, human intervention, context compression, sub-agent calls, and more.

Core Features & Use Cases

  • Custom Hooks: Register custom hooks for before/after tool execution, human intervention, context compression, sub-agent calls, and more.
  • Operation Tracking: Track and analyze agent execution through hooks that trigger at specific lifecycle events.
  • Error Handling: Catch errors during tool execution and human intervention with on-callback hooks.
  • Use Case: Imagine you want to add logging for each step of an agent's execution. You can define a beforeStep hook to log before each step is executed.

Quick Start

To create a custom hook, define the hook type and handler in the SKILL.md file and then use execAgent to register it.

Frequently Asked Questions about agent-runtime-hooks

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

FAQPage Schema
How do I add lifecycle hooks to an AI agent to run custom code before or after tool execution?

AI agent lifecycle hooks let you execute arbitrary code at key execution points by defining hook types and handlers in SKILL.md and registering them via execAgent, covering beforeStep, afterStep, and tool call boundaries.

Can I catch and handle errors during AI agent tool execution or human intervention?

Yes, you can catch errors during tool execution and human intervention by registering onToolCallError, onCallAgentError, and onCompactError hooks to handle exceptions at specific lifecycle events.

What events are available for context compression and sub-agent calls in an AI agent lifecycle?

Available events for context compression and sub-agent calls include beforeCompact, afterCompact, onCompactError, beforeCallAgent, afterCallAgent, and onCallAgentError hooks to control execution flow.

How do I track and log each step of an AI agent's execution flow?

You can track and log each step of an AI agent's execution flow by defining a beforeStep hook to trigger logging operations before each step is executed during the agent lifecycle.

Do I need any specific dependencies to set up human intervention hooks for my AI agent?

No specific dependencies are required to set up human intervention hooks. You can register beforeHumanIntervention, afterHumanIntervention, and onStopByHumanIntervention handlers directly within your agent environment.