Security advisory — Malicious litellm versions 1.82.7 and 1.82.8 were removed from PyPI (potential API key exfiltration). Uninstall them, rotate exposed credentials, and upgrade to a safe release (e.g. 1.82.9+ per upstream). Run pip show litellm to verify. PyPI · README

Hooks

Hook system in AgenticX.

Hook System

Overview

AgenticX exposes two hook layers for different execution surfaces:

LayerPackage pathPurpose
Core hooksagenticx/core/hooks/Synchronous interception around LLM and tool calls
Runtime hooksagenticx/runtime/hooks/Async lifecycle hooks on `AgentRuntime`

Core Hooks (`agenticx/core/hooks/`)

Core hooks are plain callables registered globally or on an `Agent` instance.

LLM hooks

Context type: `LLMCallHookContext`.

Before call fields:

FieldDescription
agent_idAgent identifier
task_idOptional task id
messagesMessage list (may be mutated)
modelOptional model name
temperatureOptional sampling temperature
max_tokensOptional cap
iterationLoop iteration index

Registration:

python
1from agenticx.core.hooks import (
2 LLMCallHookContext,
3 register_before_llm_call_hook,
4 register_after_llm_call_hook,
5)
6
7def log_before_llm(ctx: LLMCallHookContext) -> bool:
8 # Mutate ctx.messages in place if needed
9 return True # False blocks the LLM call
10
11register_before_llm_call_hook(log_before_llm)

Tool hooks

Context type: `ToolCallHookContext`.

Before call fields:

FieldDescription
agent_idAgent identifier
tool_nameTool being invoked
tool_argsArgument dict (may be mutated)
iterationLoop iteration

Runtime Hooks (`agenticx/runtime/hooks/`)

Runtime hooks are async methods on subclasses of `AgentHook`, coordinated by `HookRegistry`.

`AgentHook` base class

MethodRole
before_model(messages, session)Transform message sequence before LLM call
after_model(response, session)Observe or side-effect after model returns
before_tool_call(tool_name, arguments, session)Return HookOutcome(blocked=True) to veto
after_tool_call(tool_name, result, session)Replace tool result string
on_compaction(compacted_count, summary, session)After context compaction
on_agent_end(final_text, session)End of agent turn

`HookOutcome`

python
1@dataclass
2class HookOutcome:
3 blocked: bool = False
4 reason: str = ""

Example: block a tool

python
1from agenticx.runtime.hooks import AgentHook, HookOutcome
2
3class DenyShellHook(AgentHook):
4 async def before_tool_call(self, tool_name, arguments, session):
5 if tool_name in {"run_terminal_cmd", "bash"}:
6 return HookOutcome(blocked=True, reason="Shell tools disabled")
7 return None
8
9runtime.hooks.register(DenyShellHook(), priority=100)

Core vs Runtime hooks

AspectCoreRuntime
Execution modelSynchronous callablesasync methods on AgentHook
Block LLMbefore hook returns FalseTransform in before_model
Block toolbefore hook returns FalseHookOutcome(blocked=True)
RegistryModule-level lists + Agent.llm_hooksHookRegistry with numeric priority
Typical usesLogging, policy, rewritingStreaming lifecycle, memory hooks