mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-05 23:10:22 +08:00
fix: Add runtime parameter to compress_messages method(#803)
* fix: Add runtime parameter to compress_messages method(#803) The compress_messages method was being called by PreModelHookMiddleware with both state and runtime parameters, but only accepted state parameter. This caused a TypeError when the middleware executed the pre_model_hook. Added optional runtime parameter to compress_messages signature to match the expected interface while maintaining backward compatibility. * Update the code with the review comments
This commit is contained in:
@@ -3,6 +3,8 @@ import copy
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from langgraph.runtime import Runtime
|
||||
|
||||
from langchain_core.messages import (
|
||||
AIMessage,
|
||||
BaseMessage,
|
||||
@@ -144,12 +146,13 @@ class ContextManager:
|
||||
"""
|
||||
return self.count_tokens(messages) > self.token_limit
|
||||
|
||||
def compress_messages(self, state: dict) -> List[BaseMessage]:
|
||||
def compress_messages(self, state: dict, runtime: Runtime | None = None) -> dict:
|
||||
"""
|
||||
Compress messages to fit within token limit
|
||||
|
||||
Args:
|
||||
state: state with original messages
|
||||
runtime: Optional runtime parameter (not used but required for middleware compatibility)
|
||||
|
||||
Returns:
|
||||
Compressed state with compressed messages
|
||||
|
||||
Reference in New Issue
Block a user