Agent Memory and Context: Why Repeat Visits Matter
The first time an AI agent visits your website, it knows nothing. It has to explore the layout, find the right buttons, and work out how your forms behave. The second time, if the agent has memory, it already knows the path.
This difference between a first visit and a repeat visit is becoming one of the most important factors in agent performance.
How Agent Memory Works
Agent memory comes in several forms, and different frameworks handle it differently.
Session memory is the simplest. Within a single task, the agent remembers what it has already done, closely tied to how agents handle authentication and sessions. It knows it already clicked "Flights" in the navigation, that it filled in the departure city, and that the calendar picker opens when you click the date field. If the page reloads or an error occurs, the agent can retrace its steps. This is not really "memory" in the persistent sense, just context within a running conversation.
Episodic memory persists across sessions. The agent stores summaries of previous interactions with a site: what pages it visited, which paths led to success, which led to dead ends, and what the site's structure looked like. On the next visit, it can recall this information and skip the exploration phase.
Procedural memory goes further. Instead of remembering what happened, the agent remembers how to do things. "To search for flights on this site, go to /flights, fill in the From field, fill in the To field, select dates, and click Search." This is essentially a learned script that the agent can execute directly.
Browser Use and similar frameworks are starting to implement these patterns. Some store interaction traces that can be replayed. Others generate reusable procedures from successful task completions.
Why This Matters for Your Website
A site that is consistent and predictable rewards agent memory. When the agent returns and finds the same structure, its stored knowledge still applies. It can complete the task quickly and reliably.
A site that changes frequently invalidates stored memory. If the navigation rearranges itself, if form fields move around, or if URLs change between visits, the agent's memory becomes a liability rather than an advantage. It might try to click where a button used to be, or follow a URL that no longer works.
This does not mean your site should never change. It means that changes should be additive rather than destructive. Add new features, but keep existing paths working. If you must restructure, consider that agents (and humans with bookmarks) depend on the old structure.
Context Windows and Working Memory
An agent's context window is its working memory. Everything the agent knows about the current task, the current page state, and its instructions has to fit within this window.
Context windows have grown rapidly. Early GPT-4 had 8,000 tokens. Current models support 128,000 to 1,000,000 tokens. But web pages are large. A single page's DOM can be 10,000 tokens. A multi-step task involving ten pages could consume 100,000 tokens of page representations alone, leaving little room for reasoning.
This creates a practical limit on task complexity. An agent booking a simple flight might need three or four page observations. An agent comparison-shopping across five different sites for the best insurance quote might need thirty or forty. The context fills up, and the agent starts losing track of earlier information.
Agent frameworks handle this through summarisation. After the agent finishes with a page, it summarises what it learned (prices found, options available, error encountered) and discards the raw page data. These summaries take far fewer tokens and let the agent carry forward just the essential information.
How Agents Build Site Models
Over repeated visits, agents build mental models of websites. These models capture things like:
Navigation structure. The agent learns that your site has a top navigation bar with five main sections, that "Products" has a dropdown with categories, and that the search function is in the top right.
Interaction patterns. It learns that your forms validate on blur, that your date picker requires clicking month arrows rather than typing dates, and that your "Add to Cart" button triggers a slide-out panel rather than a page transition.
Error handling. It remembers that submitting the form without a required field produces an inline error message rather than a page-level alert, and that the error message appears below the relevant field.
This accumulated knowledge makes the agent faster and more reliable on each subsequent visit. But it assumes the site behaves consistently. If the same action produces different results depending on time of day, A/B test variant, or user segment, the agent's model becomes unreliable.
A/B Testing and Agent Confusion
A/B testing creates a specific problem for agent memory. If an agent encountered version A of your checkout flow on its last visit and version B on this visit, its stored procedure does not match reality.
Some agent frameworks handle this by maintaining confidence scores for their stored knowledge. If the expected element is not found, the confidence drops and the agent switches from replay mode to exploration mode. But this fallback is slower and more error-prone.
If you are running A/B tests on key flows, consider whether agent traffic should receive a consistent variant. This is not just about agent convenience; inconsistent behaviour also affects any automated monitoring tools that verify your site's functionality.
Practical Implications
Stable URLs, consistent navigation, and predictable interaction patterns are not just good UX principles. They are the foundation that allows agents to build reliable mental models of your site.
Here are specific things that help:
- Keep URLs for key functions stable. If
/search?q=flightsworks today, keep it working. - Avoid moving major UI elements between redesigns. If the search bar has been in the header for years, keep it there.
- Use consistent error handling patterns across your site. If one form shows inline errors and another shows modals, agents (and users) have to learn two systems.
- Make sure your sitemap is up to date. Agents can use sitemaps to build initial models of your site structure before they even start browsing.
The agents that visit your site today are building models that will shape their behaviour on future visits. A consistent, well-structured site creates a positive feedback loop where agent performance improves over time. You can run an audit to see how well your site supports these repeat interactions.