Hook System Deep Dive¶
Overview¶
Mozaiks uses hooks.yaml for AG2 beta prompt injection. The only canonical workflow hook type is update_agent_state.
Canonical declarations live in:
workflows/{workflow}/hooks.yaml
Builder workflows use the same contract under factory_app/workflows/{workflow}/hooks.yaml.
Workflow hook JSON files are not part of the runtime contract.
Supported Hook Types¶
hooks.yaml supports update_agent_state only.
Declarative Contract¶
hooks:
- hook_type: update_agent_state
hook_agent: PlannerAgent
filename: hook_inject_plan.py
function: inject_plan_state
Fields are required per entry:
hook_typehook_agentfilenamefunction
Runtime Registration Model¶
load_hook_entries()reads and validateshooks.yaml.create_agents()resolvesupdate_agent_statefunctions before beta agent construction.MozaiksHookPolicyruns those functions before each AG2agent.ask()call.- If a hook calls
agent.update_system_message(...), that message becomes the prompt for the current turn.
Execution Timing¶
update_agent_state runs before agent reply generation. It is for context injection, prompt guards, and deterministic runtime guidance. Message transforms, output validation, persistence, and side effects belong in structured outputs, lifecycle tools, runtime validators, or ordinary tools.
Troubleshooting¶
If a hook does not fire:
- Verify the
hooks.yamlentry validates. - Confirm
hook_agentexactly matches the runtime agent name. - Confirm
filenameandfunctionresolve to an importable callable. - Confirm the hook calls
agent.update_system_message(...)when it needs to change the current-turn prompt.