How I built tool focus for my desktop AI companion: 5 tools stay, the rest vanish, and the model holds the exit key
How I built tool focus for my desktop AI companion: 5 tools stay, the rest vanish, and the model holds the exit key Ankita AI is a desktop AI assistant by Krish Verma — a little companion, a lot more possible — and the
How I built tool focus for my desktop AI companion: 5 tools stay, the rest vanish, and the model holds the exit key
Ankita AI is a desktop AI assistant by Krish Verma — a little companion, a lot more possible — and the hardest part of giving it a browser was not the browser. It was the other hundred tools sitting next to it. Ask it to book a train ticket and the model could reach for the shell, the filesystem, or a web-search API instead of the page in front of it, then report back with evidence from a source that never touched the site. So I built tool focus: during browser work, everything except the browser group disappears from the model's world. Five tools stay. The rest vanish. And the model holds the key to let itself out.
The problem: the wrong tool family gives the wrong evidence
Ankita loads tools on demand — find_tools matches a query to a group, and only that group's schemas reach the model. That keeps each request small, but it never stopped the model from loading a second group mid-task. Halfway through a checkout it could load the shell group, run a curl, and come back claiming the price from an API response while the page said something else. The guidance I wrote into the focus prompt says it plainly: "Never claim browser work from HTTP/API evidence." A rule in a prompt is not a boundary, though. The model can always load another group. Focus had to be enforced where the model cannot argue with it.
How it works: one call in, three layers holding it shut
Entering focus is one call: find_tools(query="browser", scope="focus"). From there, src/core/tool-focus.mjs — about 30 lines — owns the whole idea. setToolFocus stores the focused set on the session state and records every switch in toolFocusTransitions, so a turn can later report exactly how many times focus changed and whether it ended focused. focusAllows is the one predicate everything else asks: no focus set, everything is allowed; focus set, only the focused tools plus five shared ones pass.
Those five are find_tools, recall, remember, write_todos, and skill. Discovery, memory, and the current checklist stay available in every focus, because a browser task that cannot remember what it is doing or check its own plan is worse than useless. Everything else goes.
The enforcement runs at three layers, and that number matters — one layer is a suggestion, three is a shape:
-
Schema filtering (
src/core/agent.mjs:755): when the agent builds the tool list for a request, every spec passes throughfocusAllows. A withheld tool never appears in the request at all, so the model cannot call what it cannot see. -
Discovery admission (
tools/find-tools.mjs:147): loading a group outside the current focus is refused before anything loads — "This group is outside the current tool focus. Call find_tools(scope="general", query=the needed group) first. No tools were loaded and focus was not changed." -
Execution gate (
src/core/tool-host.mjs:171): even if a stale or hallucinated call slips through, the tool host refuses it with the same error. Discovery and execution agree, because a boundary that only exists in one of them is a bug waiting for a race.
Entering focus is strict, too. With focus on, find_tools with scope="focus" accepts only the browser group — anything else gets "Browser focus requires only the browser group." The browser group itself is a single tool in the catalogue, so focus means exactly one working tool plus the five shared ones.
The exit is deliberate — and that is the flaw I already found
Leaving focus is one call the other way: find_tools(scope="general"). It works even when the query misses or the tool the model wants is a core tool — the code says so in a comment: "An explicit exit must work even when the desired tool is core or the query misses." And the refusal messages teach the exit: every "outside the current tool focus" error tells the model exactly which call restores general access.
So here is the contradiction, stated plainly: the model holds its own exit key, and the lock hands it the key in the error message. Focus is a scoping aid, not a security boundary — a confused model cannot wander into the shell by accident, but a determined one leaves in a single call. It is also off by default (browserToolFocus: false in src/core/config.mjs, with the comment "opt-in until repeated live capability parity clears the browser-lab gate"), it resets at the end of every turn (this.state.toolFocus = null in sendWithSkills), and voice tools marked alwaysAvailable bypass it entirely. A multi-turn browser task re-enters focus every turn; a voice command can step around it without asking.
I keep it anyway, because the failure it stops is the common one: accidental drift, not deliberate escape. Twelve tests in test/core/browser-skill.test.mjs pin the behaviour — a mixed-group focus request is refused, the boundary accepts the browser group, and the state is null again after the turn. The audit trail (focusAudit: switch count, the transitions, whether the turn ended focused) and the per-request focused flag in requestMetrics mean I can see exactly how often the model enters and leaves, instead of guessing.
But the question stays open, and it is the one I would rather be argued with about than the mechanism itself: if the exit is one self-serve call away, is focus a real boundary, or is it a polite suggestion with an error message attached? Should leaving focus require the user — an approval card, a "yes, switch methods" — or is the whole point that the model decides when the method changes, and the audit trail is the accountability?
Tell me I'm wrong: the audit trail is the honest part, and the focus itself is theatre. Or the reverse — that a boundary the model can open is still a boundary, because the cost is a visible, logged decision instead of a silent drift.
Ankita AI is open source at github.com/akyourowngames/A.N.K.I.T.A, and the site is ankita-sable.vercel.app. If you have built scoped tool access for an agent, I want to hear where you drew the line — and whether your model holds its own key too.
— Krish Verma, creator of Ankita AI
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.