<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Blog · Felipe Basurto</title>
    <link>https://felipebasurto.com/blog/</link>
    <atom:link href="https://felipebasurto.com/blog/feed.xml" rel="self" type="application/rss+xml" />
    <description>Notes on building with AI, shipping software, and things I find worth writing down.</description>
    <language>en</language>
    <dc:creator>Felipe Basurto</dc:creator>
    <lastBuildDate>Thu, 29 Oct 2026 00:00:00 GMT</lastBuildDate>
    <item>
      <title>The travelling salesman problem, with prices</title>
      <link>https://felipebasurto.com/blog/viajante/</link>
      <guid isPermaLink="true">https://felipebasurto.com/blog/viajante/</guid>
      <pubDate>Thu, 29 Oct 2026 00:00:00 GMT</pubDate>
      <author>hello@felipebasurto.com (Felipe Basurto)</author>
      <dc:creator>Felipe Basurto</dc:creator>
      <description>Viajante gives any AI assistant live flight and hotel prices. How I decoded Google Flights' undocumented protobuf, how it runs where there is no MCP, and where I think travel software is going.</description>
      <content:encoded><![CDATA[<p class="md-p">After many months, the trip was finally here. I was going to visit a friend who lives in Melbourne, and I had to be there on 15 July. I had more days off than that, so I decided to spend the two weeks before travelling on my own.</p>
<h2 class="md-heading" id="too-many-options"><span class="md-hashes" aria-hidden="true">##</span> Too many options</h2>
<p class="md-p">Bali, Vietnam, China and Kuala Lumpur were all possible. With no fixed dates and no fixed destination, every option looked as good as the others, and I could not pick one.</p>
<p class="md-p">Flight APIs and paid subscriptions mostly charge per search. That is fine for one route, but I wanted every combination of dates and cities, and each combination cost money. Then I found <a class="md-link" href="https://pypi.org/project/fast-flights/" title="https://pypi.org/project/fast-flights/" rel="noopener noreferrer" target="_blank">fast-flights</a>, an open-source library that got Google Flights data with plain HTTP requests. Connected to a model, it let the model run the searches and reason about the results. I gave a coding agent this brief:</p>
<blockquote class="md-bq">
<ul class="md-list md-list--unordered">
<li class="md-li">Leave Madrid on 1 July or later.</li>
<li class="md-li">Be in Melbourne by 15 July.</li>
<li class="md-li">Anything in between. Find the cheapest way there, through a place worth a stop.</li>
</ul>
</blockquote>
<p class="md-p">For this post I asked viajante the same question again, with the dates moved to December. One call ran eight searches in 2.3 seconds:</p>
<div class="md-table-wrap"><table class="md-table">
<thead>
<tr>
<th>Stop</th>
<th>From Madrid, 1 Dec</th>
<th>To Melbourne, 14 Dec</th>
<th align="right">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ho Chi Minh City</td>
<td>284&nbsp;€, 22&nbsp;h</td>
<td>202&nbsp;€, 23&nbsp;h</td>
<td align="right">486&nbsp;€</td>
</tr>
<tr>
<td>Bangkok</td>
<td>284&nbsp;€, 19&nbsp;h</td>
<td>213&nbsp;€, 24&nbsp;h</td>
<td align="right">497&nbsp;€</td>
</tr>
<tr>
<td>Kuala Lumpur</td>
<td>315&nbsp;€, 16&nbsp;h</td>
<td>236&nbsp;€, 11&nbsp;h</td>
<td align="right">551&nbsp;€</td>
</tr>
<tr>
<td>Bali</td>
<td>464&nbsp;€, 18&nbsp;h</td>
<td>150&nbsp;€, 5&nbsp;h&nbsp;40 nonstop</td>
<td align="right">614&nbsp;€</td>
</tr>
</tbody>
</table></div>
<p class="md-p">The cheapest total is not the obvious choice. Ho Chi Minh City is the cheapest, but its second flight waits 13 hours in Singapore. Bali costs 128&nbsp;€ more and ends with a nonstop. I wanted a model to make that kind of choice for me. In July it did, and I spent the two weeks in Thailand.</p>
<p class="md-p">I kept working on the agent after the trip, and replaced the library with my own code.</p>
<h2 class="md-heading" id="the-travelling-salesman-problem"><span class="md-hashes" aria-hidden="true">##</span> The travelling salesman problem</h2>
<p class="md-p">In Spanish, the travelling salesman problem is <em class="md-em">el problema del viajante</em>. Given a list of cities and the distance between each pair, find the shortest route that visits every city once. Each new city multiplies the number of routes, so with a few dozen cities solvers accept a good route instead of the best one:</p>
<p class="md-p">My trip was a harder version. The distances were prices, the prices changed every day, and the route had to end in Melbourne instead of returning home. That is where the name comes from. Viajante gives any AI assistant live flight and hotel prices, so the assistant can work on that problem for you.</p>
<h2 class="md-heading" id="decoding-a-protobuf-nobody-documented"><span class="md-hashes" aria-hidden="true">##</span> Decoding a protobuf nobody documented</h2>
<p class="md-p">Viajante has no API to call. For flights it asks Google Flights for the same public results page a browser loads, and reads the answer. The hard part is writing the search. It lives in the URL, in a parameter called <code class="md-codespan"><span class="md-muted">`</span>tfs<span class="md-muted">`</span></code>, and <code class="md-codespan"><span class="md-muted">`</span>tfs<span class="md-muted">`</span></code> is a protobuf.</p>
<p class="md-p">A protobuf is Google&#39;s binary format for structured data. A protobuf stores each value as a field number, a type and the value. There are no names, and Google publishes no schema for this one. Without it, <code class="md-codespan"><span class="md-muted">`</span>48 01<span class="md-muted">`</span></code> is just &quot;field 9 is 1&quot;. Nothing says that field 9 is the cabin and 1 is economy.</p>
<p class="md-p">fast-flights gave me a starting point. It encoded origin, destination, date, passengers and cabin. Every other filter on the page, such as departure time, duration, layover, price and airlines, had no known field.</p>
<h3 class="md-heading" id="change-one-thing-diff-the-bytes"><span class="md-hashes" aria-hidden="true">###</span> Change one thing, diff the bytes</h3>
<p class="md-p">The method is the one you would use on any binary format. Open Google Flights in a browser, change one control, copy the URL, decode the <code class="md-codespan"><span class="md-muted">`</span>tfs<span class="md-muted">`</span></code> before and after, and read what moved. A search is a few dozen bytes, so an AI model can decode two of them and tell you which bytes changed in seconds. Reading hex like this used to take an afternoon. With an agent it takes minutes, and that is what made every filter below possible.</p>
<p class="md-p">Two details make the diffs readable. A protobuf message starts with its length, so adding a filter inside the flight also changes the length byte in front of it. And a number above 127 takes two bytes, seven bits each, which is why 600 minutes is <code class="md-codespan"><span class="md-muted">`</span>d8 04<span class="md-muted">`</span></code>.</p>
<h3 class="md-heading" id="the-page-tells-you-if-you-were-right"><span class="md-hashes" aria-hidden="true">###</span> The page tells you if you were right</h3>
<p class="md-p">A decoded URL is only a guess. The proof is whether Google applied it. After a search, the results page shows the active filters as chips, such as &quot;Under 3 hr, Duration, Selected&quot;. So the work had two halves. When I did not know a field, I captured it from the browser. Then an agent swept variants, sending guesses as plain GET requests and reading the chips back. A guess that comes back as a chip is a field.</p>
<p class="md-p">Some guesses never did, and those are part of the result:</p>
<ul class="md-list md-list--unordered">
<li class="md-li"><strong class="md-strong">Carry-on bags</strong> came from a capture. I recorded the Bags panel and found a sub-message at field 13, with the count at field 2. Google echoes it as &quot;1 carry-on bag, Bags, Selected&quot;.</li>
<li class="md-li"><strong class="md-strong">Checked bags</strong> share that sub-message, in field 3. No probe ever produced a chip for them, so viajante refuses the filter instead of sending something it cannot prove.</li>
<li class="md-li"><strong class="md-strong">Airline exclusion</strong> is a field Google accepts and then ignores. The airline stays in the results, so viajante drops those flights itself.</li>
<li class="md-li"><strong class="md-strong">Departure and arrival times</strong> only take whole hours, so &quot;after 18:30&quot; cannot be sent. Viajante sends 18:00, so Google never removes a flight you would keep, and then applies 18:30 exactly on every row.</li>
</ul>
<p class="md-p">If a chip is missing, the search fails as <code class="md-codespan"><span class="md-muted">`</span>markup_drift<span class="md-muted">`</span></code> instead of returning results that may not be filtered.</p>
<p class="md-p">This is the map viajante uses today:</p>
<div class="md-table-wrap"><table class="md-table">
<thead>
<tr>
<th>Field</th>
<th>What it holds</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong class="md-strong">In each flight</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>date</td>
<td><code class="md-codespan"><span class="md-muted">`</span>2026-11-12<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>5</td>
<td>maximum stops</td>
<td><code class="md-codespan"><span class="md-muted">`</span>1<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>6, 7</td>
<td>airlines to include, to exclude</td>
<td><code class="md-codespan"><span class="md-muted">`</span>BA<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>8, 9</td>
<td>earliest, latest departure hour</td>
<td><code class="md-codespan"><span class="md-muted">`</span>18<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>10, 11</td>
<td>earliest, latest arrival hour</td>
<td><code class="md-codespan"><span class="md-muted">`</span>22<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>12</td>
<td>maximum travel time, in minutes</td>
<td><code class="md-codespan"><span class="md-muted">`</span>600<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>13, 14</td>
<td>origin, destination</td>
<td><code class="md-codespan"><span class="md-muted">`</span>JFK<span class="md-muted">`</span></code>, <code class="md-codespan"><span class="md-muted">`</span>LHR<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>18</td>
<td>maximum layover, in minutes</td>
<td><code class="md-codespan"><span class="md-muted">`</span>120<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>19</td>
<td>fewer emissions</td>
<td><code class="md-codespan"><span class="md-muted">`</span>1<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td><strong class="md-strong">For the whole search</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>one flight message per leg</td>
<td></td>
</tr>
<tr>
<td>8</td>
<td>passengers</td>
<td><code class="md-codespan"><span class="md-muted">`</span>1<span class="md-muted">`</span></code> = adult</td>
</tr>
<tr>
<td>9</td>
<td>cabin</td>
<td><code class="md-codespan"><span class="md-muted">`</span>1<span class="md-muted">`</span></code> = economy, <code class="md-codespan"><span class="md-muted">`</span>3<span class="md-muted">`</span></code> = business</td>
</tr>
<tr>
<td>12</td>
<td>price cap</td>
<td><code class="md-codespan"><span class="md-muted">`</span>400<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>13</td>
<td>carry-on bags</td>
<td><code class="md-codespan"><span class="md-muted">`</span>1<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>17</td>
<td>hide separately booked tickets</td>
<td><code class="md-codespan"><span class="md-muted">`</span>1<span class="md-muted">`</span></code></td>
</tr>
<tr>
<td>19</td>
<td>trip type</td>
<td><code class="md-codespan"><span class="md-muted">`</span>2<span class="md-muted">`</span></code> = one-way, <code class="md-codespan"><span class="md-muted">`</span>1<span class="md-muted">`</span></code> = round trip</td>
</tr>
</tbody>
</table></div>
<p class="md-p">Tests pin the bytes of this map against URLs decoded by hand, so if Google changes the format, a test fails before a user sees a wrong result. Two gaps remain. Field 10 inside each flight, the earliest arrival hour, and the premium-economy and first-class cabins (<code class="md-codespan"><span class="md-muted">`</span>2<span class="md-muted">`</span></code> and <code class="md-codespan"><span class="md-muted">`</span>4<span class="md-muted">`</span></code>) are written but never byte-checked.</p>
<h3 class="md-heading" id="what-i-have-not-decoded"><span class="md-hashes" aria-hidden="true">###</span> What I have not decoded</h3>
<p class="md-p">Google&#39;s answer is a JSON array with no names, only positions. It sits in the page inside a script, about 90 KB in a 1.9 MB page. Viajante finds it by counting brackets and parses it as JSON, without running Google&#39;s JavaScript. Each flight has 25 positions and each leg has 33. Viajante reads about seven of the flight positions and eight of the leg positions. They cover price, times, stops, layovers, carriers and flight numbers. The array also holds the aircraft, the length of each segment, the operating carrier and the base, tax and fee breakdown, and viajante does not read them.</p>
<p class="md-p">Did I decode all of it? No. I decoded what a model needs to choose a flight.</p>
<h3 class="md-heading" id="google-sends-less"><span class="md-hashes" aria-hidden="true">###</span> Google sends less</h3>
<p class="md-p">Once the filters were in the URL, Google stopped sending what the model did not want. Take a one-way search from JFK to London, leaving after 18:00, with at most 10 hours of travel. Version 1.5.0 sent neither filter. Google returned all 116 itineraries and viajante dropped 98 of them itself. Version 1.5.2 puts both in the <code class="md-codespan"><span class="md-muted">`</span>tfs<span class="md-muted">`</span></code>, and Google returns only the 18 that qualify. That is less than half the HTML, 2.6 MB instead of 5.8, and a median of 1.1 seconds instead of 2.3. Both end with the same 18 flights.</p>
<p class="md-p">Hotels work differently. Viajante sends a POST to the internal endpoint that Google&#39;s web apps share, with the search as a 413-byte JSON array, and gets about 200 KB of JSON back. It reads the total for the stay and never the nightly price.</p>
<h2 class="md-heading" id="when-the-assistant-has-no-mcp"><span class="md-hashes" aria-hidden="true">##</span> When the assistant has no MCP</h2>
<p class="md-p">Viajante is an MCP server, which most assistants and coding agents can use. Instinct is a personal assistant you message like a contact, and it has no way to plug in a custom MCP server. <a class="md-link" href="https://dev.to/chilarai/no-mcp-no-problem-how-i-got-instinct-ai-to-call-a-flight-api-31g0" title="https://dev.to/chilarai/no-mcp-no-problem-how-i-got-instinct-ai-to-call-a-flight-api-31g0" rel="noopener noreferrer" target="_blank">One developer</a> who wanted flights in it built a bridge. Instinct writes requests into a Google Sheet, and a script polls the sheet and calls an API.</p>
<p class="md-p">I did not want anyone to need a bridge. Instinct can write a Python file and run it, so viajante is also a Python library. The setup message on the landing page tells Instinct that it has a Python sandbox, not an MCP config, and that viajante is on PyPI. Instinct then writes something like this and runs it:</p>
<div class="md-codeblock"><div class="md-codeblock-gutter" aria-hidden="true">```python</div><pre class="md-pre"><code class="md-code language-python"><span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> date
<span class="hljs-keyword">from</span> viajante <span class="hljs-keyword">import</span> HotelQuery, search_hotels

hotels = search_hotels(
    [HotelQuery(location=<span class="hljs-string">&quot;Bangkok&quot;</span>, check_in=date(<span class="hljs-number">2026</span>, <span class="hljs-number">12</span>, <span class="hljs-number">1</span>), check_out=date(<span class="hljs-number">2026</span>, <span class="hljs-number">12</span>, <span class="hljs-number">8</span>))],
    currency=<span class="hljs-string">&quot;EUR&quot;</span>, source=<span class="hljs-string">&quot;google&quot;</span>, top=<span class="hljs-number">3</span>,
)</code></pre></div>
<p class="md-p">The same code sits behind the MCP server, the command line and the Python library, so an assistant that cannot load a tool can still call code.</p>
<h2 class="md-heading" id="why-it-is-fast"><span class="md-hashes" aria-hidden="true">##</span> Why it is fast</h2>
<p class="md-p">Almost every speed-up in viajante came from sending fewer requests, or sending them at the same time.</p>
<p class="md-p"><strong class="md-strong">No browser.</strong> For a normal search viajante never starts Chromium. It sends plain HTTP requests with <a class="md-link" href="https://github.com/lexiforest/curl_cffi" title="https://github.com/lexiforest/curl_cffi" rel="noopener noreferrer" target="_blank">curl_cffi</a>, a Python binding for curl that copies Chrome&#39;s TLS handshake, so Google answers it like a browser.</p>
<p class="md-p"><strong class="md-strong">Fewer requests.</strong> Google shows a consent page to visitors from the EU, and declining it costs extra requests before the first result. Viajante keeps the decline cookie for 30 days and skips that step. A round trip adds a second problem. Google prices it as a package and shows the return flights only after you pick an outbound flight. So viajante opens one return page for each of the eight cheapest outbound flights. Version 1.4.7 opened them one by one. Today all eight go out together:</p>
<p class="md-p">I ran the same round trip, JFK to Lisbon, three times on each version. The median was 9.9 seconds in 1.4.7 and 2.5 in 1.5.2, with the same cheapest package. The saved cookie only helps after a first search. On a machine that has never searched, a one-way search takes 3.7 to 3.9 seconds, as slow as the old versions. Most of the time goes to the network, not the parser.</p>
<h2 class="md-heading" id="designed-for-a-model-not-a-person"><span class="md-hashes" aria-hidden="true">##</span> Designed for a model, not a person</h2>
<p class="md-p">A person wants one good answer. A model needs the data behind it, a way to tell what is known from what is not, and as few tokens as possible.</p>
<p class="md-p"><strong class="md-strong">The raw offers come first.</strong> The model gets the top eight offers, each with every field Google returned. A shortlist labels flights by what they are, such as <code class="md-codespan"><span class="md-muted">`</span>lowest_price<span class="md-muted">`</span></code> or <code class="md-codespan"><span class="md-muted">`</span>shortest<span class="md-muted">`</span></code>, never by whether they are best, and each trade-off names a missing field, like &quot;Checked bag fee unknown&quot;. The decision stays with the model.</p>
<p class="md-p"><strong class="md-strong">Empty has three meanings.</strong> Every tool returns the same envelope, and <code class="md-codespan"><span class="md-muted">`</span>empty_reason<span class="md-muted">`</span></code> says why there are no results. <code class="md-codespan"><span class="md-muted">`</span>provider_empty<span class="md-muted">`</span></code> means Google returned nothing. <code class="md-codespan"><span class="md-muted">`</span>filtered_out<span class="md-muted">`</span></code> means Google returned results and the filters removed them all. <code class="md-codespan"><span class="md-muted">`</span>not_loaded<span class="md-muted">`</span></code> means the search did not finish. The model may say &quot;there are no flights&quot; only in the first case.</p>
<p class="md-p"><strong class="md-strong">Every offer carries its evidence.</strong> Each one has the time it was fetched, the search URL, the booking URL and a list of which fields are known. Before the model answers, <code class="md-codespan"><span class="md-muted">`</span>verify_answer<span class="md-muted">`</span></code> checks its draft against the searches and flags any price, airport code or link that no search returned.</p>
<h2 class="md-heading" id="where-travel-software-is-going"><span class="md-hashes" aria-hidden="true">##</span> Where travel software is going</h2>
<p class="md-p">Skyscanner, Kayak, Google Flights and Booking.com assume a person who searches one route and one set of dates at a time, then clicks through the results. An assistant can run dozens of searches in the time a person runs one, remember every result and read every review in any language. The interface is what slows it down.</p>
<p class="md-p">I think many interfaces are going away. A lot of software exists so that a person can drive a database by clicking through filters, tabs, a calendar and a checkout form. An agent needs none of that. It needs something to talk to, an MCP server or a library, and I expect many services to end up as exactly that.</p>
<p class="md-p">Viajante is my bet on what that looks like for travel. I do not think the booking site of the future is somewhere you click. I think it is an agent that does the searching, across every date and city, and comes back with two or three finalists and their photos. It tells you which one it would take and why, for example closer to the airport, one stop fewer, or 128&nbsp;€ more for a nonstop. You say yes, and it pays with the card you saved. You never open a filter.</p>
<p class="md-p">Search, comparison and the recommendation work today. Photos and payment do not. In a few years a tool like viajante may not be needed, because the providers will offer an interface for agents themselves. Today they do not, so someone has to.</p>
<h2 class="md-heading" id="try-it"><span class="md-hashes" aria-hidden="true">##</span> Try it</h2>
<p class="md-p">With Node, add this to your assistant&#39;s MCP configuration:</p>
<div class="md-codeblock"><div class="md-codeblock-gutter" aria-hidden="true">```json</div><pre class="md-pre"><code class="md-code language-json"><span class="hljs-punctuation">{</span>
  <span class="hljs-attr">&quot;mcpServers&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
    <span class="hljs-attr">&quot;viajante&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
      <span class="hljs-attr">&quot;command&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;npx&quot;</span><span class="hljs-punctuation">,</span>
      <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">&quot;-y&quot;</span><span class="hljs-punctuation">,</span> <span class="hljs-string">&quot;@viajante/mcp&quot;</span><span class="hljs-punctuation">]</span>
    <span class="hljs-punctuation">}</span>
  <span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span></code></pre></div>
<p class="md-p">Without Node, install <a class="md-link" href="https://docs.astral.sh/uv/getting-started/installation/" title="https://docs.astral.sh/uv/getting-started/installation/" rel="noopener noreferrer" target="_blank">uv</a> and use <code class="md-codespan"><span class="md-muted">`</span>&quot;command&quot;: &quot;uvx&quot;<span class="md-muted">`</span></code> with <code class="md-codespan"><span class="md-muted">`</span>&quot;args&quot;: [&quot;--from&quot;, &quot;viajante[mcp]&quot;, &quot;viajante-mcp&quot;]<span class="md-muted">`</span></code>. For an assistant with no MCP, run <code class="md-codespan"><span class="md-muted">`</span>pip install viajante<span class="md-muted">`</span></code> on Python 3.10 or newer. Then ask it for a trip with a date to hit and a few days to spare. This is how I use it:</p>
<p class="md-p">The code is on <a class="md-link" href="https://github.com/felipebasurto/viajante" title="https://github.com/felipebasurto/viajante" rel="noopener noreferrer" target="_blank">GitHub</a> and the package is on <a class="md-link" href="https://pypi.org/project/viajante/" title="https://pypi.org/project/viajante/" rel="noopener noreferrer" target="_blank">PyPI</a>. If something breaks, <code class="md-codespan"><span class="md-muted">`</span>viajante feedback<span class="md-muted">`</span></code> opens a GitHub issue with your version already filled in.</p>
<h2 class="md-heading" id="limits"><span class="md-hashes" aria-hidden="true">##</span> Limits</h2>
<ul class="md-list md-list--unordered">
<li class="md-li"><strong class="md-strong">Google can change the page at any time.</strong> Searches then fail as <code class="md-codespan"><span class="md-muted">`</span>markup_drift<span class="md-muted">`</span></code> until I update viajante.</li>
<li class="md-li"><strong class="md-strong">Rate limits are a guess.</strong> After a 429 or a refused request, viajante pauses every Google search on the computer for 2 minutes, or for as long as Google asks, up to 30.</li>
<li class="md-li"><strong class="md-strong">It does not book.</strong> Check the final price and the cancellation terms on the provider before you pay.</li>
</ul>
<h2 class="md-heading" id="lessons"><span class="md-hashes" aria-hidden="true">##</span> Lessons</h2>
<ul class="md-list md-list--unordered">
<li class="md-li"><strong class="md-strong">Sending a filter proves nothing.</strong> Check that the provider applied it, send a looser bound when you cannot send the exact one, and filter exactly yourself.</li>
<li class="md-li"><strong class="md-strong">Empty has to say why, and a guess has to be refused.</strong> An error the model can explain is better than a quiet wrong answer.</li>
</ul>
<p class="md-p">Viajante does one narrow job. It gets an assistant the same flight and hotel data a person sees in a browser, in a few seconds, and it says when it could not. The route, the trade-offs and the opinion stay with the model. That is what I wanted in July, with two weeks, a date in Melbourne and no plan.</p>
]]></content:encoded>
      <category>AI agents</category>
      <category>MCP</category>
      <media:content url="https://felipebasurto.com/assets/blog/viajante/og.png" medium="image" type="image/png" />
    </item>
    <item>
      <title>Model context is not static</title>
      <link>https://felipebasurto.com/blog/model-context-is-not-static/</link>
      <guid isPermaLink="true">https://felipebasurto.com/blog/model-context-is-not-static/</guid>
      <pubDate>Wed, 23 Sep 2026 00:00:00 GMT</pubDate>
      <author>hello@felipebasurto.com (Felipe Basurto)</author>
      <dc:creator>Felipe Basurto</dc:creator>
      <description>In 78% of 67,074 public coding-agent runs, the agent kept re-sending code that its own edit had made stale. I built a context engine, based on the CORVUS paper, that keeps that code current. It works byte for byte, but the model did not reliably do better, and requests did not get cheaper.</description>
      <content:encoded><![CDATA[<p class="md-p">A coding agent reads a function:</p>
<div class="md-codeblock"><div class="md-codeblock-gutter" aria-hidden="true">```js</div><pre class="md-pre"><code class="md-code language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">total</span>(<span class="hljs-params">quantity</span>) {
  <span class="hljs-keyword">return</span> quantity * <span class="hljs-number">10</span>;
}</code></pre></div>
<p class="md-p">Then something or someone edits the file: the agent itself, a formatter, another process or another agent. Now the multiplier is <code class="md-codespan"><span class="md-muted">`</span>20<span class="md-muted">`</span></code>. What does the model see on its next request?</p>
<p class="md-p">The file on disk says <code class="md-codespan"><span class="md-muted">`</span>20<span class="md-muted">`</span></code>. The model still sees <code class="md-codespan"><span class="md-muted">`</span>10<span class="md-muted">`</span></code>, because the agent&#39;s earlier read is still in the model&#39;s context, and most agents re-send the whole conversation on every request. The tools work on one version of the file while the model reasons from another.</p>
<p class="md-p">What usually happens is that the agent can read the file again, and it often does, but then it depends on the model deciding to. I built <a class="md-link" href="https://github.com/felipebasurto/freshctx" title="https://github.com/felipebasurto/freshctx" rel="noopener noreferrer" target="_blank">FreshCtx</a> to take that job away from the model. It is a local context engine: a program that rebuilds a current view of the code the agent has read before every request is sent.</p>
<p class="md-p">This post measures how often the problem shows up in public agent runs, explains the paper FreshCtx is based on and how the engine works, and then answers three questions:</p>
<ul class="md-list md-list--unordered">
<li class="md-li">Is the code the model receives current?</li>
<li class="md-li">Does the model do better with it?</li>
<li class="md-li">What does it cost?</li>
</ul>
<p class="md-p">If you prefer video, this <a class="md-link" href="https://www.youtube.com/watch?v=DIVOnXUCZkg" title="https://www.youtube.com/watch?v=DIVOnXUCZkg" rel="noopener noreferrer" target="_blank">walkthrough on YouTube</a> covers the same material:</p>
<details class="md-details">
<summary class="md-details__summary">Words used in this article</summary>

<ul class="md-list md-list--unordered">
<li class="md-li"><strong class="md-strong">Harness:</strong> the program around the model that runs tools, records their results and builds each model request.</li>
<li class="md-li"><strong class="md-strong">Request:</strong> everything sent to the model in one call, usually the whole conversation so far.</li>
<li class="md-li"><strong class="md-strong">File view:</strong> a tool result that shows a file or some of its lines.</li>
<li class="md-li"><strong class="md-strong">Stale:</strong> the file has changed since the view, so at least one line it shows no longer matches the disk.</li>
<li class="md-li"><strong class="md-strong">Marker:</strong> a short placeholder that replaces an old file view in the request.</li>
<li class="md-li"><strong class="md-strong">Projection:</strong> the current code for what the agent has read, added once at the end of the request.</li>
<li class="md-li"><strong class="md-strong">Prompt cache:</strong> providers charge less for the start of a request when it is identical to the start of an earlier one.</li>
</ul>
</details>

<h2 class="md-heading" id="every-coding-agent-sees-old-code"><span class="md-hashes" aria-hidden="true">##</span> Every coding agent sees old code</h2>
<p class="md-p">Cursor, Claude Code, Codex, Devin, OpenCode, OpenHands, Hermes and Pi all run the same basic loop. The model reads the request and decides what to do next. The harness gives it tools, such as reading a file, editing one or running a command: the model asks for one, the harness runs it and adds its output, the tool result, to the conversation. The model never touches the disk. Everything it knows about the code comes from tool results in the request.</p>
<p class="md-p">The simplest way to build the next request, and the usual one, is to re-send the whole conversation so far, with every tool result in it, until compaction trims it:</p>
<p class="md-p">A file read does two jobs: it records what a tool returned at one moment, and it supplies source code for later reasoning. The two agree until the file changes. Keeping the old result is useful for debugging; reusing it as current source is the risk. The conversation is a cache that never refreshes.</p>
<h2 class="md-heading" id="how-often-it-happens"><span class="md-hashes" aria-hidden="true">##</span> How often it happens</h2>
<p class="md-p">To count it, I used a public dataset, <a class="md-link" href="https://huggingface.co/datasets/nebius/SWE-rebench-openhands-trajectories" title="https://huggingface.co/datasets/nebius/SWE-rebench-openhands-trajectories" rel="noopener noreferrer" target="_blank">nebius/SWE-rebench-openhands-trajectories</a>. It holds 67,074 runs of OpenHands, an open-source coding agent, using the Qwen3-Coder-480B model to fix real GitHub issues, with every request recorded. Compaction was switched off, so every request carries the whole conversation.</p>
<p class="md-p">The rule was strict: a view counts as stale only when the next thing to touch its file is the agent&#39;s own edit, changing a line the view showed. Reads through shell commands such as <code class="md-codespan"><span class="md-muted">`</span>cat<span class="md-muted">`</span></code> do not count.</p>
<p class="md-p">Here is one interesting case I found. A task asked the agent to fix a bug in <a class="md-link" href="https://github.com/ucfopen/canvasapi" title="https://github.com/ucfopen/canvasapi" rel="noopener noreferrer" target="_blank">canvasapi</a>, a Python library for the Canvas learning platform. The agent read all 231 lines of <code class="md-codespan"><span class="md-muted">`</span>canvasapi/module.py<span class="md-muted">`</span></code>, then edited the function it had just read. The edit added two lines, so everything below line 126 moved down. From then on, every request carried the old read next to a file that no longer matched it:</p>
<p class="md-p">That is just one run. Across all of them, <strong class="md-strong">78% of runs sent the model at least one request with a stale view, and 22% still did in their very last request</strong>. Counted by request instead of by run, about 1 in 7 requests carried one:</p>
<p class="md-p">A stale view is not proof of a wrong answer; if it were, no agent would work. Models often re-read and recover. But it means the prompt holds two versions of the same code, and the model has to work out which is current.</p>
<h2 class="md-heading" id="the-idea-comes-from-corvus"><span class="md-hashes" aria-hidden="true">##</span> The idea comes from CORVUS</h2>
<p class="md-p">Everything here builds on <a class="md-link" href="https://arxiv.org/abs/2607.22711" title="https://arxiv.org/abs/2607.22711" rel="noopener noreferrer" target="_blank">CORVUS</a>, a paper published two months ago by <a class="md-link" href="https://zmw12306.github.io/" title="https://zmw12306.github.io/" rel="noopener noreferrer" target="_blank">Mingwei Zheng</a> of Purdue University, with <a class="md-link" href="https://davidmobrien.github.io/" title="https://davidmobrien.github.io/" rel="noopener noreferrer" target="_blank">David O&#39;Brien</a>, <a class="md-link" href="https://jncsw.github.io/" title="https://jncsw.github.io/" rel="noopener noreferrer" target="_blank">Siwei Cui</a>, <a class="md-link" href="https://pardisp.github.io/" title="https://pardisp.github.io/" rel="noopener noreferrer" target="_blank">Pardis Pashakhanloo</a>, <a class="md-link" href="https://rajdeepmukherjee.com/" title="https://rajdeepmukherjee.com/" rel="noopener noreferrer" target="_blank">Rajdeep Mukherjee</a>, <a class="md-link" href="https://codingsoo.github.io/" title="https://codingsoo.github.io/" rel="noopener noreferrer" target="_blank">Myeongsoo Kim</a> and <a class="md-link" href="https://sachitkuhar.github.io/" title="https://sachitkuhar.github.io/" rel="noopener noreferrer" target="_blank">Sachit Kuhar</a> of AWS AI Labs. </p>
<p class="md-p">They described this problem before I did, and they named its cause: agents keep an append-only history, where a file read is a fixed snapshot that nothing ever updates. Agents then re-read files they already have, and edit from old snapshots, so edits fail and need recovering.</p>
<p class="md-p">Their fix adds one phase to the agent loop. A new <code class="md-codespan"><span class="md-muted">`</span>sync_file<span class="md-muted">`</span></code> tool puts a file on a list and leaves a short marker in the history. Before every step, a context sync reads each listed file from disk and adds its current contents at the end of the prompt. The prompt holds at most one copy of each file, and that copy is current. Simplified from their first two figures:</p>
<p class="md-p">Across 573 tasks and four models, they report 9% to 50% fewer input tokens, up to about half the cost, and pass rates within about 1.4 points of the baseline. </p>
<p class="md-p">They also found that current files work better at the end of the prompt than near the start. Their future work names two open problems: refreshing selected functions instead of whole files, and prompt caching, which gets harder when part of the prompt changes on every step.</p>
<p class="md-p">That gives three broad ways to handle an old file view:</p>
<p class="md-p"><strong class="md-strong">FreshCtx is my attempt at the first item of their future work: refreshing only the functions the agent read, instead of whole files.</strong></p>
<h2 class="md-heading" id="how-freshctx-works"><span class="md-hashes" aria-hidden="true">##</span> How FreshCtx works</h2>
<p class="md-p">FreshCtx follows the CORVUS idea with four differences:</p>
<ul class="md-list md-list--unordered">
<li class="md-li"><strong class="md-strong">No new tool.</strong> The agent reads files the way it always has, and any successful read counts.</li>
<li class="md-li"><strong class="md-strong">Only the outgoing copy changes.</strong> The saved conversation, what the tools really returned, stays as it was for debugging and replay.</li>
<li class="md-li"><strong class="md-strong">Functions, not files.</strong> It refreshes the function, or the range of lines, that the agent read. On five traces from Express, Flask, Go tools and ripgrep, that made the refreshed code 1.7 to 8.6 times smaller than whole files.</li>
<li class="md-li"><strong class="md-strong">An adapter, not an agent.</strong> It runs as a small local process next to the harness, and a thin adapter inside the harness, the bridge, talks to it.</li>
</ul>
<p class="md-p">Before each request, the bridge gets back a rewritten copy: each old view becomes a short marker, and the current code for everything the agent read, the projection, is added once at the end. For the <code class="md-codespan"><span class="md-muted">`</span>total<span class="md-muted">`</span></code> example:</p>
<p class="md-p">The model gets one current version instead of two that disagree, while the saved conversation keeps <code class="md-codespan"><span class="md-muted">`</span>* 10<span class="md-muted">`</span></code> as the record.</p>
<h3 class="md-heading" id="how-does-it-find-the-function-again"><span class="md-hashes" aria-hidden="true">###</span> How does it find the function again?</h3>
<p class="md-p">The agent reads some lines at some position. After an edit, those lines may have moved, and they may have changed. Line numbers are useless for finding them again, since a lot can happen to a file during a coding session, and asking a model would be slow, expensive and unreliable.</p>
<p class="md-p">So FreshCtx reads the file the way a compiler does. It uses <a class="md-link" href="https://tree-sitter.github.io/tree-sitter/" title="https://tree-sitter.github.io/tree-sitter/" rel="noopener noreferrer" target="_blank">Tree-sitter</a>, an open-source parser used by editors such as Neovim and Zed, which turns each file into a tree: the file is the trunk, each function or declaration is a branch, and each line hangs off the branch it belongs to.</p>
<p class="md-p">When the agent reads a line, FreshCtx notes which branch it hangs from. Before the next request, it parses the file again and looks for that branch by name. Lines can move and change, but the branch called <code class="md-codespan"><span class="md-muted">`</span>total<span class="md-muted">`</span></code> is still the branch called <code class="md-codespan"><span class="md-muted">`</span>total<span class="md-muted">`</span></code>.</p>
<p class="md-p">One line read inside a function brings back the whole function because, even though sending less would be cheaper, half a function is very hard to reason about. A top-level line such as <code class="md-codespan"><span class="md-muted">`</span>RATE<span class="md-muted">`</span></code> belongs to no function, so FreshCtx finds it again by the text around it: a best guess.</p>
<p class="md-p">If a file cannot be parsed, FreshCtx falls back to the whole file, and if the same code appears twice and it cannot tell which one was read, it leaves the code out rather than guess. There is room for improvement here, but it will never be an exact science.</p>
<p class="md-p">Parsing is local and fast enough to run before every request, and Tree-sitter still builds a tree when the code has a syntax error, which happens often while an agent is mid-edit.</p>
<h3 class="md-heading" id="what-is-the-projection-and-why-does-it-have-a-size-limit"><span class="md-hashes" aria-hidden="true">###</span> What is the projection, and why does it have a size limit?</h3>
<p class="md-p">The projection is the block of current code that FreshCtx adds at the end of each request: one copy of every function the agent has read, as it is on disk right now. It is re-sent in full on every request, and it sits in the part of the prompt that is billed at full price, as the cost section shows.</p>
<p class="md-p">Without a limit, every function the agent ever read would come back on every request, so a long session would grow more expensive with each step, and the current code would crowd out the conversation in the model&#39;s context window.</p>
<p class="md-p">So the projection has a budget, 128 KiB by default. It fills with the most recently read functions first, on the assumption that what the agent read last is what it is working on, and a function is never cut in half. One that does not fit is left out, and its marker says so, so the model knows to read it again if it needs it.</p>
<p class="md-p">Just before sending, FreshCtx re-reads the chosen files and checks the hash of every piece of code it inserts. If a formatter changed the file after the plan, or a tool call was left without its result, the request is not sent. A half-rewritten request is worse than none.</p>
<h2 class="md-heading" id="is-the-code-in-the-request-up-to-date"><span class="md-hashes" aria-hidden="true">##</span> Is the code in the request up to date?</h2>
<p class="md-p">Yes. I replayed every 56th run of the OpenHands dataset, 1,198 in total. For each one, I rebuilt the repository at its starting commit and ran its views, edits and requests through the engine, without calling a model:</p>
<p class="md-p">Zero stale views.</p>
<p class="md-p">The more telling result is the code in their place: <strong class="md-strong">every piece of it matched the rebuilt file byte for byte at the moment of its request</strong>.</p>
<p class="md-p">One gap remains, however: after an edit, OpenHands prints a snippet of the edited file, which FreshCtx does not track yet, so 1,237 requests still carried stale code that way.</p>
<p class="md-p">A separate check covered an edit from outside the agent: a session in <a class="md-link" href="https://github.com/earendil-works/pi" title="https://github.com/earendil-works/pi" rel="noopener noreferrer" target="_blank">Pi</a>, an open-source coding agent, read a file, another process changed a constant from <code class="md-codespan"><span class="md-muted">`</span>10<span class="md-muted">`</span></code> to <code class="md-codespan"><span class="md-muted">`</span>12<span class="md-muted">`</span></code>, and the next request held <code class="md-codespan"><span class="md-muted">`</span>12<span class="md-muted">`</span></code> with FreshCtx and <code class="md-codespan"><span class="md-muted">`</span>10<span class="md-muted">`</span></code> without it.</p>
<h2 class="md-heading" id="does-the-model-actually-do-better"><span class="md-hashes" aria-hidden="true">##</span> Does the model actually do better?</h2>
<p class="md-p">This is the question that matters most, and it cannot be checked byte for byte. I ran two small live experiments with <a class="md-link" href="https://pi.dev/" title="https://pi.dev/" rel="noopener noreferrer" target="_blank">Pi</a> and the <code class="md-codespan"><span class="md-muted">`</span>deepseek-v4-flash<span class="md-muted">`</span></code> model, each with and without FreshCtx:</p>
<ul class="md-list md-list--unordered">
<li class="md-li"><strong class="md-strong">When the model could re-read, it did worse.</strong> Five tasks gave a session two reads, changed both files while it was closed, then resumed it and checked the answer. Without FreshCtx, the model saw old code, re-read both files and answered correctly every time. With FreshCtx, it had current code from the start, but failed two tasks.</li>
<li class="md-li"><strong class="md-strong">When it could not re-read, it did better.</strong> In one ten-turn session, I changed a file between turns and asked about it with the instruction &quot;Do not use tools. Do not read.&quot; On the turns where the code had changed, plain Pi gave the old value 8 times out of 8. FreshCtx gave the current value 7 times out of 8.</li>
</ul>
<p class="md-p">In the first experiment, each dot is one request after the session resumed, and a run stopped after eight:</p>
<p class="md-p">Both failures came from how the code was presented. In the tax-base task, the reads came back as markers, and nothing linked them to the current code at the end, so the model kept re-reading. It only stopped because each run was capped at eight requests, a limit I set so that a stuck model could not loop forever.</p>
<p class="md-p">In the moved-symbol task, it took the <code class="md-codespan"><span class="md-muted">`</span>46<span class="md-muted">`</span></code> in <code class="md-codespan"><span class="md-muted">`</span>fees.js:region:46<span class="md-muted">`</span></code>, a size in bytes, for a line number, and kept asking for a line that did not exist. The header now says <code class="md-codespan"><span class="md-muted">`</span>46bytes<span class="md-muted">`</span></code>; the marker fix is still open.</p>
<p class="md-p">In the second experiment, the model read the file only on turns 1, 5 and 8:</p>
<p class="md-p">This setup clearly favors FreshCtx by design. Together, the two experiments say that FreshCtx helps when the model would otherwise trust the conversation, and that a marker must say where its current code went.</p>
<p class="md-p">Until that is fixed and tested again, I have no evidence that FreshCtx gives better answers in normal use, where the agent can re-read.</p>
<h2 class="md-heading" id="is-it-cheaper"><span class="md-hashes" aria-hidden="true">##</span> Is it cheaper?</h2>
<p class="md-p">The answer is no. Most of each request is an exact copy of the previous one, so providers serve it from the prompt cache at a fraction of the price, about 1/30 in the DeepSeek price table I used. Only the end is billed in full.</p>
<p class="md-p">FreshCtx keeps the cached start stable, because markers do not change, but it puts the current code in the full-price end:</p>
<p class="md-p">The old views that FreshCtx removes would have been cheap, and the code that replaces them is not. Requests also came out 1.93% larger in the replay, because reading a few lines inside a large function brings the whole function back.</p>
<p class="md-p">CORVUS reports up to half the cost, and the two results do not contradict each other. Its savings come from the agent&#39;s behavior: fewer duplicate reads, fewer failed edits and fewer steps, and the CORVUS authors flag caching as an open problem, as I do. </p>
<p class="md-p">My replay cannot show behavioral savings, because the agent&#39;s actions were fixed in the recording, and my live runs were too small to measure them. In the one resumed task where I compared tokens, FreshCtx used more, 6,489 prompt tokens against 2,410, because the model needed five requests instead of two.</p>
<h2 class="md-heading" id="lessons-for-anyone-building-something-like-this"><span class="md-hashes" aria-hidden="true">##</span> Lessons for anyone building something like this</h2>
<ul class="md-list md-list--unordered">
<li class="md-li"><strong class="md-strong">Measure staleness in your own transcripts.</strong> The rule above is a short script, and it needs nothing but the transcripts.</li>
<li class="md-li"><strong class="md-strong">Rewrite the copy, not the record.</strong> Keep what the tools returned for debugging and replay; change only what you send.</li>
<li class="md-li"><strong class="md-strong">Label every number you show a model.</strong> A bare <code class="md-codespan"><span class="md-muted">`</span>46<span class="md-muted">`</span></code> was read as a line number. The header now says <code class="md-codespan"><span class="md-muted">`</span>46bytes<span class="md-muted">`</span></code>.</li>
<li class="md-li"><strong class="md-strong">Leave a pointer when you move content.</strong> The tax-base loop happened because nothing linked the markers to the code at the end.</li>
<li class="md-li"><strong class="md-strong">Put changing content at the end, and budget for it.</strong> The end works best and keeps the cached start stable, but it is paid in full on every request.</li>
<li class="md-li"><strong class="md-strong">Judge by outcomes.</strong> Current code and a finished task are different things.</li>
</ul>
<h2 class="md-heading" id="what-i-take-from-this"><span class="md-hashes" aria-hidden="true">##</span> What I take from this</h2>
<p class="md-p">Keeping the code in a request current is solvable, and it can be checked byte for byte. Whether it helps is less clear. </p>
<p class="md-p">The model did not do better where it could re-read, and it is not cheaper. The harder problem is making sure the model understands what it was given.</p>
<p class="md-p">This is one agent and one model on one public dataset, plus a handful of live runs. Next, I will make each marker say where its current code went and re-run the resumed tasks with repeated runs. </p>
<p class="md-p">If that still brings no gain, FreshCtx is mainly useful where re-reading does not happen: long sessions, compacted histories and edits from outside the agent. If it does, the next question is whether the gain survives the cache cost.</p>
<h2 class="md-heading" id="try-it"><span class="md-hashes" aria-hidden="true">##</span> Try it</h2>
<p class="md-p">From a clone of the <a class="md-link" href="https://github.com/felipebasurto/freshctx" title="https://github.com/felipebasurto/freshctx" rel="noopener noreferrer" target="_blank">FreshCtx repository</a>, with Node.js 22 or newer:</p>
<div class="md-codeblock"><div class="md-codeblock-gutter" aria-hidden="true">```bash</div><pre class="md-pre"><code class="md-code language-bash">npm run demo</code></pre></div>
<p class="md-p">It runs the real engine on the <code class="md-codespan"><span class="md-muted">`</span>total<span class="md-muted">`</span></code> example, without calling a model, and prints the rewritten request with its checks. There are bridges for <a class="md-link" href="https://github.com/felipebasurto/freshctx/tree/main/bridges/pi" title="https://github.com/felipebasurto/freshctx/tree/main/bridges/pi" rel="noopener noreferrer" target="_blank">Pi</a>, tested against the real agent, and <a class="md-link" href="https://github.com/felipebasurto/freshctx/tree/main/bridges/openhands" title="https://github.com/felipebasurto/freshctx/tree/main/bridges/openhands" rel="noopener noreferrer" target="_blank">OpenHands</a>, tested with recorded requests. To connect another harness, see the <a class="md-link" href="https://github.com/felipebasurto/freshctx/blob/main/docs/protocol.md" title="https://github.com/felipebasurto/freshctx/blob/main/docs/protocol.md" rel="noopener noreferrer" target="_blank">protocol reference</a> and the <a class="md-link" href="https://github.com/felipebasurto/freshctx/blob/main/CONTRIBUTING.md" title="https://github.com/felipebasurto/freshctx/blob/main/CONTRIBUTING.md" rel="noopener noreferrer" target="_blank">contributor guide</a>; pull requests are welcome.</p>
<p class="md-p">The measurements, replays and live runs are all in <a class="md-link" href="https://github.com/felipebasurto/freshctx-research" title="https://github.com/felipebasurto/freshctx-research" rel="noopener noreferrer" target="_blank">freshctx-research</a>.</p>
<p class="md-p">Thanks for reading, and thanks to the CORVUS authors, whose paper this work rests on.</p>
]]></content:encoded>
      <category>Coding agents</category>
      <category>Context engineering</category>
      <media:content url="https://felipebasurto.com/assets/blog/model-context-is-not-static/og.png" medium="image" type="image/png" />
    </item>
  </channel>
</rss>
