@@ -70,8 +70,8 @@ class DynamicSubAgentManager:
7070 _max_subagent_count : int = 3
7171 _auto_cleanup_per_turn : bool = True
7272 _shared_context_enabled : bool = False
73- _shared_context_maxlen : int = 200 # 公共上下文保留的历史消息条数
74- _max_subagent_history : int = 500 # 每个subagent最多保留的历史消息条数
73+ _shared_context_maxlen : int = 200 # 公共上下文保留的历史消息条数
74+ _max_subagent_history : int = 500 # 每个subagent最多保留的历史消息条数
7575 _tools_blacklist : set [str ] = {
7676 "send_shared_context_for_main_agentcreate_dynamic_subagent" ,
7777 "protect_subagent" ,
@@ -187,12 +187,15 @@ def configure(
187187 auto_cleanup_per_turn : bool = True ,
188188 shared_context_enabled : bool = False ,
189189 shared_context_maxlen : int = 200 ,
190+ max_subagent_history : int = 500 ,
191+ ** kwargsr ,
190192 ) -> None :
191193 """Configure DynamicSubAgentManager settings"""
192194 cls ._max_subagent_count = max_subagent_count
193195 cls ._auto_cleanup_per_turn = auto_cleanup_per_turn
194196 cls ._shared_context_enabled = shared_context_enabled
195197 cls ._shared_context_maxlen = shared_context_maxlen
198+ cls ._max_subagent_history = max_subagent_history
196199
197200 @classmethod
198201 def is_auto_cleanup_per_turn (cls ) -> bool :
@@ -265,18 +268,26 @@ def update_subagent_history(
265268 if isinstance (current_messages , list ):
266269 _MAX_TOOL_RESULT_LEN = 2000
267270 for msg in current_messages :
268- if isinstance (msg , dict ) and msg .get ("role" ) == "system" : # 移除system消息
271+ if (
272+ isinstance (msg , dict ) and msg .get ("role" ) == "system"
273+ ): # 移除system消息
269274 current_messages .remove (msg )
270275 # 对过长的 tool 结果做截断,避免单条消息占用过多空间
271- if (isinstance (msg , dict ) and msg .get ("role" ) == "tool" and isinstance (msg .get ("content" ), str ) and len (msg ["content" ]) > _MAX_TOOL_RESULT_LEN
276+ if (
277+ isinstance (msg , dict )
278+ and msg .get ("role" ) == "tool"
279+ and isinstance (msg .get ("content" ), str )
280+ and len (msg ["content" ]) > _MAX_TOOL_RESULT_LEN
272281 ):
273282 msg ["content" ] = (
274- msg ["content" ][:_MAX_TOOL_RESULT_LEN ] + "\n ...[truncated]"
283+ msg ["content" ][:_MAX_TOOL_RESULT_LEN ] + "\n ...[truncated]"
275284 )
276285
277286 session .subagent_histories [agent_name ].extend (current_messages )
278287 if cls ._max_subagent_history < len (session .subagent_histories [agent_name ]):
279- session .subagent_histories [agent_name ] = session .subagent_histories [agent_name ][- cls ._max_subagent_history :]
288+ session .subagent_histories [agent_name ] = session .subagent_histories [
289+ agent_name
290+ ][- cls ._max_subagent_history :]
280291
281292 logger .debug (
282293 "[EnhancedSubAgent:History] Saved messages for %s, current len=%d" ,
0 commit comments