# How Any Agent Works: A Technical Deep Dive > Inside Any Agent, a Chrome Manifest V3 browser agent that reads pages, surfs the web, fills forms, parses Office uploads and builds PDFs locally on 8B–12B Ollama models with no cloud APIs. - Author: Yadunandan Singh (https://yadunandansingh.com/) - Published: 2026-11-26 · updated 2026-11-26 - URL: https://yadunandansingh.com/blog/how-any-agent-works/ - Topics: Agentic AI, System Design, TypeScript - First published on Medium: https://medium.com/@yadunandan-ai-dev - Source repository: https://github.com/YADUNANDAN-SINGH/Any-Agent - LinkedIn article: https://lnkd.in/p/gMbxr5EV - LinkedIn walkthrough video post: https://lnkd.in/p/gRBkXjgb ## Summary Yadunandan Singh explains the architecture of Any Agent, an open-source Chrome Manifest V3 extension (~6,200 lines of TypeScript) that runs an Observe-Think-Act browser agent against local 8B-12B Ollama models (deepseek-r1:8b, gemma4:12b) at localhost:11434 with no cloud APIs. A content-script distiller turns pages into up to 90 numbered elements and 9,000 chars of text (with scrolled-screenshot vision fallback and 10-source label resolution), URL-tagged notes replace HTML history, declarativeNetRequest handles localhost CORS, context scales from 8K to 32K tokens, and 7-stage JSON repair plus self-healing fills drive forms while Safe Submit pauses before submission. A zero-dependency ZIP/XML reader parses DOCX and PPTX uploads alongside pdf.js, a hand-written PDF 1.4 engine writes A4 reports, and local TF-IDF retrieves memory with one-click Undo. ## Key takeaways - Runs entirely inside Chrome Manifest V3 (side panel, service worker, content script and chrome.storage.local) against local Ollama at localhost:11434, with zero-config CORS via declarativeNetRequest. - A page distiller feeds 8B–12B models up to 90 numbered elements (inputs first), cleaned text and search results, or scrolled screenshots for canvas and image-heavy pages. - Up to six Observe–Think–Act rounds stay compact by carrying URL-tagged notes instead of earlier HTML, capping steps at one navigation, and sizing num_ctx between 8K and 32K tokens. - Seven-stage JSON repair, 10-source label resolution, React/Vue/Angular native setters and self-healing fills absorb model mistakes, while Safe Submit pauses before final submission. - Zero black-box document libraries: a built-in ZIP/deflate-raw XML parser reads .docx and .pptx files, a hand-written PDF 1.4 engine builds multi-page reports, and local TF-IDF retrieves memory. --- [Any Agent](https://github.com/YADUNANDAN-SINGH/Any-Agent) is a Chrome extension that runs an AI agent in the browser's side panel, powered entirely by a model on your own computer through [Ollama](https://ollama.com/). It reads the page you are on, searches and browses the web, fills in forms from a saved profile, answers questions about your documents and writes PDFs. There is no cloud service, no API key and no subscription. Most browser assistants send every page you read to a remote server. Any Agent sends your prompts, page content, screenshots, documents and personal profile only to the Ollama server at `localhost:11434`. Everything it stores lives in `chrome.storage.local`. One constraint shapes almost every design decision in the project: it is built for **small local models of 8B to 12B parameters**, such as `deepseek-r1:8b` and `gemma4:12b`. Models that size have short attention, make mistakes with element ids and often return slightly broken JSON. So Any Agent does three things around the model: - Condenses each page into a short, labelled summary instead of raw HTML. - Keeps every step small: one navigation per step, then look again. - Corrects the model instead of failing, by repairing JSON and finding the intended form field from its label. This article walks through how each part works, from the extension's architecture to the agent loop, the page reader, documents, memory and the Ollama client. ## Architecture Any Agent is a Chrome Manifest V3 extension made of three scripts and a storage area. The only process outside Chrome is Ollama, running on the same machine. ![Architecture diagram of Any Agent inside Chrome Manifest V3: Storage (chrome.storage.local) and Side panel (src/App.tsx) sit at the top, calling the Service worker (src/background/index.ts) to navigate and capture, the Content script (src/content/index.ts) to read pages and act, and Ollama at localhost:11434 to stream local 8B–12B text and vision models.](https://yadunandansingh.com/blog/how-any-agent-works/architecture.webp "Any Agent architecture · 4 parts in Chrome, 1 local model") The **side panel** is the brain: it owns the agent loop and is the only part that talks to the model. The **content script** is its eyes and hands inside the web page. The **service worker** does what a page script cannot do for itself: change the tab's address, wait for a page to load and take screenshots. The parts talk through Chrome's message passing. The side panel sends `DISTILL_DOM` and `EXECUTE_ACTIONS` to the content script with `chrome.tabs.sendMessage`. It asks the service worker for `NAVIGATE_ACTIVE_TAB`, `WAIT_FOR_TAB_SETTLE` and `CAPTURE_VISIBLE_TAB` with `chrome.runtime.sendMessage`. The whole project is about 6,200 lines of TypeScript with four runtime dependencies: React, React DOM, the `lucide-react` icon set and `pdf.js`. Vite builds all three scripts from one codebase. `vite.config.ts` declares three entry points and gives the service worker and content script the fixed names `background.js` and `content.js`, because `manifest.json` refers to them by name. The manifest requests the `sidePanel`, `activeTab`, `tabs`, `scripting`, `storage`, `downloads` and `declarativeNetRequest` permissions. ## The agent loop: Observe, Think, Act Every prompt runs through a loop of up to six rounds (the **Max autonomous steps** setting) of Observe, Think and Act. The loop lives in one function, `runMultiStepAgent` in `src/App.tsx`, and it ends as soon as the model has nothing left to do. ### Gathering context before the first step Before the loop starts, the side panel collects everything the model might need: - **Documents:** the files attached to this prompt plus the most recent ones from earlier in the chat, up to three. They share a budget of 24,000 characters, split evenly, and anything past a document's share is marked as truncated. - **Images:** uploaded images and rendered pages of scanned PDFs, up to four. - **Conversation:** the last four messages, 1,200 characters each, so a follow-up such as *"now turn it into a PDF"* knows what *"it"* means. - **Intent flags:** two regular expressions check whether the user asked for a PDF (`isPdfRequestedPrompt`) or for screenshots (`isScreenshotRequestedPrompt`). ### Two modes: answering and acting Not every prompt needs the browser. `buildAgentPrompt` in `src/lib/ollama.ts` decides between two prompt styles with `isActionOrientedPrompt`, a regular expression that looks for words such as *fill*, *click*, *search*, *go to* and *visit*, bare domains like `github.com`, and time words like *latest* or *today's*. Words that only describe a PDF deliverable are removed first, so *"make a PDF of this page"* does not trigger browsing. - **Answer mode:** for a plain question about the page or a document, the model streams a Markdown answer straight into the chat. It takes one step. - **Action mode:** for anything that needs the browser, the model must end its reply with a JSON object. Every step after the first is always in action mode. The JSON contract in action mode looks like this: ```json { "answer": "Markdown answer (full when complete, a short progress note otherwise)", "summary": "Short 1-line status of this step", "notes": "Key facts from THIS page, with the source URL", "status": "continue", "actions": [{ "action": "search_web", "value": "best budget laptops 2026" }] } ``` The model can choose from 13 actions: `fill`, `select`, `check`, `click`, `press_enter`, `scroll`, `navigate`, `search_web`, `open_result`, `go_back`, `screenshot`, `generate_pdf` and `extract_to_memory`. ### One round of the loop 1. **Observe.** The side panel asks for a snapshot of the active tab: readable text, a numbered list of interactive elements and, on search pages, a numbered list of results. If the page has little text, it captures screenshots instead. If the page is a CAPTCHA wall, the loop stops and hands control back to you, along with any notes gathered so far. 2. **Think.** The prompt is assembled from the request, the snapshot, your profile, relevant knowledge, documents, earlier step summaries and notes. It goes to the text model, or to the vision model when images are attached. Reasoning streams live into the step card. 3. **Act.** The reply is parsed and its actions are sorted into four groups: memory writes, screenshot requests, PDF builds and browser actions. Browser actions run on the active tab. 4. **Decide.** The loop runs again only if there is something new to look at. ![Flowchart of one Any Agent prompt across up to six rounds: Observe snapshots the tab (or hands control back to you on a CAPTCHA wall), Think streams the model, Act runs the actions, and a decision diamond checks whether there is anything new to read before looping back or finishing to write the PDF, show the answer and learn memory.](https://yadunandansingh.com/blog/how-any-agent-works/agent-loop.webp "Agent loop · 3 stages, 1 decision, 2 exits") A round sends the agent back to Observe only when the last step opened a new page, asked for screenshots, or left browser actions to follow up on. The last rule is short enough to quote: ```ts const wantsAnotherStep = screenshotRequested || navigated || (stepResult.status === 'continue' && domActions.length > 0); const isFinishing = !wantsAnotherStep || stepNum >= settings.maxSteps; ``` ### Keeping each step small Two rules keep the prompt short enough for an 8B model: - **Notes replace history.** Earlier pages are never shown to the model again. Instead, each step writes the facts it found into `notes`, tagged with the source URL, and later steps see only those notes. The final answer draws on every page visited without carrying every page in the prompt. - **One navigation per step.** After parsing, the agent keeps only the actions up to and including the first navigation (`navigate`, `search_web`, `open_result` or `go_back`). Anything after it would point at element ids on a page that no longer exists. On the final step, the prompt tells the model not to navigate and to write the best complete answer it can from its notes. ### After the loop If you asked for a PDF and none was built during the loop, a separate writing pass produces the document (see *Documents in, PDFs out* below). Then, without blocking the interface, the agent checks whether your message revealed anything new about you that is worth remembering. The **Stop** button aborts the whole run through an `AbortController` that is passed to each model request in the run. ## Reading and acting on web pages A small model cannot reason over raw HTML, so the content script (`src/content/index.ts`) turns each page into a short, numbered text summary, and turns the model's numbered actions back into real DOM events. ### The page distiller `distillPage()` builds a `PageSnapshot` with four main parts: - **Interactive elements.** Form fields are collected first, then buttons and links, so inputs always get the low ids `[1]`, `[2]` and are never crowded out by navigation links. The list stops at 90 elements. When a page has more than two form fields, links inside `nav`, `header` and `footer` are skipped. Each element is tagged with a `data-any-agent-id` attribute so the model can point at it by number. - **Readable text.** A `TreeWalker` walks the `main` or `article` container, skips scripts, navigation, footers and hidden nodes, and keeps headings, paragraphs, list items and table cells, with duplicates removed. Headings are prefixed with `#` and list items with `•`. The text is capped at 9,000 characters. If the walk finds under 200 characters, as on single-page apps built from nested `div`s, it falls back to `document.body.innerText`. - **Search results.** On Google, DuckDuckGo and Bing result pages, the distiller parses up to 10 organic results with their full URLs, unwrapping DuckDuckGo and Google redirect links. The noisy link list is replaced by a clean numbered list, so the model can simply say `open_result 2`. - **A verification check.** `detectHumanVerification()` flags CAPTCHA walls by page title (*"Just a moment"*, *"Are you a robot"*), by Google's `/sorry/` path, or by a reCAPTCHA, hCaptcha or Turnstile widget on a short page. The interactive elements reach the model as one line each: ```output [1] | label="Full name" | REQUIRED [2] | label="Email" | placeholder="you@example.com" [3]