> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hedera.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Hooks and Policies

> Learn how to use Hooks and Policies to customize tool behavior and enforce business logic in the Hedera Agent Kit.

## Overview

The Hedera Agent Kit provides a flexible and powerful system for putting limits on tool usage and enforcing business logic, effectively enabling you to limit the functionality of AI agents through **Hooks** and **Policies**.

These can be used to enforce security, compliance, and other business rules.

### Concepts

* **Hooks**: Extensions that observe and modify tool execution (logging, tracking, etc.). They are generally non-blocking.
* **Policies**: Specialized hooks that act as validation rules. They can **block** tool execution if certain conditions aren't met.

<Note>
  Hooks and policies are available from **v4** of the JavaScript SDK and from **v3.4.0** of the Python SDK.

  Only tools extending `BaseTool` (JavaScript) or `ToolV2` (Python) support hooks and policies. All core tools provided with the kit support these features by default. While classic tool interfaces continue to be supported for backward compatibility, they do not gain hook or policy support until migrated to the new base classes.

  <Accordion title="Migration Guides">
    **JavaScript**: [Migrating Custom Tools to BaseTool](https://github.com/hashgraph/hedera-agent-kit-js/blob/main/docs/MIGRATION-v4.md#migrating-custom-tools-to-basetool-recommended-non-breaking)

    **Python**: [Python ToolV2 Migration Guide](https://github.com/hashgraph/hedera-agent-kit-py/blob/main/docs/MIGRATION_TO_BASETOOLV2.md)
  </Accordion>
</Note>

***

## Tool Lifecycle

Every tool in the kit follows a standardized 7-stage lifecycle. Hooks and policies can execute at 4 specific points during this lifecycle:

<AccordionGroup>
  <Accordion title="1. Pre-Tool Execution" icon="bolt">
    Before anything happens, when raw parameters are passed.
  </Accordion>

  <Accordion title="2. Post-Parameter Normalization" icon="filter">
    After parameters are validated and cleaned.
  </Accordion>

  <Accordion title="3. Post-Core Action" icon="gears">
    After the main logic (e.g., transaction creation) executes, but before any secondary actions (like submission).
  </Accordion>

  <Accordion title="4. Post-Tool Execution" icon="check-double">
    After everything completes, including transaction signing and submission.
  </Accordion>
</AccordionGroup>

```text theme={null}
[1. Pre-Tool Execution] --------> Hook Stage 1
         |
[2. Parameter Normalization]
         |
[3. Post-Parameter Normalization] --> Hook Stage 2
         |
[4. Core Action]
         |
[5. Post-Core Action] --------------> Hook Stage 3
         |
[6. Secondary Action]
         |
[7. Post-Tool Execution] -----------> Hook Stage 4
         |
[Result Returned]
```

***

## Implementation Guides

Select your preferred SDK to see available hooks and policies, learn how to configure them, or see how to create your own:

<CardGroup cols={2}>
  <Card title="JavaScript SDK" icon="js" href="/solutions/ai/agent-kit/js/create-hooks-and-policies">
    Available Hooks & Policies, configuration, and developer templates for JS/TS.
  </Card>

  <Card title="Python SDK" icon="python" href="/solutions/ai/agent-kit/python/create-hooks-and-policies">
    Available Hooks & Policies, configuration, and developer templates for Python.
  </Card>
</CardGroup>
