Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions astrbot/builtin_stars/builtin_commands/commands/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,39 @@ async def _get_current_persona_id(self, session_id):
return None
return conv.persona_id

async def reset(self, message: AstrMessageEvent) -> None:
"""Clear the context of the current conversation.

Args:
message: Command event identifying the session and sender.
"""
umo = message.unified_msg_origin
cfg = self.context.get_config(umo=umo)
agent_runner_type = cfg["agent_runner"]["runner_type"]

active_event_registry.stop_all(umo, exclude=message)
cid = await self.context.conversation_manager.get_curr_conversation_id(umo)
if agent_runner_type in THIRD_PARTY_AGENT_RUNNER_KEY:
await _clear_third_party_agent_runner_state(
self.context,
umo,
agent_runner_type,
)
else:
if cid:
await self.context.conversation_manager.update_conversation(
umo,
cid,
history=[],
)

message.set_extra("_clean_group_context_session", True)
message.set_result(
MessageEventResult().message(
"✅ The current conversation context has been cleared."
)
)

async def stop(self, message: AstrMessageEvent) -> None:
"""停止当前会话正在运行的 Agent"""
cfg = self.context.get_config(umo=message.unified_msg_origin)
Expand Down Expand Up @@ -141,19 +174,14 @@ async def new_conv(self, message: AstrMessageEvent) -> None:
"""
cfg = self.context.get_config(umo=message.unified_msg_origin)
agent_runner_type = cfg["agent_runner"]["runner_type"]
active_event_registry.stop_all(message.unified_msg_origin, exclude=message)
if agent_runner_type in THIRD_PARTY_AGENT_RUNNER_KEY:
active_event_registry.stop_all(message.unified_msg_origin, exclude=message)
await _clear_third_party_agent_runner_state(
self.context,
message.unified_msg_origin,
agent_runner_type,
)
message.set_result(
MessageEventResult().message("✅ New conversation created.")
)
return

active_event_registry.stop_all(message.unified_msg_origin, exclude=message)
cpersona = await self._get_current_persona_id(message.unified_msg_origin)
cid = await self.context.conversation_manager.new_conversation(
message.unified_msg_origin,
Expand Down
14 changes: 3 additions & 11 deletions astrbot/builtin_stars/builtin_commands/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ async def name(self, event: AstrMessageEvent, alias: GreedyStr) -> None:
@filter.command("reset")
@filter.permission_type(filter.PermissionType.SHARED_GROUP_ADMIN)
async def reset(self, message: AstrMessageEvent) -> None:
"""Start a new conversation, keeping previous history.

Args:
message: Command event identifying the session and sender.
"""
await self.conversation_c.new_conv(message)
"""Clear the context of the current conversation."""
await self.conversation_c.reset(message)

@filter.command("stop")
async def stop(self, message: AstrMessageEvent) -> None:
Expand All @@ -59,11 +55,7 @@ async def stop(self, message: AstrMessageEvent) -> None:
@filter.command("new")
@filter.permission_type(filter.PermissionType.SHARED_GROUP_ADMIN)
async def new_conv(self, message: AstrMessageEvent) -> None:
"""Start a new conversation, keeping previous history.

Args:
message: Command event identifying the session and sender.
"""
"""Create a new conversation."""
await self.conversation_c.new_conv(message)

@filter.command("stats")
Expand Down
20 changes: 10 additions & 10 deletions docs/en/use/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following commands are shipped with AstrBot and loaded by default:
- `/help`: View currently enabled commands and AstrBot version information.
- `/sid`: View current message source information, including UMO, user ID, platform ID, message type, and session ID. This is commonly used when configuring admins, allowlists, or routing rules.
- `/name`: Set a display alias for the current UMO, which means one concrete group or private-chat message source on a platform, so it is easier to recognize in WebUI. This command requires admin permission.
- `/reset`: Create and switch to a new conversation, just like `/new`.
- `/reset`: Clear the context of the current conversation.
- `/stop`: Stop Agent tasks currently running in the current session.
- `/new`: Create and switch to a new conversation.
- `/stats`: View token usage statistics for the current conversation.
Expand Down Expand Up @@ -73,20 +73,20 @@ Display rules:

### `/reset` and `/new`

`/reset` and `/new` use the same restart flow. Both command entries and their individual command management settings are retained.
Both commands stop running tasks in the current session and clear the session's temporary group context after the reply is sent. Their conversation behavior is different:

For AstrBot's built-in Agent Runner, it:
`/reset`:

- Marks other active events in the current session as stopped, without waiting for every task to exit.
- Creates and selects an empty conversation, preserving previous history and inheriting the current persona.
- Clears the current session's group context cache after the reply is sent.
- For AstrBot's built-in Agent Runner, clears the current conversation's context messages while preserving its conversation ID, title, persona, and token usage statistics.
- For third-party Agent Runners such as `dify`, `coze`, `dashscope`, and `deerflow`, clears the remote runner context while preserving the local conversation ID.
- If there is no current conversation, returns a success message without creating a local conversation.

For third-party Agent Runners such as `dify`, `coze`, `dashscope`, and `deerflow`, it:
`/new`:

- Stops running tasks in the current session.
- Removes the saved third-party conversation ID for this session, so the next turn starts a new conversation.
- For AstrBot's built-in Agent Runner, preserves the old conversation record, creates and selects a new local conversation, and inherits the current persona.
- For third-party Agent Runners, clears the remote runner context first, then creates and selects a new local conversation; old local conversation records remain available.

DeerFlow also attempts to delete the old remote thread. Third-party runners do not guarantee retention of previous history.
DeerFlow also attempts to delete the old remote thread.

Permission notes:

Expand Down
20 changes: 10 additions & 10 deletions docs/zh/use/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AstrBot 的指令通过插件机制注册。为了保持主程序轻量,当前
- `/help`:查看当前启用的指令和 AstrBot 版本信息。
- `/sid`:查看当前消息来源信息,包括 UMO、用户 ID、平台 ID、消息类型和会话 ID。常用于配置管理员、白名单或路由规则。
- `/name`:为当前 UMO(统一消息来源,即某个平台上的一个群聊或私聊会话)设置展示别名,让 WebUI 中的会话来源更容易识别。该指令需要管理员权限。
- `/reset`:与 `/new` 一样,创建并切换到新对话
- `/reset`:清空当前对话的上下文
- `/stop`:停止当前会话中正在运行的 Agent 任务。
- `/new`:创建并切换到一个新对话。
- `/stats`:查看当前会话的 Token 用量统计。
Expand Down Expand Up @@ -67,20 +67,20 @@ AstrBot 的指令通过插件机制注册。为了保持主程序轻量,当前

### `/reset` 和 `/new`

`/reset` 和 `/new` 执行相同的新建对话流程,保留两个指令入口及各自的指令管理设置。
两条指令都会停止当前会话中正在运行的任务,并在回复发送后清理当前会话的群聊临时上下文。它们的对话处理方式不同:

对于 AstrBot 内置 Agent Runner,它会
`/reset` 会

- 标记当前会话中其他活跃事件停止,不等待所有任务退出
- 创建并切换到空的新对话,保留旧对话历史并继承当前人格
- 在回复发送后清理当前会话的群聊上下文缓存
- 对 AstrBot 内置 Agent Runner,清空当前对话的上下文消息,但保留对话 ID、标题、Persona 和 Token 用量统计
- 对第三方 Agent Runner,例如 `dify`、`coze`、`dashscope`、`deerflow`,清理远端 runner 上下文,但保留本地对话 ID
- 当前没有对话时直接返回成功提示,不会创建新的本地对话

对于第三方 Agent Runner,例如 `dify`、`coze`、`dashscope`、`deerflow`,它会
`/new` 会

- 停止当前会话中正在运行的任务
- 删除当前会话保存的第三方会话 ID,让下一轮对话重新开始
- 对 AstrBot 内置 Agent Runner,保留旧对话记录,创建并切换到新的本地对话,并继承当前 Persona
- 对第三方 Agent Runner,先清理远端 runner 上下文,再创建并切换到新的本地对话;旧的本地对话记录仍然保留

DeerFlow 还会尝试删除旧的远端 thread;第三方路径不保证保留旧记录
DeerFlow 还会尝试删除旧的远端 thread。

权限说明:

Expand Down
Loading
Loading