agents.base.mixins.hooks_mixin¶
Enhanced hooks mixin for the Haive framework.
from typing import Any Provides a flexible hooks system that can be used by both single and multi agents, with support for different hook points and graph-aware modifications.
Classes¶
Mixin that provides comprehensive hooks functionality. |
Functions¶
|
Decorator for marking methods as hooks. |
Module Contents¶
- class agents.base.mixins.hooks_mixin.HooksMixin(**kwargs)¶
Bases:
Generic
[haive.agents.base.types.TState
]Mixin that provides comprehensive hooks functionality.
This mixin is generic over the state type, allowing hooks to be type-safe with respect to the agent’s state schema.
Initialize hooks storage.
- clear_hook_results()¶
Clear all stored hook results.
- Return type:
None
- disable_hooks()¶
Disable hook execution.
- Return type:
None
- enable_hooks()¶
Enable hook execution.
- Return type:
None
- get_hook_result(point, hook_name)¶
Get stored result from a previous hook execution.
- Parameters:
point (haive.agents.base.types.HookPoint)
hook_name (str)
- Return type:
Any
- register_hook(point, hook, priority=0, name=None, graph_aware=False, condition=None)¶
Register a hook with enhanced capabilities.
- Parameters:
point (haive.agents.base.types.HookPoint) – Hook point to register at
hook (collections.abc.Callable) – Hook function to call
priority (int) – Execution priority (higher = earlier)
name (str | None) – Optional hook name
graph_aware (bool) – Whether hook needs graph context
condition (collections.abc.Callable[[HooksMixin, haive.agents.base.types.HookContext[haive.agents.base.types.TState]], bool] | None) – Optional condition function
- Return type:
None
- run_hooks(point, *args, context=None, **kwargs)¶
Run hooks for a specific point with enhanced context.
- Returns:
Last non-None result from hooks, or None
- Parameters:
point (haive.agents.base.types.HookPoint)
context (haive.agents.base.types.HookContext[haive.agents.base.types.TState] | None)
- Return type:
Any
- unregister_hook(point, hook=None)¶
Unregister one or all hooks at a point.
- Parameters:
point (haive.agents.base.types.HookPoint)
hook (collections.abc.Callable | str | None)
- Return type:
None
- agents.base.mixins.hooks_mixin.hook(point, priority=0, name=None, graph_aware=False, condition=None)¶
Decorator for marking methods as hooks.
- Usage:
@hook(HookPoint.AFTER_GRAPH_BUILD, priority=10) def add_output_parser(self, graph, context):
# Modify graph return graph
- Parameters:
point (haive.agents.base.types.HookPoint)
priority (int)
name (str | None)
graph_aware (bool)
condition (collections.abc.Callable | None)