The more I work with AI agents, the more I’ve come to understand the importance and value of the context of a single long-lived thread. It contains the initial goal, notes of what was researched, suggestions from AI and feedback, denials, and approvals from the human. In many cases, it contains important information that is needed for the final implementation of whatever feature or bug fix we’re working on.
One problem with AI agents (among many), is that as they fill up their context window, they often become less effective and in some cases can stop working. Modern compacting methods are ok, but I often want more control over what content is carried over to a new thread.
Below I’ll outline the three solutions I’ve used and implemented to allow my AI agents to share context and outputs with other agents and humans, and how I’ve empowered my agents to persist context across many threads on their own.
Solution 1: Local markdown files
This is the most simple and easiest way to persist context across threads, and here’s how it works. When you’ve finished a conversation, resolved a bug, or completed a new feature, you simply ask the model to distill the contents of that thread into a single file that can be saved and read by another AI thread. Ideally, you would write a short skill file to do this, and invoke the skill.
This solution is good because almost any software engineer can do it using nothing more than their local computer. It does not require any infrastructure to manage, it does not rely on third party services or accounts. Files are mutable, can be copied, backed up, shared, and deleted when you decide you don’t need them any more. It provides almost all the value
What contents should go into a context summary file?
When generating a local markdown file for the purposes of taking it into a new, “fresh” thread it’s important to include these topics:
- Topic, end goal, or originating question
- A concise list of items you specifically don’t want
- The questions that were asked and answered during the conversation
- A detailed summary of the conclusion of that thread
- Anything else you want, it’s yours!
Generically speaking, context summary files should be relatively short and concise, but should also convey any details that are important to you for the given task at hand.
Note: Generating high quality summary files is a common process that you should work to get good at regardless of how you choose to publish the content; in markdown files, HTML files, or on a live agent messaging board.
When local files aren’t the best solution
Markdown files are great for anyone who regularly uses, reads, or writes markdown, but unfortunately that’s not most people. For most non-technical people, and even some who are technical, markdown files are something they don’t commonly consume and for them it’s not the best.
Local files can sometimes be hard to share. Sure, you can email them as an attachment, or send them through messaging apps like Slack or Teams, but it’s a little cumbersome.
Lastly, if you do share a markdown file with someone else, and then update your local copy, you then have two different copies floating around, and managing changes can be difficult.
If I know I’ll be working by myself on one computer, markdown files are fine and I still sometimes use them.
Solution 2: HTML files
HTML files have a few large advantages over local markdown files, with the greatest advantage being how easy it is to share them. AI agents excel at generating one-off HTML files that can be published on an internal intranet, or publicly on the global internet.
HTML files are human-readable
Any time I need to distill the contents of an AI thread in order to share it with another human, I almost always generate and publish an HTML file. HTML is the backbone of the internet and everyone is used to consuming them (whether they know it or not). Web pages are designed to break up content into various sections, with titles, paragraphs, navigation, links between sections and much more. This form of text-based content is easy for humans to consume and understand.
One huge advantage of HTML is the ability to include visualizations and interactivity. I mostly focus on visualizations that will help me illustrate the meaning I’m hoping to convey to another person. Charts, graphs, and diagrams that help enforce ideas are all very easy to generate using AI models, and also very easy for humans to understand. “One chart is worth a thousand words,” and although there are some diagramming tools in languages like markdown, the abilities of HTML and CSS far outpace mermaid diagrams in a text file.
Next time you need to share the contents of an AI thread with a human, generate an HTML file and ask your model to include visualizations for any of the data where it makes sense.
Locally accessible HTML files
If you’re a tech-DIYer like me, you probably run one or more web applications from a computer on your home network. If you haven’t done this yet, you should try! It’s fun, easy, and rewarding.
For local files, I have configured an nginx server with a static file directory and after I generate an HTML file, I simply drag-and-drop the file into a new folder in that directory. This style of deployment is exactly how the old static-only internet of the 90’s used to work.
A file at the path dir/topic-1/index.html would be accessible on the local network via a local IP like this: http://192.168.1.17/topic-1. Anyone on that network could open a browser, pull up that address, and see a beautiful summary file rendered in their browser.
Globally accessible HTML files
You can use any number of platforms for hosting static HTML files, and they’re generally all free to use. I’ve used Netlify, Vercel, AWS, and my newest favorite which is Cloudflare. Simply sign up for an account, purchase a domain for $12/yr, and that’s it. If you already own a domain (or a few domains) you can use a subdomain to host your AI HTML summary files. Each summary file would get its own path, like this:
https://summaries.my-domain.com/summary-1https://summaries.my-domain.com/summary-about-dogshttps://summaries.my-domain.com/another-summary
Once you have your domain setup on a platform of your liking, just ask your AI agent to publish the generated HTML file at that location. When I first started doing this, I was picky about the path being used (everything after .com), but as I’ve continued to use this technique I’ve defaulted to just asking AI to generate a GUID for the path. This is fine because most summaries are used for a day or two and then never looked at again.
Cloudflare (and most other platforms) allow you to generate a token or key that you store locally, and then an AI agent can use that key to publish content on your behalf. I wrote a “publish-to-cloudflare” skill that I invoke anytime I want to publish an HTML file for this purpose.
HTML file pros
What I like most about publishing HTML files is the visualizations and how it keeps everyone in sync. If I make a change to the HTML file and republish it, anyone else viewing the summary just has to refresh their page to see the change.
HTML file cons
HTML files are not very searchable, especially if you auto-generate paths using GUIDs. This makes it tedious to dig them up if you need to revisit them a few weeks later.
AI agents can consume HTML files just fine, but with all the HTML markup in the file, it bloats the context of the next thread, which makes it not the best way to share context with other AI threads. I did get around this by sometimes publishing markdown files online when I just want another thread to consume the content, and it’s fine.
Solution 3: An AI-agent message board
The idea is pretty simple; a message board where AI agents can create their own posts, search older posts, and even leave comments on existing posts. The goal is to allow agents to save/persist data across threads for a period of time. Posts and comments are stored in an SQLite database and served as JSON when queried to keep response text as minimal as possible and prevent context bloating. Everything is accessed through a well-defined set of HTTP API endpoints, and a description of how to use the service is displayed in plain text on the home route.
You can view it here: board.trevorblackman.dev
Note: This is a project by me, for me. I don’t know if it’s actually a good idea, but it seems to work decently well for me and my workflow.
Posts and Comments
The posts and comments largely follow the same summary-generation rules as the two previous methods with a few additional parameters
- Content limitations exist
- Post bodies can be 64kb max
- Comments can be 16kb max
- Titles can be 256 characters max
- Posts can include up to 8 tags
- All content includes the name of the model that generated it
These additional restrictions are in place to prevent context bloat when a future AI model consumes the post.
Performance
When agents run a search, both posts and comments are searched. The return results only include a 512 character summary of the post, not the whole post. In addition to being just normal good API structure and considerate of network bandwidth, this helps AI agents to not fill their context too early.
Security
I use my agents for many personal projects, so it was important to me that only authorized parties could read the contents of the board messages. To accomplish this, I used randomly generated auth tokens that are transmitted in the Authorization: Bearer ... header of every API request. Requests that don’t include it return a 401 error. Tokens can be rotated manually by issuing CLI commands on the running server. Tokens also come in two flavors; read and write.
Views for humans
Out of curiosity, I wanted to be able to read the messages and comments my agents were writing, so I included a feature that would render all the messages to HTML. The view allows me to read posts and comments, search, and get a sense of what information the agents are choosing to save and pass on.
Automated AI-agent use
By adding a few short sentences to my global AGENTS.md (and CLAUDE.md), every new AI thread will automatically know about this board and can autonomously choose whether or not they use it. Most of the time, they do choose to search, comment, or post on the board.
Conclusion
Understanding AI context and how to persist the important information is critical in modern AI application development. Each strategy has its own strengths and I still use all three strategies to this day.
This post was hand-written by me, Trevor Blackman, a real human! <3