agent-ops-patterns / gallery / AnythingLLM map / how it decides
How AnythingLLM decides
In AnythingLLM, plain code routes each message, gathers what the model sees and cuts it down to fit, while the AI model picks the agent's tools and decides when the agent is done: its first reply without a tool call is the answer. In web chat a person is asked before some tool actions, but MCP tool calls run without asking anyone.
What it does without asking you
-
Does this message go to the agent instead of plain chat?
Decided by plain code It goes to the agent when it starts with @agent, or when the workspace is in automatic mode and its model can call tools natively, provided the agent run can be set up; otherwise it is answered as plain chat.
agents.js:56· decision A3 in the full map -
In web chat, should this tool action run right now?
Decided by a person The person sees a card with the skill name, the tool's description and the request, and clicks approve or reject.
websocket.js:283· decision D3 in the full map -
May this MCP tool call run?
Decided by plain code Yes: once a server's tools are loaded, each call goes straight to the server with the model's arguments; nothing asks a person.
index.js:94· decision D21 in the full map
How it decides it is done
-
Has the agent finished, so its text goes back as the answer?
Decided by an AI model The agent model decides: its first reply without a tool call ends the loop and becomes the answer. A reply that is exactly TERMINATE ends the whole session.
index.js:1056· decision G1 in the full map -
Did the model stop because it ran out of output tokens rather than because it finished?
Decided by plain code Code watches for the provider's out-of-tokens stop reason and flags the run, which the interface uses to say why the reply stopped.
ai-provider.js:818· decision G2 in the full map
Limits and memory
-
When the assembled prompt does not fit the model's window, what is cut?
Decided by plain code Code trims by fixed shares: a system prompt or context over its share has its middle cut out, and the newest history that fits is kept. If the user's message alone is over 70% of the window, only that message is sent, cut down.
index.js:49· decision B11 in the full map -
How much earlier conversation does the agent start with?
Decided by plain code The newest 20 saved exchanges for this workspace, user and thread, fixed, whatever the workspace's own history setting says.
index.js:89· decision B4 in the full map
Other judgments
-
Which tool, if any, does the agent call next (models with native tool calling)?
Decided by an AI model The agent model, given the chat history and the offered tools, returns either text or a tool call; code keeps the first call.
tooled.js:248· decision C1 in the full map -
When the model asks for several tools at once, which run?
Decided by plain code Only the first; code drops the rest without telling the model.
tooled.js:372· decision C10 in the full map -
Which parts of the workspace's documents are relevant enough to put in the context?
Decided by an AI model An embedding model finds the 4 nearest chunks by default, and code drops those below the workspace's similarity threshold (default 0.25) or from a pinned document.
index.js:417· decision B8 in the full map
Three problems in the code
-
1. When the model asks for several tools at once, only the first runs
On the shared OpenAI-compatible tool-calling path, if the model asks for more than one tool in a single reply, only the first is run and the others are dropped without the model being told. A request that needs several lookups or actions can come back with part of the work left undone unless the model notices and asks again.
Not reported upstream, checked 2026-11-01.
Where:
tooled.js:370-381,tooled.js:454-455. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-01; every sentence it found too wide was rewritten or removed, and every rewrite was checked again. -
2. The agent does not use the workspace's chat history setting
A workspace's chat history setting decides how much earlier conversation plain chat sends (20 when it is unset or zero). The agent does not read it: it always starts with the newest 20 saved exchanges, so a workspace set to send less, or more, gets 20 in agent mode.
Not reported upstream, checked 2026-11-01.
Where:
index.js:908,index.js:89-102. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-01; every sentence it found too wide was rewritten or removed, and every rewrite was checked again. -
3. Chats are marked as processed for memory even when the memory pass did not run
Every 3 hours by default, a background job reads a person's recent chats to pick out facts worth remembering. Once a group of chats passes the first two checks it is marked processed whatever happened, so if the model call fails or no model is set up, the job does not come back to those chats on its next run. Only the latest 20 are read, so in a larger group the older chats are marked processed without being read.
Not reported upstream, checked 2026-11-01.
Where:
extract-memories.js:178-182,extract-memories.js:34-38,memory-extraction-utils.js:83-88. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-01; every sentence it found too wide was rewritten or removed, and every rewrite was checked again.