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+). Run pip show litellm to verify. PyPI · README

Hooks

Hook system in AgenticX.

Hook System

Hooks intercept LLM and tool calls without forking the runtime. Use them for guardrails, logging, and policy. They are not skills and not MCP servers.

Two layers:

Diagram: pre_tool_guard only runs if tool:before_call is dispatched.

Worked example: confirm a risky shell

Scene. The model wants bash_exec on a destructive command.

  1. Permissions are Ask Every Time or an allowlist that does not include this command.
  2. Runtime emits tool:before_call. Bundled pre_tool_guard can block merged rm -rf flags. A quoted commit message must not match.
  3. Near should show an in-app confirm (themed dialog), not a bare window.confirm. Choose Allow / Deny. Run Everything must stick — no second popup for the same class of call.

What you should see. A dialog over a folded bash_exec card, countdown if the gate has one. After deny, the tool result explains the block; the chat continues.

In-app confirm over a shell tool card
Near confirm dialog: Cancel or Confirm, with the policy for this step.

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