agentsclimarketplace

Agent lifecycle hooks

Skill kjuhwa/skills-hub/skills/agents/agent-lifecycle-hooks

Attach RunHooks and AgentHooks to observe and react to agent lifecycle events.From its SKILL.md

Install
npx -y skills add kjuhwa/skills-hub --skill agent-lifecycle-hooks

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.3 KB, 450 tokens by cl100k_base, as published. Nobody here has run it

agent-lifecycle-hooks

Implement RunHooks (run-level) or AgentHooks (agent-level) to observe agent start/end, LLM calls, tool calls, and handoffs. Pass hooks to Runner.run(hooks=...) or Agent(hooks=...).

When to apply

Logging, usage tracking, debugging, or triggering side effects (e.g., saving state) at each lifecycle step. Alternative to custom tracing processors for lightweight observation.

Core snippet

from agents import Agent, RunHooks, AgentHooks, RunContextWrapper, AgentHookContext, Tool, Runner

class ExampleHooks(RunHooks):
    async def on_agent_start(self, context: AgentHookContext, agent: Agent) -> None:
        print(f"Agent {agent.name} started. Input: {context.turn_input}")

    async def on_agent_end(self, context: RunContextWrapper, agent: Agent, output) -> None:
        print(f"Agent {agent.name} ended with: {output}")

    async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
        print(f"Tool {tool.name} called")

    async def on_tool_end(self, context: RunContextWrapper, agent: Agent, tool: Tool, result: str) -> None:
        print(f"Tool {tool.name} result: {result}")

    async def on_handoff(self, context: RunContextWrapper, from_agent: Agent, to_agent: Agent) -> None:
        print(f"Handoff: {from_agent.name} -> {to_agent.name}")

hooks = ExampleHooks()

async def main():
    agent = Agent(name="Assistant", instructions="Be helpful.")
    result = await Runner.run(agent, "Hello!", hooks=hooks)

Key notes

  • RunHooks applies to the entire run; AgentHooks scopes to a single agent
  • on_tool_start/end only fires for local function tools, not hosted tools
  • context.usage tracks cumulative token usage across the run
  • context.turn_input in on_agent_start gives the agent's current input

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,144. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.