Repository navigation
feat(chat): ask in the chat before Agent mode changes anything - #35
Merged
Merged
Conversation
Agent mode could only read, because the server had no way to ask before
writing files or running commands. Add approvals in the conversation and
let the agent use those tools once the user allows them.
- New server/approvals.py classifies each tool call as read (never
asks), change (asks) or run (always asks, including anything marked
requires_confirmation). Unknown tools ask.
- For a risky call the agent's thread pauses and the stream sends
approval_required. POST /v1/chat/approvals/{id} answers with approve,
approve_tool (that tool for the rest of the run) or deny. No answer in
5 minutes, or a request that can't ask, is a no.
- Each stream starts with agent_run. POST /v1/chat/runs/{run_id}/stop,
or closing the stream, ends the run at its next tool call.
- Agent mode always uses its own orchestrator, which carries the hook,
instead of the server's configured agent. It adds file_write,
shell_exec and read-only git tools, stays in the home folder, runs
tools one at a time and gets at least 25 turns.
- The tool card shows Allow, Allow <tool> for this task and Deny, with
the command or path in words. Stop ends the agent run, not only the
reply.
- The assistant preset stays read-only, since locus serve builds its
agent without the approval hook.
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.
What does this PR do?
Phase 3 of
docs/design/2026-11-08-agent-mode-plan.md. Agent mode (from #34) could only read, because the server had no way to ask before writing files or running commands. This PR adds approvals inside the chat, so the agent can use those tools once the user allows them.Server
Risk levels:
src/locus/server/approvals.pyclassifies each tool call:readnever asks.changeasks.runalways asks. This covers commands, code, and anything markedrequires_confirmation.Unknown tools count as
change, so new tools ask by default.Asking: before a risky call, the agent's thread pauses and the stream sends
approval_required.POST /v1/chat/approvals/{id}answers with one of:approve: this call only.approve_tool: this tool for the rest of the run.deny: skip the call.No answer within 5 minutes counts as a no. Requests that can't ask (non-streaming) deny risky calls.
Stop: each agent stream starts with an
agent_runevent.POST /v1/chat/runs/{run_id}/stop, or the client closing the stream, ends the run at its next tool call, and the answer becomes "Stopped."Agent: Agent mode now always uses its own
orchestrator, which carries the approval hook, instead of reusing the server's configured agent.file_write,shell_exec,git_status,git_diffandgit_log.security.allowed_dirsis set.Frontend
dir" or "Write notes.txt", with Allow, Allow for this task and Deny buttons.Preset:
assistantstays read-only, becauselocus servebuilds its agent without the approval hook.Not in this PR (still phase 3): a plan checklist before multi-step tasks, Undo for file changes, "always allow" rules that last beyond one run, and resuming a stopped run.
How was this tested?
tests/server/test_agent_approvals.pycovers:approve_tooltests/server/test_agent_mode.pyis updated for Agent mode always using its own agent, and checks that the built agent has the hook, sequential tools and the home folder limit.shell_exec(echo hi) and thenfile_write. Each call raised an approval and, once approved, ran for real.ToolCallCard.test.ts), andtsc -bis clean.tests/server, the preset tests and the CLI tests give 570 passed and 9 failed. They're the same 9 that fail onmain, intest_api_routes(TestAgentRoutes),test_connectors_router,test_deep_research_tools_wiringandtest_security_factory_wiring; at least one needs thelocus_rustextension, which isn't installed locally.Checklist
uv run pytest tests/ -v): new and related suites pass; the 9 failures above also fail onmainruff check)ruff format --check)