Skip to content

feat(chat): ask in the chat before Agent mode changes anything - #35

Merged
aryanjsx merged 1 commit into
mainfrom
feat/agent-approvals
Nov 8, 2026
Merged

aryanjsx merged 1 commit into
mainfrom
feat/agent-approvals

Conversation

@aryanjsx

@aryanjsx aryanjsx commented Nov 8, 2026

Copy link
Copy Markdown
Owner

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.py classifies each tool call:

    • read never asks.
    • change asks.
    • run always asks. This covers commands, code, and anything marked requires_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_run event. 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.

    • It adds file_write, shell_exec, git_status, git_diff and git_log.
    • File tools stay in the home folder unless security.allowed_dirs is set.
    • Tools run one at a time, because approvals are tracked per run on the agent's thread.
    • It gets at least 25 turns.

Frontend

  • Approval prompt: the tool card describes the step in words, such as "Run dir" or "Write notes.txt", with Allow, Allow for this task and Deny buttons.
  • Stop: the button now calls the stop endpoint, so it ends the agent run, not just the reply on screen.
  • Leftover steps: anything still waiting when a stream ends is marked denied.

Preset: assistant stays read-only, because locus serve builds 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?

  • New approval tests: tests/server/test_agent_approvals.py covers:
    • risk levels
    • approve, deny and approve_tool
    • timeouts
    • Stop while waiting
    • unknown ids (404 and 422)
    • full streams answered and stopped from another thread
    • non-streaming agent mode denying changes
  • Updated tests: tests/server/test_agent_mode.py is 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.
  • Real orchestrator: I ran it with a scripted model that called shell_exec (echo hi) and then file_write. Each call raised an approval and, once approved, ran for real.
  • Frontend: all 131 vitest tests pass (new: ToolCallCard.test.ts), and tsc -b is clean.
  • Server suite: tests/server, the preset tests and the CLI tests give 570 passed and 9 failed. They're the same 9 that fail on main, in test_api_routes (TestAgentRoutes), test_connectors_router, test_deep_research_tools_wiring and test_security_factory_wiring; at least one needs the locus_rust extension, which isn't installed locally.
  • Not yet tried: the desktop app with a real model; Ollama wasn't running.

Checklist

  • Tests pass (uv run pytest tests/ -v): new and related suites pass; the 9 failures above also fail on main
  • Linter passes on changed files (ruff check)
  • Formatter passes on changed files (ruff format --check)
  • New/changed public API has docstrings
  • Follows registry pattern (if adding new component)
  • Documentation updated (if applicable)

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.
@aryanjsx
aryanjsx merged commit 735933b into main Nov 8, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant