HookEvent
@Deprecated(forRemoval = true, since = "2.0.0") public abstract sealed class HookEvent permits PreCallEvent, PostCallEvent, ReasoningEvent, ActingEvent, SummaryEvent, ErrorEvent
io/agentscope/core/hook/HookEvent.java:76–211所有钩子事件的基类。位于 io.agentscope.core.hook 包。核心成员包括 getType、getAgent、getTimestamp、getMemory、getSystemMessage、setSystemMessage。
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:
-
#getAgent()- The agent instance -
#getMemory()- Convenient access to agent's memory (may be null) -
#getType()- The event type -
#getTimestamp()- When the event occurred
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:
-
Seeded from
sysPromptat the start of eachcall()beforePreCallEventhooks run. -
After
PreCallEventhooks complete, the resulting system message is frozen as the base for the entire call. -
Before each
PreReasoningEvent(andPreSummaryEvent), 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. -
Before
model.stream(...)is called: the event's final system message is prepended toPreReasoningEvent#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.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
protected HookEvent(HookEventType type, Agent agent) | 初始化 `HookEvent` 实例。 Constructor for HookEvent. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public final HookEventType getType()final | 获取事件类型。 Get the event type. |
public final Agent getAgent()final | 获取智能体实例。 Get the agent instance. |
public final long getTimestamp()final | 获取时间戳。 Get the timestamp when event was created. |
public final Memory getMemory()final | 获取记忆。 Convenient access to the agent's conversation context wrapped as a read-only
`Memory` view. |
public final Msg getSystemMessage()final | 获取系统消息。 Returns the current unified system message, or `null` if none has been set. |
public final void setSystemMessage(Msg systemMsg)final | 设置系统消息。 Replaces the entire system message with the given one. |
public final void appendSystemContent(String text)final | 追加系统内容。 Appends the given text as a new `TextBlock` at the end of the system message. |
public final void appendSystemContent(ContentBlock block)final | 追加系统内容。 Appends a `ContentBlock` at the end of the system message. |
构造器详情Constructor Detail
HookEvent
protected HookEvent(HookEventType type, Agent agent)
初始化 HookEvent 实例。
Constructor for HookEvent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | HookEventType | 类型(类型 `HookEventType`)。The event type (must not be null) |
agent | Agent | 智能体(类型 `Agent`)。The agent instance (must not be null) |
NullPointerException可能抛出 `NullPointerException`。if type or agent is null
io/agentscope/core/hook/HookEvent.java:98–102方法详情Method Detail
getType
public final HookEventType getType()
获取事件类型。
Get the event type.
HookEventTypeio/agentscope/core/hook/HookEvent.java:109–111getAgent
public final Agent getAgent()
获取智能体实例。
Get the agent instance.
Agentio/agentscope/core/hook/HookEvent.java:118–120getTimestamp
public final long getTimestamp()
获取时间戳。
Get the timestamp when event was created.
longio/agentscope/core/hook/HookEvent.java:127–129getMemory
public final Memory getMemory()
获取记忆。
Convenient access to the agent's conversation context wrapped as a read-only Memory view.
Memoryio/agentscope/core/hook/HookEvent.java:139–144getSystemMessage
public final Msg getSystemMessage()
获取系统消息。
Returns the current unified system message, or null if none has been set.
Msgio/agentscope/core/hook/HookEvent.java:156–158setSystemMessage
public final void setSystemMessage(Msg systemMsg)
设置系统消息。
Replaces the entire system message with the given one.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
systemMsg | Msg | 系统消息(类型 `Msg`)。the new system message (may be null to clear) |
io/agentscope/core/hook/HookEvent.java:168–170appendSystemContent
public final void appendSystemContent(String text)
追加系统内容。
Appends the given text as a new TextBlock at the end of the system message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text | String | 文本(类型 `String`)。the text to append (must not be null) |
io/agentscope/core/hook/HookEvent.java:180–183appendSystemContent
public final void appendSystemContent(ContentBlock block)
追加系统内容。
Appends a ContentBlock at the end of the system message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
block | ContentBlock | 内容块(类型 `ContentBlock`)。the content block to append (must not be null) |
io/agentscope/core/hook/HookEvent.java:193–210