Class SummarizationHook
java.lang.Object
com.alibaba.cloud.ai.graph.agent.hook.messages.MessagesModelHook
com.alibaba.cloud.ai.graph.agent.hook.summarization.SummarizationHook
- All Implemented Interfaces:
Hook,Prioritized
Hook that summarizes conversation history when token limits are approached.
This hook monitors message token counts and automatically summarizes older
messages when a threshold is reached, preserving the first user message and
recent messages to maintain context continuity.
Example:
SummarizationHook summarizer = SummarizationHook.builder()
.model(chatModel)
.maxTokensBeforeSummary(4000)
.messagesToKeep(20)
.keepFirstUserMessage(true) // Default: true
.build();
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.alibaba.cloud.ai.graph.agent.hook.messages.MessagesModelHook
MessagesModelHook.AfterModelAction, MessagesModelHook.BeforeModelAction -
Field Summary
Fields inherited from interface com.alibaba.cloud.ai.graph.agent.Prioritized
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Method Summary
Modifier and TypeMethodDescriptionbeforeModel(List<org.springframework.ai.chat.messages.Message> previousMessages, RunnableConfig config) static SummarizationHook.Builderbuilder()Gets the list of allowed jump destinations for this hook.getName()Gets the unique name of this hook.Methods inherited from class com.alibaba.cloud.ai.graph.agent.hook.messages.MessagesModelHook
afterModel, afterModelAction, beforeModelAction, getAgent, getAgentName, getOrder, setAgent, setAgentNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.alibaba.cloud.ai.graph.agent.hook.Hook
getHookPositions, getKeyStrategys, getModelInterceptors, getToolInterceptors, getTools
-
Method Details
-
builder
-
beforeModel
public AgentCommand beforeModel(List<org.springframework.ai.chat.messages.Message> previousMessages, RunnableConfig config) - Overrides:
beforeModelin classMessagesModelHook
-
getName
Description copied from interface:HookGets the unique name of this hook. The name is used to identify the hook in the execution graph.- Returns:
- the hook name, must not be null
-
canJumpTo
Description copied from interface:HookGets the list of allowed jump destinations for this hook.Hooks can control the flow of execution by specifying where the agent can jump to after the hook executes. This allows hooks to redirect the execution flow based on their logic.
Common jump destinations include:
JumpTo.model: Jump to model nodeJumpTo.tool: Jump to tool nodeJumpTo.end: Jump to end (terminate agent)
- Returns:
- list of allowed jump destinations, empty list by default
- See Also:
-