Guide
Why are imported Rasa response hooks skipped?
Find out why Rasa skips an imported response hook, then register a local wrapper and test the callback the loader returns.
Key takeaways (3)
- Check that the runtime discovers a hook after importing it.
- Keep shared policy in a library and give the loader a local decorated entry point.
- Test discovery and invoke the returned callback before checking a live agent.
If a banking tool has already sent its message, you want your Rasa assistant to avoid adding a second reply. This example uses a response hook to remove duplicate text from the response payload.
The function worked in a direct offline call. Importing that same function into the hook file left Rasa’s loader with nothing to register. We repeated the comparison with the pinned Rasa package.

The distinction is where the function was defined. This loader accepts decorated functions defined in the module it loads. Importing a function leaves its original module attached to it.
Adding a local decorated wrapper changed registration from zero modifiers to one. The callback returned by discovery then cleared the supplied duplicate text and returned a listen tool call.
A direct call can pass while discovery finds nothing
We compared two hook files while keeping the same decorated library function in both. One imports that function. The other adds a decorated wrapper defined in the hook file. Each arrangement runs in a separate process against the actual pinned Rasa Pro software development kit.
| Hook arrangement | Direct library call | Loader discovers | Returned callback |
|---|---|---|---|
| Import the decorated library function | Clears text; returns listen | 0 modifiers | None to invoke |
| Define a local decorated wrapper | Clears text; returns listen | 1 modifier | Clears text; returns listen |
The comparison supplies a delivered-reply marker and duplicate text. A successful policy call clears that text and leaves a listen tool call. That is presentation control for a supplied payload, not a recorded conversation.
Why importing does not change ownership
The pinned loader first identifies functions marked as hooks. It then compares each function’s __module__ with the loaded module’s __name__. When they differ, it logs skipped_imported_hook and leaves that function out of the registry.
An import binds the existing function to a name in another module. It does not redefine the function there. Its __module__ still names the library where it was defined. The local wrapper is a new function, so its module matches the one being inspected.
This rule comes from rasa/mantle/hooks/loader.py in Rasa Pro 3.21.0.dev5. To inspect it or repeat the comparison below, first prepare the captured project. You need Git, uv and Python 3.12. From a directory where you can create a new checkout, run:
git clone --no-checkout https://github.com/RasaHQ/rasa-community-resources.git hook-component-check
cd hook-component-check
git fetch origin b5a308ecd9acdc795ce56260ec81c21c879aa9c7
git checkout --detach b5a308ecd9acdc795ce56260ec81c21c879aa9c7
cd examples/jack-henry-silverlake
uv sync --locked
Keep this example directory as your working directory for every Python command below. It contains pyproject.toml, uv.lock and the resulting .venv. If dependency installation fails, resolve its package or Python-version error first. The pinned README covers the full demo; the hook comparison uses its installed package without starting the demo server.
Now inspect the ownership check in that locked package:
.venv/bin/python -c 'import inspect; from rasa.mantle.hooks.loader import _hooks_defined_in_module; print(inspect.getsource(_hooks_defined_in_module))'
The inspection command prints the loader’s function definition. If .venv/bin/python is missing, check your working directory and finish the locked install. If the import fails, use the first import error to check that environment before running the probe.
The local-wrapper arrangement still logs a skipped import for the library function. The wrapper is what adds the discovered callback. Simply making the skipped event disappear is not the test.

The import changes which module can refer to the function. Its definition module stays the same. The local wrapper has its own definition module, so discovery can register that entry point while the policy remains shared.
Give the loader a local entry point
The original hook file imports the policy:
from lib.reply_policy import keep_host_reply_once
The current wrapper defines and decorates a local function:
# SPDX-License-Identifier: MIT
"""Register the local host-reply policy with the runtime hook loader."""
from rasa.mantle.hooks import modify_model_response
from rasa.mantle.hooks.payloads import ModelResponsePayload
from lib.reply_policy import keep_host_reply_once
@modify_model_response()
async def banking_host_reply(payload: ModelResponsePayload) -> ModelResponsePayload:
return await keep_host_reply_once(payload)
Keep shared policy in the library and give discovery its own local entry point. This adds a wrapper whose signature must stay consistent with the policy. In return, registration has a small, visible home without moving the policy body.
The comparison holds the original decorated library constant to isolate that ownership rule. It combines the original import with the current wrapper. It is a new two-arrangement experiment, not a reconstruction of every historical application dependency.
Repeat the comparison in the locked environment
Use the example’s locked environment at the captured source revision. It needs Rasa Pro 3.21.0.dev5. The probe creates temporary hook modules and launches a fresh process for each arrangement.
Download the probe script and fixed source inputs into that example directory, then run:
.venv/bin/python discovery-probe.py discovery-input.json
Both child processes exited successfully. These are their exact result lines, excerpted from the captured log:
RESULT_JSON={"variant": "imported", "directPolicyText": null, "directPolicyTools": ["listen"], "modifierCount": 0, "libraryFunctionModule": "lib.reply_policy"}
RESULT_JSON={"variant": "local-wrapper", "directPolicyText": null, "directPolicyTools": ["listen"], "modifierCount": 1, "libraryFunctionModule": "lib.reply_policy", "discoveredCallbackText": null, "discoveredCallbackTools": ["listen"], "discoveredFunctionModule": "_mantle_hooks_root"}
The machine-readable result also records the input hashes. The quoted lines contain no path redactions.
The existing regression test protects the current wrapper. Its subprocess program checks both registration and the returned callback’s effect.
Show the current regression program
import asyncio
from pathlib import Path
from types import SimpleNamespace
from rasa.mantle.hooks.loader import load_hooks
from rasa.mantle.hooks.payloads import ModelResponsePayload
from rasa.mantle.orchestration.turn_context import _current_turn_ctx
registry=load_hooks(Path.cwd())
assert registry.modifier_count==1
from lib import reply_policy
_current_turn_ctx.set(SimpleNamespace(sender_id="caller",turn=object(),is_cancelled=False))
reply_policy.remember_delivery()
reply=asyncio.run(registry.all_hooks()[0].func(ModelResponsePayload(sender_id="caller",text="duplicate")))
assert reply.text is None
assert [call["tool_name"] for call in reply.tool_calls]==["listen"]The fresh process matters because other snapshot tests evict library modules. The test uses the runtime’s real turn-context variable, then supplies a sender, a turn, and a delivered-reply marker. It requires one modifier before checking the payload.
What these checks establish
The bounded component receipt records a separate current-source run: 77 tests with no declared skips. It includes this loader regression and the audit tying the installed runtime files to the locked wheel. The transfer-classification article uses that same execution. Those are two uses of one run, not independent trials.
The original zero-modifier log and earlier suites remain historical evidence. Their three vendor-input skips are preserved in the earlier continuous integration output excerpt. The excerpt manifest records the original log hash and exact selected lines. The new comparison isolates registration with a fixed library. It does not turn historical skips into passes or recreate the original application in full.
Not claimed: Trained agent, model, voice, vendor, or current global release acceptance.
For your own hook, keep the direct policy checks, add the loader check, and call what the loader returned. A live-agent check comes after registration and needs its own evidence.