Adding Memory and Tool-Calling Capabilities to Large Language Models
This article explains how to turn a standard chat-based LLM into an agent that can remember, act, and run on schedule. It covers persistent memory design across fact, summary, and retrieval layers, tool-calling workflows with parameter whitelists and result trimming, local component bridging for file and system access, scheduled tasks with session isolation and idempotency, and the data sovereignty and permission boundaries required to keep execution controllable.
1. The Problem: Why a Chat Box Can’t Get Work Done
Most general-purpose LLMs still ship as single-turn or multi-turn chat products. The user submits a prompt, the model returns text, and the context is dropped as soon as the session ends. That design is efficient for information retrieval and text rewriting, but it breaks down as soon as a task becomes stateful and executable:
- Stateless: writing style, coding conventions, and output format preferences stated yesterday have to be restated today.
- No hands: the model can only talk, not act. It cannot read or write files, reach the network, or trigger system capabilities.
- No sense of time: a human has to initiate every task, so nothing runs on a schedule unattended.
This is why a class of “browser-side augmentation” approaches has emerged: leave the model untouched and layer a capability orchestration layer on top of the chat interface the user already has, filling in memory, tools, and scheduling. Each is covered below.
2. Capability One: Persistent Memory to Stop Repeating Yourself
Memory is fundamentally about moving information that needs to be reused across sessions out of the context window and into controlled storage. Engineering it usually takes three layers:
- Fact layer: structured entries such as user identity, preferences, glossaries, and project constraints.
- Summary layer: compressed history that keeps conclusions and decisions while discarding small talk and redundant reasoning.
- Retrieval layer: at the start of a new session, semantically recall relevant entries for the current task and inject them into the prompt.
A schematic memory entry looks like this:
{"id": "pref-code-style","type": "preference","content": "Answer in Chinese, keep code comments concise, prefer runnable examples","scope": "global","updated_at": "2026-01-01T09:00:00Z"}
The critical engineering decisions are the write policy and the recall policy. Writing on every sentence drowns memory in noise; the common practice is to persist only when the user explicitly confirms or a strong preference signal appears. Recall should combine similarity filtering with time decay so stale constraints don’t override current intent. Memory should also support viewing, editing, and deletion — that is the baseline for data governability.
3. Capability Two: Tool Calling to Give the Model Hands
Tool calling turns the model from a text generator into a task planner. A typical toolset includes:
- Web search and web page text extraction;
- Reading content from tabs the user has explicitly authorized as context;
- File read/write and format conversion;
- Structured data processing and chart generation;
- Local command execution (requires high privilege, see Section 5).
A tool call generally follows this flow: the model emits a structured call intent → the runtime validates arguments and permissions → the tool executes and returns results → results are written back into the context → the model continues reasoning or wraps up. Schematically:
{"tool": "web_search","arguments": { "query": "industry updates from the past week", "limit": 5 },"reason": "Need current facts to support the conclusion"}
Three things are mandatory in production: an argument whitelist (never let the model freely assemble high-risk parameters), timeouts and retries (external dependencies are inherently unreliable), and result trimming (page bodies run to tens of thousands of characters, so summarize before entering the context to control cost and noise).
4. Capability Three: Bridging Local Components to Reach System Capabilities
The browser sandbox blocks direct access to local files and system interfaces, so a lightweight component running on the machine acts as a bridge, communicating with the extension over a loopback address. Its responsibility boundary should be strictly constrained:
- Expose only an explicitly declared set of operations, such as “read documents in a specified directory” or “run a predefined script”;
- Require a one-time token on every request, validate the origin and path, and reject directory traversal;
- For document handling, parse into an intermediate structure first and only then hand it to the model, rather than pushing binary content straight into the context.
The general document pipeline is: parse → structure into paragraphs and tables → semantic chunking → model processing → write back into a new document. Tables and images are best extracted into structured form first, with the model reasoning over that structured result; accuracy and stability are clearly better than reading the whole file raw.
5. Capability Four: Scheduled Tasks and Isolated Sessions
Scheduling turns the assistant from reactive to proactive. It relies on standard schedule expressions, for example triggering an information roundup once a day at a fixed time:
0 8 * * * /local/runner collect --topic="industry updates" --out=./reports
What actually determines usability is not the scheduler but isolation and observability:
- Session isolation: each task gets its own context and memory namespace so tasks don’t contaminate each other;
- Idempotency: repeated triggers in the same period produce no duplicate side effects, and outputs are overwritten per date partition;
- Failure handling: retries, alert notifications, and retained execution logs are all required;
- Least privilege: scheduled tasks are granted only the minimum permissions needed to meet their goal.
6. Data Sovereignty and Security Boundaries
The core value proposition of this kind of setup is that data stays local. Making that real requires: keys and memory stored in a local encrypted area; output files written to a user-specified directory; no mandatory backend upload channel; and an auditable network egress. Tiered authorization is also recommended: separate read-only, write, and execute permissions, require a second confirmation for high-risk operations, and keep a complete audit trail.
7. Implementation Recommendations
- Start with read-only capabilities (retrieval, summarization, memory), verify the payoff, then open up write and execute.
- Define directory conventions and naming schemes for memory and outputs to make backup and migration easy.
- Host the execution component in a container platform or local sandbox, and close the loop with logging, monitoring, and alerting.
- Periodically prune memory entries to prevent conflicting constraints.
8. Conclusion
Upgrading a chat model into an assistant that remembers, acts, and keeps time depends less on model parameters than on the surrounding capability orchestration and permission governance. Baidu AI Cloud offers corresponding product categories in model services, container platforms, and logging, monitoring, and alerting, which can serve as a reference foundation for building such a controllable execution chain.
