Files
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

42 lines
1.3 KiB
Python

# coding: utf-8
# Copyright (c) 2025 inclusionAI.
HOOK_TEMPLATE = """
import traceback
from aworld.core.context.base import Context
from aworld.core.event.base import Message, Constants, TopicType
from aworld.runners.hook.hooks import *
from aworld.runners.hook.hook_factory import HookFactory
from aworld.logs.util import logger
from aworld.utils.common import convert_to_snake
@HookFactory.register(name="{name}",
desc="{desc}")
class {name}({point}Hook):
def name(self):
return convert_to_snake("{name}")
async def exec(self, message: Message) -> Message:
{func_import}import {func}
try:
res = {func}(message)
if not res:
raise ValueError(f"{func} no result return.")
return Message(payload=res,
session_id=message.context.session_id,
sender="{name}",
category=Constants.TASK,
topic="{topic}")
except Exception as e:
logger.error(traceback.format_exc())
return Message(payload=str(e),
session_id=message.context.session_id,
sender="{name}",
category=Constants.TASK,
topic=TopicType.ERROR)
"""