Repository navigation
feat: approve listed tools before they run, with per-conversation permission modes in ChatUI - #11283
Open
liquidtoy001 wants to merge 4 commits into
Open
liquidtoy001 wants to merge 4 commits into
liquidtoy001 wants to merge 4 commits into
Conversation
Contributor
|
Sorry @liquidtoy001, your pull request is larger than the review limit of 150,000 diff characters |
liquidtoy001
force-pushed
the
feat/tool-approval-permission-modes
branch
from
November 21, 2026 08:51
4c53324 to
98d323c
Compare
liquidtoy001
force-pushed
the
feat/tool-approval-permission-modes
branch
from
November 23, 2026 15:59
8cf0dc8 to
0592d4e
Compare
liquidtoy001
force-pushed
the
feat/tool-approval-permission-modes
branch
2 times, most recently
from
November 26, 2026 07:00
60eb113 to
5851c04
Compare
…mission modes
Tools listed in agent.config.misc.tool_approval.tools wait for the
requester's approval before FunctionToolExecutor runs them, so sub-agents
are covered too. Only the requester (or a scheduled task's creator) can
answer; wakeups never do. Approving a future_task create/edit also grants
its listed tools when it runs on schedule.
ChatUI requests gain one path for per-conversation options:
WEBCHAT_CHAT_OPTIONS and resolve_webchat_chat_options() validate them, the
ChatOptions request model carries them for send, regenerate, thread and
WebSocket requests, and the WebChat adapter puts them on the event. The
first option is the permission mode (workspace, workspace_no_ask, ask,
full): modes only narrow the role's local policy, follow changes live
through PUT /api/v1/chat/sessions/{id}/permission-mode, and never pass
full access or a waiver to scheduled tasks.
ActionRow gains optional single_use, title, detail and tool_call_id fields
for WebChat, and an approval_result chunk records the applied outcome.
Per-conversation options are stored in one browser entry per conversation (chatSessionPrefs), spread into every chat request and cleared when the conversation is deleted or the user logs out. The newest open approval card is docked above the chat input; answered cards fold into the run details. Tool cards show a waiting state while their approval is pending. A pill next to + selects the conversation's permission mode; "Don't ask again" from workspace shows as "Workspace · not asking".
liquidtoy001
force-pushed
the
feat/tool-approval-permission-modes
branch
from
November 26, 2026 07:32
5851c04 to
12a81a1
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dependencies / 依赖
This PR is now on current
master(7be85d2), which includes the merged WebChat turn history fixes (#11282). It has no other open dependency. The provider request fixes (#11303) and the failed speech and knowledge base model call cards (#11304) are independent of it.The follow-up ChatUI branches (file change preview and undo, thinking level, polish, session panel) are in my fork (
liquidtoy001/AstrBot) and build on this PR; I will open them after this one.Size: +3761/−79, of which tests +1520/−9 (backend +795/−8, dashboard +981/−57, i18n +156/−4, generated and spec +140/−1, docs +169).
Branch:
feat/tool-approval-permission-modes, onmaster7be85d2. Related: #5398, #9942, #9377.Relation to recent master changes:
permission_modethrough the shared run, and approval outcomes stream through the same run events. Theendhandling keeps feat(chat): add inline run details and preserve replies after refresh #11166'sconnection.completedflag.astr_agent_runtime/tool_executor.py; this PR adds one call at the start ofFunctionToolExecutor.execute, so whichever lands second needs a small rebase.CORE_MESSAGESand the configured language instead of its own table.ProcessStagesession filters), so the requester's reply always answers the approval. A steering message from someone else in a group can move the waiting call to the background, where it keeps waiting for the requester and its result wakes the session.actionrowandviewstream parts keep upstream's handling, with approval cards taken byprocessToolStreamPayloadfirst.Today a tool runs as soon as the model calls it, including shell commands, file writes and MCP tools called by scheduled tasks or sub-agents while nobody watches. Plugins cannot stop it: the result of
on_using_llm_toolis ignored, and sub-agents do not pass through the main agent's hooks. This PR adds an opt-in approval list that works on every platform, and per-conversation permission modes in ChatUI.Plugin-facing changes / 面向插件的改动
FunctionToolExecutor.executecall now passes the approval gate first. With the default empty list nothing is asked and behaviour is unchanged.CURRENT_TOOL_CALL_ID(astrbot/core/agent/tool_executor.py): the ID of the tool call being executed, set and reset by the runner.ActionRowgains optionalsingle_use,title,detailandtool_call_idfields (only WebChat renders them).WebChatMessageEvent.sendreturns whether the message was delivered.Modifications / 改动点
Approval gate (
astrbot/core/astr_agent_runtime/tool_approval.py, new).FunctionToolExecutor.executecallscheck_tool_approval()first, so main agents and sub-agents are both covered.agent.config.misc.tool_approval.tools(empty by default, so nothing changes) andtimeout(default 120 s), built-in runner only. Config metadata in four languages.SessionFiltermatches origin and sender, not the whole group ([Bug] 群聊中空提及等待器会截获其他成员的消息(session_waiter 未绑定发送者) #9377), and wakeup events never match. Concurrent requests for one approver take turns.tool_call_timeoutstarts.astrbot/core/i18n.py(CORE_MESSAGES, zh-CN and en-US) and follow the configured system language (Context.locale, feat: add system language for core and built-in replies #11254).WebChatMessageEvent.sendnow returns whether it was delivered). The decision itself is only sent to an open stream, so it is never saved as a text message.Scheduled tasks.
future_taskin the list, creating or editing a task needs approval. The approval is stored in the job payload (tool_approval_granted) and also covers the listed tools the task uses when it runs.payload.sender_id). A task with no creator does not run listed tools.Permission modes (ChatUI) (
permission_mode.py, new):workspace,ask(default),full, plusworkspace_no_ask(see below).askit switches tofull; fromworkspaceit switches toworkspace_no_ask(still confined and sandboxed; the pill shows "Workspace · not asking", choosing Workspace again asks again). Unattended runs only ever getworkspace, andfuture_taskcreate/edit still asks.workspaceturns a role'shostfile scope intoworkspaceinget_local_permission_policy(), which also requires process isolation for execution. Shell sessions opened earlier pick up the change (require_sandboxed). In the local runtime it skips approval for the file, grep, shell and Python tools only.fullskips approval except forfuture_taskcreate/edit. Unattended runs never takefull. Tasks created or edited inworkspacemode store it and run narrowed.PUT /api/v1/chat/sessions/{session_id}/permission-mode(chat scope) returns 403 unless the session is the caller's own WebChat session. The mode is cleared when the conversation or thread is deleted.Per-conversation options path (new, so later options do not have to be threaded through every handler):
astrbot/core/platform/sources/webchat/request_flags.py:WEBCHAT_CHAT_OPTIONSandresolve_webchat_chat_options(). Missing or invalid values becomeNone, so the configured behaviour applies.astrbot/dashboard/schemas.py: a sharedChatOptionsrequest model, used by regenerate and thread messages.openspec/openapi-v1.yaml: oneChatPermissionModeschema referenced byChatRequest,ChatMessageRegenerateRequestandChatThreadMessageRequest. The generated client anddocs/public/openapi.jsonare regenerated.chat_service.py(send, regenerate, thread) andlive_chat_service.py(WebSocket) forward the resolved options; the WebChat adapter sets each one as an event extra of the same name.utils/chatSessionPrefs.mjskeeps the options in the conversation's record of upstream's per-user ChatUI preferences (chatPreferences().sessions[id].options, feat(chatui): add tabbed workbench and resident plugin views #11218), keyed by request field. Send, regenerate, WebSocket and thread requests spread them. A new conversation starts from the defaults, and the options are removed when the conversation is deleted (single or batch).WEBCHAT_CHAT_OPTIONS, a field toChatOptionsand the OpenAPI spec, and awriteChatSessionPref(sessionId, "<field>", value)call in the dashboard.ActionRowgains optionalsingle_use,title,detailandtool_call_id. Only WebChat uses them;toDictomits unset fields. WebChat also receivesexpires_at/expires_in. The tool executor exposesCURRENT_TOOL_CALL_ID, so the card can point at its tool call. After a decision, anapproval_resultchunk reports the outcome the backend applied.BotMessageAccumulatorstores it on the card, so a click after the deadline cannot show "Allowed".Dashboard
ChatInput.vue:extensionslot for the docked card.Chat.vue:ButtonActionRow.vue:useActionRowChoices.ts: shared choices plus one clock for all card deadlines.ToolCallCard.vue: a "Waiting for approval" state with a paused timer.ThreadPanel.vue: a thread starts with the conversation's mode, and "Don't ask again" there affects only the thread.OpenAPI:
ChatPermissionMode,ChatPermissionModeRequest, the PUT path. The generated client,docs/public/openapi.jsonand the scopes table are updated.This is NOT a breaking change. / 这不是一个破坏性变更。An empty approval list (the default) and the default
askmode behave as before.Screenshots or Test Results / 运行截图或测试结果
The approval card docked above the input, with the arguments folded and the three choices:
The same card with its arguments shown:
The tool call waiting for the decision in the run details:
After the choice, the one-line record folded into the run details with the tool call:
The permission menu next to +:
After Don't ask again in this conversation from Workspace, the conversation stays confined but stops asking; choosing Workspace again asks again:
Verification (Windows 11, Python 3.12, Node 22):
test_tool_approval.py, end to end through the agent runner with a scripted provider):/stopends the wait; sub-agent calls are gated;future_taskgrants its scheduled run, but that run must still ask to schedule another task;fullskips,workspaceskips only confined tools, and an unattended run is neverfull;full, from workspace stays confined;test_computer_tool_permissions.py,test_local_shell_component.py).test_cron_tools.py,test_cron_manager.py).test_webchat_chat_options.py).test_fastapi_v1_dashboard.py).test_chat_service_stream.py).toolApproval,permissionWatcher): per-conversation mode storage, card locking (chosen, answered, expired, unlocked after a failed delivery), the docked card, approval waits on the matching tool call only, and the backend sync watcher. Each was checked to fail when the rule it covers is broken.vue-tsc --noEmit,pnpm run i18n:checkandpnpm buildpass.ruff checkandruff formatpass on the changed files.cd docs && pnpm run docs:buildbuilds. Pages to check:Checklist / 检查清单
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR. / 新增use/tool-approval.md(中英),并更新webui.md、proactive-agent.md、send-message.md;无入口移动。Models used: Claude Fable 5.2, Claude Opus 5.5 (Claude Code), GPT-6 Astra (Codex).