类 HookEvent

java.lang.Object
io.agentscope.core.hook.HookEvent
直接已知子类:
ActingEvent, ErrorEvent, PostCallEvent, PreCallEvent, ReasoningEvent, SummaryEvent

@Deprecated(forRemoval=true, since="2.0.0") public abstract sealed class HookEvent extends Object permits PreCallEvent, PostCallEvent, ReasoningEvent, ActingEvent, SummaryEvent, ErrorEvent
已过时, 待删除: 此 API 元素将从以后的版本中删除。
since 2.0.0. Use MiddlewareBase instead.
Base class for all hook events.

This is a sealed class - only the predefined event types are permitted. This enables exhaustive pattern matching in switch expressions.

All events provide access to common context:

System message lifecycle: Every event carries a unified systemMsg field that holds the single MsgRole.SYSTEM message visible to the LLM. ReActAgent manages this field across the event lifecycle as follows:

  1. Seeded from sysPrompt at the start of each call() before PreCallEvent hooks run.
  2. After PreCallEvent hooks complete, the resulting system message is frozen as the base for the entire call.
  3. Before each PreReasoningEvent (and PreSummaryEvent), the frozen base is injected fresh into the event — hooks that run on these events always start from the same clean baseline and may append per-iteration content.
  4. Before model.stream(...) is called: the event's final system message is prepended to PreReasoningEvent.getInputMessages() as the first element.

Because each PreReasoningEvent starts from a fresh copy of the frozen base, hooks that fire per-iteration (e.g. subagent guidance) can safely use appendSystemContent(String) — content is added to that iteration's copy and never accumulates across iterations.

Hooks should modify the system message exclusively via setSystemMessage(Msg), appendSystemContent(String), or appendSystemContent(ContentBlock). Injecting MsgRole.SYSTEM messages into inputMessages directly is forbidden and results in an IllegalStateException at runtime.

Modifiability: Whether an event allows modification is determined by the presence of setter methods in the concrete event class.

另请参阅:
  • 构造器概要

    构造器
    限定符
    构造器
    说明
    protected
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Constructor for HookEvent.
  • 方法概要

    修饰符和类型
    方法
    说明
    final void
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Appends a ContentBlock at the end of the system message.
    final void
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Appends the given text as a new TextBlock at the end of the system message.
    final Agent
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Get the agent instance.
    final Memory
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Convenient access to the agent's conversation context wrapped as a read-only Memory view.
    final Msg
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Returns the current unified system message, or null if none has been set.
    final long
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Get the timestamp when event was created.
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Get the event type.
    final void
    setSystemMessage(Msg systemMsg)
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Replaces the entire system message with the given one.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • HookEvent

      protected HookEvent(HookEventType type, Agent agent)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Constructor for HookEvent.
      参数:
      type - The event type (must not be null)
      agent - The agent instance (must not be null)
      抛出:
      NullPointerException - if type or agent is null
  • 方法详细资料

    • getType

      public final HookEventType getType()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Get the event type.
      返回:
      The event type
    • getAgent

      public final Agent getAgent()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Get the agent instance.
      返回:
      The agent instance (never null)
    • getTimestamp

      public final long getTimestamp()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Get the timestamp when event was created.
      返回:
      The timestamp (milliseconds since epoch)
    • getMemory

      public final Memory getMemory()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Convenient access to the agent's conversation context wrapped as a read-only Memory view. Mutations should be performed against AgentState.contextMutable() on the running agent's state.
      返回:
      a read-only Memory view, or null if the event's agent is not a ReActAgent
    • getSystemMessage

      public final Msg getSystemMessage()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Returns the current unified system message, or null if none has been set.

      On PreCallEvent and PreReasoningEvent, modifications made by earlier hooks in the chain are already reflected here.

      返回:
      the system message, may be null
    • setSystemMessage

      public final void setSystemMessage(Msg systemMsg)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Replaces the entire system message with the given one.

      Prefer appendSystemContent(java.lang.String) when you only need to add a portion of the system message; use this method only when you need to set a completely custom system message.

      参数:
      systemMsg - the new system message (may be null to clear)
    • appendSystemContent

      public final void appendSystemContent(String text)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Appends the given text as a new TextBlock at the end of the system message.

      If no system message exists yet, one is created automatically with MsgRole.SYSTEM and name "system".

      参数:
      text - the text to append (must not be null)
    • appendSystemContent

      public final void appendSystemContent(ContentBlock block)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Appends a ContentBlock at the end of the system message.

      If no system message exists yet, one is created automatically with MsgRole.SYSTEM and name "system".

      参数:
      block - the content block to append (must not be null)