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
86 lines
1.9 KiB
Python
86 lines
1.9 KiB
Python
# coding: utf-8
|
|
# Copyright (c) 2025 inclusionAI.
|
|
import abc
|
|
|
|
from aworld.core.context.base import Context
|
|
from aworld.core.event.base import Message
|
|
from aworld.models.model_response import ModelResponse
|
|
|
|
|
|
class HookPoint:
|
|
START = "start"
|
|
FINISHED = "finished"
|
|
ERROR = "error"
|
|
PRE_LLM_CALL = "pre_llm_call"
|
|
POST_LLM_CALL = "post_llm_call"
|
|
OUTPUT_PROCESS = "output_process"
|
|
|
|
class Hook:
|
|
"""Runner hook."""
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
@abc.abstractmethod
|
|
def point(self):
|
|
"""Hook point."""
|
|
|
|
@abc.abstractmethod
|
|
async def exec(self, message: Message, context: Context = None) -> Message:
|
|
"""Execute hook function."""
|
|
|
|
|
|
class StartHook(Hook):
|
|
"""Process in the hook point of the start."""
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
def point(self):
|
|
return HookPoint.START
|
|
|
|
|
|
class FinishedHook(Hook):
|
|
"""Process in the hook point of the finished."""
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
def point(self):
|
|
return HookPoint.FINISHED
|
|
|
|
|
|
class ErrorHook(Hook):
|
|
"""Process in the hook point of the error."""
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
def point(self):
|
|
return HookPoint.ERROR
|
|
|
|
class PreLLMCallHook(Hook):
|
|
"""Process in the hook point of the pre_llm_call."""
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
def point(self):
|
|
return HookPoint.PRE_LLM_CALL
|
|
|
|
class PostLLMCallHook(Hook):
|
|
"""Process in the hook point of the post_llm_call."""
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
def point(self):
|
|
return HookPoint.POST_LLM_CALL
|
|
|
|
class OutputProcessHook(Hook):
|
|
"""Output process hook for processing output data for display."""
|
|
__metaclass__ = abc.ABCMeta
|
|
|
|
def point(self):
|
|
return HookPoint.OUTPUT_PROCESS
|
|
|
|
def process_output_content(self, content: str) -> str:
|
|
"""process output content
|
|
|
|
Args:
|
|
content: original content
|
|
|
|
Returns:
|
|
processed content
|
|
"""
|
|
return content
|
|
|