Skip to content

Commit fbc7b2b

Browse files
authored
Merge branch 'AstrBotDevs:master' into Sjshi763/issue4409
2 parents 75e2f99 + 912e40e commit fbc7b2b

11 files changed

Lines changed: 57 additions & 24 deletions

File tree

ASYNC_TASK_new.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

astrbot/cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "4.14.1"
1+
__version__ = "4.14.4"

astrbot/core/agent/runners/tool_loop_agent_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ async def step(self):
213213
if not llm_response.is_chunk and llm_response.usage:
214214
# only count the token usage of the final response for computation purpose
215215
self.stats.token_usage += llm_response.usage
216+
if self.req.conversation:
217+
self.req.conversation.token_usage = llm_response.usage.total
216218
break # got final response
217219

218220
if not llm_resp_result:

astrbot/core/astr_main_agent.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
import os
99
import zoneinfo
10+
from collections.abc import Coroutine
1011
from dataclasses import dataclass, field
1112

1213
from astrbot.api import sp
@@ -114,6 +115,7 @@ class MainAgentBuildResult:
114115
agent_runner: AgentRunner
115116
provider_request: ProviderRequest
116117
provider: Provider
118+
reset_coro: Coroutine | None = None
117119

118120

119121
def _select_provider(
@@ -837,8 +839,12 @@ async def build_main_agent(
837839
config: MainAgentBuildConfig,
838840
provider: Provider | None = None,
839841
req: ProviderRequest | None = None,
842+
apply_reset: bool = True,
840843
) -> MainAgentBuildResult | None:
841-
"""构建主对话代理(Main Agent),并且自动 reset。"""
844+
"""构建主对话代理(Main Agent),并且自动 reset。
845+
846+
If apply_reset is False, will not call reset on the agent runner.
847+
"""
842848
provider = provider or _select_provider(event, plugin_context)
843849
if provider is None:
844850
logger.info("未找到任何对话模型(提供商),跳过 LLM 请求处理。")
@@ -955,7 +961,7 @@ async def build_main_agent(
955961
if action_type == "live":
956962
req.system_prompt += f"\n{LIVE_MODE_SYSTEM_PROMPT}\n"
957963

958-
await agent_runner.reset(
964+
reset_coro = agent_runner.reset(
959965
provider=provider,
960966
request=req,
961967
run_context=AgentContextWrapper(
@@ -973,8 +979,12 @@ async def build_main_agent(
973979
tool_schema_mode=config.tool_schema_mode,
974980
)
975981

982+
if apply_reset:
983+
await reset_coro
984+
976985
return MainAgentBuildResult(
977986
agent_runner=agent_runner,
978987
provider_request=req,
979988
provider=provider,
989+
reset_coro=reset_coro if not apply_reset else None,
980990
)

astrbot/core/config/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
77

8-
VERSION = "4.14.1"
8+
VERSION = "4.14.4"
99
DB_PATH = os.path.join(get_astrbot_data_path(), "data_v4.db")
1010

1111
WEBHOOK_SUPPORTED_PLATFORMS = [

astrbot/core/cron/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ async def _woke_main_agent(
310310
config = MainAgentBuildConfig(
311311
tool_call_timeout=3600,
312312
llm_safety_mode=False,
313+
streaming_response=False,
313314
)
314315
req = ProviderRequest()
315316
conv = await _get_session_conv(event=cron_event, plugin_context=self.ctx)

astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ async def process(
164164
event=event,
165165
plugin_context=self.ctx.plugin_manager.context,
166166
config=build_cfg,
167+
apply_reset=False,
167168
)
168169

169170
if build_result is None:
@@ -172,6 +173,7 @@ async def process(
172173
agent_runner = build_result.agent_runner
173174
req = build_result.provider_request
174175
provider = build_result.provider
176+
reset_coro = build_result.reset_coro
175177

176178
api_base = provider.provider_config.get("api_base", "")
177179
for host in decoded_blocked:
@@ -190,6 +192,10 @@ async def process(
190192
if await call_event_hook(event, EventType.OnLLMRequestEvent, req):
191193
return
192194

195+
# apply reset
196+
if reset_coro:
197+
await reset_coro
198+
193199
action_type = event.get_extra("action_type")
194200

195201
event.trace.record(
@@ -357,7 +363,8 @@ async def _save_to_history(
357363

358364
token_usage = None
359365
if runner_stats:
360-
token_usage = runner_stats.token_usage.total
366+
# token_usage = runner_stats.token_usage.total
367+
token_usage = llm_response.usage.total if llm_response.usage else None
361368

362369
await self.conv_manager.update_conversation(
363370
event.unified_msg_origin,

changelogs/v4.14.2.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## What's Changed
2+
3+
### 新增
4+
- 控制台页面新增调试提示和本地化文件 ([#4852](https://github.com/AstrBotDevs/AstrBot/pull/4852))
5+
6+
### 修复
7+
- 修复插件热重载时平台适配器未清理导致注册冲突的问题 ([#4859](https://github.com/AstrBotDevs/AstrBot/pull/4859))
8+
9+
### 其他
10+
- 更新 ruff 版本至 0.15.0
11+
- 新增 robots.txt ([#4847](https://github.com/AstrBotDevs/AstrBot/pull/4847))
12+
13+
## What's Changed (EN)
14+
15+
### New Features
16+
- Add debug hint to console page and localization files ([#4852](https://github.com/AstrBotDevs/AstrBot/pull/4852))
17+
18+
### Bug Fixes
19+
- Fix platform adapter not being cleaned up during plugin hot reload, causing registration conflicts ([#4859](https://github.com/AstrBotDevs/AstrBot/pull/4859))
20+
21+
### Others
22+
- Update ruff version to 0.15.0
23+
- Add robots.txt ([#4847](https://github.com/AstrBotDevs/AstrBot/pull/4847))

changelogs/v4.14.3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## What's Changed
2+
3+
### 修复
4+
- 修复 `on_llm_request` 钩子可能无法应用效果的问题

changelogs/v4.14.4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## What's Changed
2+
3+
### 修复
4+
- 修复 token 统计错误的问题,修复在多轮 tool call 情况下或者其他极端情况下可能造成 tool 无限调用的问题。

0 commit comments

Comments
 (0)