类 HookEvent
- 直接已知子类:
ActingEvent,ErrorEvent,PostCallEvent,PreCallEvent,ReasoningEvent,SummaryEvent
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 instancegetMemory()- Convenient access to agent's memory (may be null)getType()- The event typegetTimestamp()- 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.
- 另请参阅:
-
构造器概要
构造器限定符构造器说明protectedHookEvent(HookEventType type, Agent agent) 已过时, 待删除: 此 API 元素将从以后的版本中删除。Constructor for HookEvent. -
方法概要
修饰符和类型方法说明final voidappendSystemContent(ContentBlock block) 已过时, 待删除: 此 API 元素将从以后的版本中删除。Appends aContentBlockat the end of the system message.final voidappendSystemContent(String text) 已过时, 待删除: 此 API 元素将从以后的版本中删除。Appends the given text as a newTextBlockat the end of the system message.final AgentgetAgent()已过时, 待删除: 此 API 元素将从以后的版本中删除。Get the agent instance.final Memory已过时, 待删除: 此 API 元素将从以后的版本中删除。Convenient access to the agent's conversation context wrapped as a read-onlyMemoryview.final Msg已过时, 待删除: 此 API 元素将从以后的版本中删除。Returns the current unified system message, ornullif none has been set.final long已过时, 待删除: 此 API 元素将从以后的版本中删除。Get the timestamp when event was created.final HookEventTypegetType()已过时, 待删除: 此 API 元素将从以后的版本中删除。Get the event type.final voidsetSystemMessage(Msg systemMsg) 已过时, 待删除: 此 API 元素将从以后的版本中删除。Replaces the entire system message with the given one.
-
构造器详细资料
-
HookEvent
已过时, 待删除: 此 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
已过时, 待删除: 此 API 元素将从以后的版本中删除。Get the event type.- 返回:
- The event type
-
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
已过时, 待删除: 此 API 元素将从以后的版本中删除。Convenient access to the agent's conversation context wrapped as a read-onlyMemoryview. Mutations should be performed againstAgentState.contextMutable()on the running agent's state.- 返回:
- a read-only
Memoryview, ornullif the event's agent is not aReActAgent
-
getSystemMessage
已过时, 待删除: 此 API 元素将从以后的版本中删除。Returns the current unified system message, ornullif none has been set.On
PreCallEventandPreReasoningEvent, modifications made by earlier hooks in the chain are already reflected here.- 返回:
- the system message, may be null
-
setSystemMessage
已过时, 待删除: 此 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
已过时, 待删除: 此 API 元素将从以后的版本中删除。Appends the given text as a newTextBlockat the end of the system message.If no system message exists yet, one is created automatically with
MsgRole.SYSTEMand name"system".- 参数:
text- the text to append (must not be null)
-
appendSystemContent
已过时, 待删除: 此 API 元素将从以后的版本中删除。Appends aContentBlockat the end of the system message.If no system message exists yet, one is created automatically with
MsgRole.SYSTEMand name"system".- 参数:
block- the content block to append (must not be null)
-
MiddlewareBaseinstead.