{
  "beforeHooks": "# SPDX-License-Identifier: MIT\n\"\"\"Keep the host-delivered banking message as the only reply for its turn.\"\"\"\nfrom lib.reply_policy import keep_host_reply_once\n",
  "afterHooks": "# SPDX-License-Identifier: MIT\n\"\"\"Register the local host-reply policy with the runtime hook loader.\"\"\"\nfrom rasa.mantle.hooks import modify_model_response\nfrom rasa.mantle.hooks.payloads import ModelResponsePayload\nfrom lib.reply_policy import keep_host_reply_once\n\n\n@modify_model_response()\nasync def banking_host_reply(payload: ModelResponsePayload) -> ModelResponsePayload:\n    return await keep_host_reply_once(payload)\n",
  "fixedDecoratedLibrary": "# SPDX-License-Identifier: MIT\n\"\"\"End a banking turn after its host-owned message has actually been delivered.\n\nThis is presentation control, never transfer authority. The host still checks\nconsent and journals the request before sending. Records live for one runtime\nturn only and are not persisted or shared with another example.\n\"\"\"\nfrom collections import OrderedDict\nimport time\nfrom uuid import uuid4\n\nfrom rasa.mantle.hooks import modify_model_response\nfrom rasa.mantle.hooks.payloads import ModelResponsePayload\nfrom rasa.mantle.orchestration.turn_context import current_turn_context\n\n_delivered = OrderedDict()\n_MAX_RECORDS = 128\n_MAX_AGE = 300\n\n\ndef _turn():\n    try:\n        native = current_turn_context()\n    except LookupError:\n        return None\n    if native.is_cancelled:\n        return None\n    return native\n\n\ndef delivery_pending():\n    native = _turn()\n    if native is None:\n        return False\n    saved = _delivered.get(native.sender_id)\n    return bool(saved and saved[0] is native.turn and time.monotonic()-saved[1] <= _MAX_AGE)\n\n\ndef remember_delivery():\n    native = _turn()\n    if native is None:\n        return\n    _delivered[native.sender_id] = (native.turn, time.monotonic())\n    _delivered.move_to_end(native.sender_id)\n    while len(_delivered) > _MAX_RECORDS:\n        _delivered.popitem(last=False)\n\n\nasync def deliver_reply(context, text):\n    if context is None or context.is_cancelled or delivery_pending():\n        return\n    await context.send(text)\n    remember_delivery()\n\n\n@modify_model_response()\nasync def keep_host_reply_once(payload: ModelResponsePayload) -> ModelResponsePayload:\n    native = _turn()\n    if native is None or native.sender_id != payload.sender_id:\n        return payload\n    saved = _delivered.pop(payload.sender_id, None)\n    if not saved or saved[0] is not native.turn or time.monotonic()-saved[1] > _MAX_AGE:\n        return payload\n    # Agentic banking has no collect/confirmation flow steps. The supported\n    # listen tool ends this turn without a second review, status paraphrase,\n    # or another tool call after the host's canonical message.\n    return payload.model_copy(update={\"text\": None, \"tool_calls\": [{\n        \"id\": \"host-reply-\" + uuid4().hex, \"tool_name\": \"listen\",\n        \"tool_args\": {}, \"type\": \"function\"}]})\n"
}
