Skills Plugins MCP Prompt Model 博客 我的中心

agent-runtime-hooks

Use for agent lifecycle hooks, tool mocks, intervention, sub-agent calls and context compression.

DeepseekModel 官方收录技能 质量 优秀 · 90 v1.0.0

获取

https://deepseekmodel.com/api/download.php?id=lobehub-lobehub-agents-skills-agent-runtime-hooks-skill-md&format=skill
下载 .skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用
.skill 文件中 system_prompt 字段的实际内容。
name agent-runtime-hooks description Use for agent lifecycle hooks, tool mocks, intervention, sub-agent calls and context compression. user-invocable false Agent Runtime Hooks Lifecycle hooks for observing and intercepting agent execution. Hooks are registered per-operation via execAgent({ hooks }) and dispatched by HookDispatcher . Hook Types 16 hook types across 5 categories: execAgent({ hooks }) │ ├─ beforeStep ──────────── Before each step executes │ │ │ ├─ [call_llm] LLM inference │ │ │ ├─ [call_tool] │ │ ├─ beforeToolCall ── Before tool executes (supports mocking) │ │ ├─ (tool execution) │ │ ├─ afterToolCall ─── After tool completes (observation only) │ │ └─ onToolCallError ─ Tool threw an exception │ │ │ ├─ [request_human_approve] │ │ ├─ beforeHumanIntervention ── Before agent pauses │ │ ├─ afterHumanIntervention ─── After approve/reject + resume │ │ └─ onStopByHumanIntervention ── User rejected, agent halted │ │ │ ├─ [compress_context] │ │ ├─ beforeCompact ──── Before compression starts │ │ ├─ afterCompact ───── After compression completes │ │ └─ onCompactError ─── Compression failed │ │ │ ├─ [callAgent] (via execSubAgentTask) │ │ ├─ beforeCallAgent ── Before sub-agent starts │ │ ├─ afterCallAgent ─── After sub-agent completes │ │ └─ onCallAgentError ── Sub-agent failed │ │ │ └─ afterStep ──────────── After step completes │ ├─ (next step...) │ ├─ onComplete ───────────── Operation reaches terminal state └─ onError ──────────────── Error during execution Key Files File Role packages/agent-runtime/src/types/hooks.ts Type definitions (AgentHookType, all event interfaces) apps/server/src/services/agentRuntime/hooks/types.ts Server-side types (AgentHook, re-exports) apps/server/src/services/agentRuntime/hooks/HookDispatcher.ts Registration, dispatch, dispatchBeforeToolCall apps/server/src/modules/AgentRuntime/RuntimeExecutors.ts Tool/Compact/HumanIntervention hook dispatch apps/server/src/services/agentRuntime/AgentRuntimeService.ts Step hooks + HumanIntervention resume/reject apps/server/src/services/aiAgent/subAgentRuns.ts CallAgent hook dispatch Registration Flow const hooks : AgentHook [] = [ { id : 'my-hook' , type : 'afterStep' , handler : async (event) => { ... } }, ]; await aiAgentService. execAgent ({ agentId, prompt, hooks }); // Internally: hookDispatcher.register(operationId, hooks) // Cleanup: hookDispatcher.unregister(operationId) Hook Reference Step Level beforeStep — Before each step. event: AgentHookEvent afterStep — After each step. event: AgentHookEvent (content, toolsCalling, totalCost, etc.) onComplete — Terminal state. event: AgentHookEvent (reason: done/error/interrupted/max_steps/cost_limit) onError — Error occurred. event: AgentHookEvent (errorMessage, errorDetail) Tool Call Level beforeToolCall — Before tool executes. Supports mocking via event.mock() . // event: ToolCallHookEvent { (identifier, apiName, args, callIndex, stepIndex, operationId, mock); } // Mock example: event. mock ({ content : '{"error":"rate limited"}' }); Dispatch method: hookDispatcher.dispatchBeforeToolCall() (returns mock result or null). afterToolCall — After tool completes. Observation only. // event: AfterToolCallHookEvent { (identifier, apiName, args, callIndex, content, success, mocked, executionTimeMs, stepIndex); } onToolCallError — Tool threw an exception (catch block, not just success=false ). // event: ToolCallErrorHookEvent { (identifier, apiName, args, callIndex, error, stepIndex); } Human Intervention beforeHumanIntervention — Before agent pauses for approval. // event: BeforeHumanInterventionHookEvent { operationId, stepIndex, pendingTools : [{ identifier, apiName }] } afterHumanIntervention — After approve/reject, agent resumes. // event: AfterHumanInterventionHookEvent { operationId, action : 'approve' | 'reject' | 'rejectAndContinue' , toolCallId?, rejectionReason? } onStopByHumanIntervention — User rejected, agent halted. // event: StopByHumanInterventionHookEvent { operationId, toolCallId?, rejectionReason? } Context Compression beforeCompact — Before compression starts. // event: BeforeCompactHookEvent { (operationId, stepIndex, messageCount, tokenCount); } afterCompact — After compression completes. // event: AfterCompactHookEvent { (operationId, stepIndex, groupId, messagesBefore, messagesAfter, summary); } onCompactError — Compression failed. // event: CompactErrorHookEvent { (operationId, stepIndex, tokenCount, error); } Sub-Agent (CallAgent) beforeCallAgent — Before calling sub-agent. Dispatched on parent operation. // event: BeforeCallAgentHookEvent { (operationId, agentId, instruction); } afterCallAgent — Sub-agent completed. Dispatched on parent operation. // event: AfterCallAgentHookEvent { (operationId, agentId, subOperationId, threadId, success); } onCallAgentError — Sub-agent failed. Dispatched on parent operation. // event: CallAgentErrorHookEvent { (operationId, agentId, error); } Note: CallAgent hooks require parentOperationId in ExecSubAgentTaskParams . Design Notes Fire-and-forget : All handlers return Promise<void> . Errors are non-fatal. Exception : beforeToolCall supports mock via event.mock() — uses dispatchBeforeToolCall() which returns the mock result. Sequential : Same-type hooks run in registration order. Local only : beforeToolCall mock only works in local mode (in-memory hooks). Webhook mode does not support mocking. Scoped per operation : Auto-cleaned via hookDispatcher.unregister() on completion. Sandbox/MCP : No separate hooks — they go through executeTool , so beforeToolCall / afterToolCall cover them. Use event.identifier to filter. Real-World Example: agent-evals See devtools/agent-evals/helpers/runner.ts — createEvalHooks() uses afterStep , onComplete , afterToolCall , and beforeToolCall (for mock).
Agent 识别该技能的关键词,点击任意一个即可复制。

该技能未提供触发词。

下载的 .skill 包内含以下字段。
字段 说明
format格式标识(skill/v1)
skill_id技能唯一 ID
name技能名称
version版本号
description技能描述
category所属分类(数组)
trigger_words触发词列表
tags标签列表
source来源标识
source_url来源链接(本页地址)
exported_at导出时间(每次下载生成)
system_prompt系统提示词正文
model_config模型参数:provider / model / temperature / max_tokens / top_p
examples示例
install_guide各平台导入说明(Coze / Dify / Claude / 自定义框架)
同一份技能可按不同平台格式导出。
.skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用 下载
.skillpro 增强格式,额外含脚本 / 工具 / 依赖 / 钩子占位 下载
.json 纯 JSON 导出,只含 system_prompt 与模型参数 下载
Coze 带 frontmatter 的 Markdown,Coze 平台导入用 下载
Dify Dify DSL,创建应用后直接导入 下载

每日精选 Skill 推荐,免费送到你邮箱

输入邮箱,每天接收一个精选 AI Agent 技能推荐。完全免费,持续更新。

提交后我们会发送一封确认邮件,点击邮件里的链接才会开始收信。

完全免费,取消任意时间。我们不会发送垃圾邮件。