Skip to content

Commit 1222aae

Browse files
committed
formatting
1 parent a9dd635 commit 1222aae

4 files changed

Lines changed: 27 additions & 13 deletions

File tree

astrbot/core/agent/runners/tool_loop_agent_runner.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,12 @@ def _append_tool_call_result(tool_call_id: str, content: str) -> None:
11231123
)
11241124
else:
11251125
inline_result = "\n\n".join(result_parts)
1126-
inline_result = await self._materialize_large_tool_result(
1127-
tool_call_id=func_tool_id,
1128-
content=inline_result,
1129-
)
1126+
inline_result = (
1127+
await self._materialize_large_tool_result(
1128+
tool_call_id=func_tool_id,
1129+
content=inline_result,
1130+
)
1131+
)
11301132
_append_tool_call_result(
11311133
func_tool_id,
11321134
inline_result

astrbot/core/astr_agent_tool_exec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,14 @@ async def _execute_handoff(
423423
max_steps=agent_max_step,
424424
tool_call_timeout=run_context.tool_call_timeout,
425425
stream=stream,
426-
return_runner_messages=True
426+
return_runner_messages=True,
427427
)
428428

429429
# 保存历史上下文
430430
if agent_name and runner_messages:
431431
try:
432432
from astrbot.core.dynamic_subagent_manager import DynamicSubAgentManager
433+
433434
DynamicSubAgentManager.update_subagent_history(
434435
umo, agent_name, runner_messages
435436
)

astrbot/core/config/default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@
198198
},
199199
"enhanced_subagent": {
200200
"enabled": False,
201-
"log_level": "debug",
202201
"max_subagent_count": 3,
203202
"auto_cleanup_per_turn": True,
204-
"shared_context_enabled": False,
203+
"shared_context_enabled": True,
205204
"shared_context_maxlen": 200,
205+
"max_subagent_history": 500,
206206
},
207207
"provider_stt_settings": {
208208
"enable": False,

astrbot/core/dynamic_subagent_manager.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)