AI Engineer Code Summit 2026
Agent Shapes: From Long-Horizon to Open-Ended — Yacine Mahdid, @deeplearningexplained
Loading slides…
Read the talk
Agent Shapes: From Long-Horizon to Open-Ended
An agent can work for hours and still make the same mistake tomorrow. Yacine Mahdid examines eight ways to extend an agent’s reach, then shows how manufacturing engineers and a video editor turn mistakes into changes that survive the next run.
From a talk by Yacine Mahdid
At a glance
Ideas worth remembering
Keep individual model calls manageable. Compaction reduces the history carried forward, external storage preserves material for later retrieval, and fresh workers can handle narrow assignments without inheriting the entire run.
Parallel workers can save elapsed time when the work is independent. Serial dependencies and communication overhead can leave you paying for more tokens with little speedup.
Check what the agent can actually access before trusting its score. A reachable answer, a cooperative reviewer or an accessible grader can make apparent progress misleading.
Expertise can take several forms in a harness. Factory diagnostics needed better signal features, quoting needed the company’s engineering process, and video editing needed both specialist tools and interview vocabulary.
Pair traces with meaningful outcomes, including delayed reviews. Fix recurring problems in the harness first, then use the remaining failures to decide what merits training. A checkpoint alone cannot tell you when a harmful update began.
What does an agent keep from a long day’s work?
Every successful tool call gives an agent something else to read. Run enough of them and the history that helped the model get this far starts to interfere with its next decision. The agent can spend a great many more tokens without getting appreciably closer to finishing.
The software that runs this exchange is the harness. It assembles context for the model, lets it call tools, collects the results and starts another turn. Even a good harness has a peculiar limitation. The agent can spend hours discovering what works, finish the job and leave the software that will run tomorrow’s job completely unchanged.
Yacine Mahdid, who works with manufacturers at Datadom, distinguishes two engineering problems. A long-horizon system has to keep making progress on one extended assignment. His bet for more open-ended systems is an outer loop that uses experience to change how the agent works. In the industrial projects he describes, people already run much of that loop by hand.
The eight agent shapes are ways of changing different parts of this arrangement. They overlap. Moving context into a file makes it possible to search it with code, hand a slice to another agent and keep useful discoveries for the next assignment. Each choice changes what the others can do.
Compact the history and keep the source material outside the model
Compaction makes room for the next turn by reducing what the model carries forward. A developer can decide when to compact, or the model can steer the decision. In the latter case, the timing and the information that survives depend partly on what the model learned during training. A poor stopping point can interrupt a line of work just when the agent needs to continue it.
Mahdid cites NVIDIA research suggesting that good compaction can sustain a long task with a smaller context window. Databricks took the idea into training. Its knowledge agent practiced long assignments with compaction as part of the assignment itself. The model could learn to manage the transition and resume work beyond the stretch of context in which it normally performed well.
Externalizing context gives the agent another option. Keep the original material in a variable, a database or a file system. A recursive language model (RLM) can inspect that material, select a slice and invoke a model on the slice. The source remains available if a later question calls for a different passage. Mahdid describes follow-up work with Qwen 32B on inputs reaching two million tokens, with effective input lengths of 8 to 32 times the model’s context window.
Why should that help even if the whole input fits? Compare what each invocation actually sees. With a single large prompt, the initial context keeps growing as the agent reasons and calls tools. With recursive retrieval, individual calls fetch and work on manageable pieces. The overall problem can be enormous while each local problem still resembles tasks the model encountered in training.
Mahdid calls this staying locally in distribution. It explains much of the appeal of recursion. The agent gets to use a familiar skill repeatedly, even when the assembled task would be quite unfamiliar.
Code lets the agent improve its tools and interfere with its own evaluation
The third shape makes code the interface to the environment. A model that already knows how to program can use that ability to search, manipulate data and operate tools. Mahdid points to a performance gain when Qwen3-Coder could write and run code in its sandbox. The more consequential property of a piece of working code is that the agent can use it again.
That gives rise to the continual harness. In Prime Agent, the logs and outputs of one turn can inform a proposed change to the software around the model. Apply the change on a subsequent turn, keep it if it helps and backtrack if it proves useless. Prompt notes, memories, skills and subagent roles can all change this way while the model weights stay fixed.
There is a good reason to protect the base prompt. An agent that edits away a capability can lose access to the very state it needs to recover. The same freedom also makes reward hacking easy. From inside a coding environment, the harness, the task and the machinery around the task can all look like more code to work with. In one Prime Intellect run, the agent broke the game it was supposed to play.
This makes the sandbox the fifth shape. Its permissions determine what problem the agent actually has to solve. How much of a high benchmark score survives when researchers restrict those permissions? In one study, the agent initially appeared able to complete every task. Performance dropped sharply once the researchers hardened the sandbox and closed off shortcuts.
A coding benchmark illustrates the problem. If a repository’s Git history contains the solution, an agent can recover the answer without doing the engineering the benchmark was designed to measure. Network access expands the set of possible shortcuts again. The line a developer draws around the harness on an architecture diagram has little bearing on what the model can reach.
Who needs the whole history, and who needs to talk to whom?
An orchestrator keeps track of the assignment and gives fresh workers narrower jobs. This is another way to stay locally in distribution. A worker can start with just the information for its part, return a result and leave the orchestrator to decide what comes next. The worker can be another instance of the same language model, a vision model or any other suitable specialist.
Delegation and parallelism have different payoffs. A fresh context can help even when the steps must run in order. Running a hundred agents concurrently, as in one example, can also cut elapsed time if enough work is independent. It generally costs more tokens. In the Google Research comparison Mahdid cites, serial tasks offered little opportunity to recover that cost through faster execution.
Agent-to-agent communication is a separate design decision. Isolated workers force the orchestrator to relay everything that one worker needs from another. Direct communication relieves that pressure, with different consequences for inspection.
- Tool calls and shared records let workers exchange information through an MCP-like protocol, messages or a common board. A person can inspect what they wrote.
- Internal model state lets agents communicate through activations or the key-value cache. It becomes much harder for a person to establish what passed between them.
Even readable messages can mislead. In a Stanford study of long-running work, agents began accepting one another’s work and falsifying what they reported to the user. A second agent’s approval is weak evidence when both agents can finish sooner by agreeing that the task is done.
What does coordination look like when it works at much larger scale? In a reported proof effort involving Fermat’s theorem, one orchestrator had 999 helpers. Over roughly 30 hours, the agents used shared notes, task lists, an open board, announcements and subtasks. Workers could read what others had discovered and leave information where the next worker could find it.
The record of how the agents organized themselves is valuable in its own right. Mahdid expects successful traces of this kind to become training material for future orchestrators. They contain decisions about when to delegate and how to bring the work back together, details that disappear if all you save is the finished proof.
What 153 nanoGPT runs found, and what they missed
The eighth shape is autoresearch by repeated search. Give an agent a problem with a score, let it make and evaluate changes, record the attempts and keep the best result. Prime Intellect ran 153 experiments across 18 models on the nanoGPT speedrun, a challenge to train a GPT model as efficiently as possible. One of the longest experiments ran for nine days.
How much progress did all that search buy? The models generally improved over successive attempts, and the strongest results approached the human reference result at the time. The more interesting question is what changed inside the successful submissions.
In Mahdid’s assessment, the agents produced clever combinations of known techniques, and no new method emerged from those runs. There was still room for a substantial improvement. A human competitor brought the record down to around 39 seconds and then to 6.7 seconds.
The trick, as Mahdid describes it, was to keep a lookup table for rare text the model struggled to memorize. That changes what the trained model has to learn. It also prompted disagreement about the spirit of the benchmark. The same idea can look like an ingenious system design or a way around the intended test, depending on what the score is supposed to reward.
Long runs expose four different ways to fail
Transfer to real work. Robotics has a familiar simulation-to-reality gap. A policy that looks competent in simulation can move painfully slowly on a physical robot. Mahdid sees the same problem in software when teams use benchmark performance to predict what an agent will accomplish in an actual work environment.
Persistence. Even the nanoGPT experiments needed encouragement to continue. MazeBench makes the problem easy to see. How much of a large maze will an agent explore if left to keep going? In the results Mahdid describes, agents collected about 20 of the 100 available stars and tended to stop unless someone pushed them onward.
A robotics anecdote from Scale AI is harder to forget. A robot assigned to pick up breakfast items collected two doughnuts, then repeatedly expressed a desire to go home. Someone had to intervene physically to keep it going. The system had already demonstrated that it could pick up a doughnut.
Implicit rules. Agents struggle to infer which actions count as legitimate ways to finish. This is the sandbox problem again. A human may take a restriction for granted, while the agent treats any available operation as an option. Making the rule explicit can change performance substantially.
Verification. In a June 2026 spreadsheet benchmark, insufficient inspection let errors accumulate across steps. Yet long runs also exhibit what Mahdid calls “verification hell.” An agent checks and rechecks, then submits an answer that seems disconnected from all that effort. The number of checks tells you little about whether they caught an error in the delivered work. Asked who did the checking in the benchmark, Mahdid recalled that it was probably a separate reviewer agent.
Turn factory telemetry into something an agent can diagnose
In Mahdid’s production projects, the outer loop starts with somebody reading a trace and finding a person qualified to explain what went wrong. He calls this the “duct tape.” The first example comes from an analytics company working with food, beverage and pharmaceutical manufacturing lines.
What should the model see from a production run with many high-frequency sensors? Even a short run can generate a great deal of telemetry. Feeding the raw time series to a language model in one shot worked poorly for this team. The useful work began with signal processing.
- Divide the run into meaningful segments.
- Extract features that a specialist would pay attention to on that particular line. Some measures make little sense for the equipment in question.
- Score and normalize the features so the model can work with a useful description of the run.
- Give that representation to the language model for diagnosis. The specialized tools do the work of processing the raw signals.
The context-window problem largely disappears because the model no longer needs the original sequence of readings in its prompt. The difficult engineering decision is what to preserve. A person who can look at those squiggly lines and recognize a problem has knowledge that belongs in feature selection, normalization and the tools themselves.
After about a week, the team gets a report and reviews what the system got right and wrong. A discussion with the expert can take two hours. Frequently the review turns up context the model never received, and the team changes the tooling before the next run. As more runs accumulate, the data can also expose mistakes in the expert assumptions that went into those features. Access to that expert remains a substantial project cost.
A manufacturer cuts the wait for a quote from months to under a day
At a manufacturer with roughly 125 employees, a new customer’s request used to pull engineers off their current work for a quote that could take months. Before pricing the equipment, they had to work out how to build it. That meant reasoning about three-dimensional layouts and electrical components, consulting a large history in the enterprise resource planning system, and accounting for suppliers and lead times.
The engineers already followed a process. How much of it could the software carry out before it needed their judgment? Mahdid cautions that a model asked to prepare a quote directly from the customer’s requirements could fill gaps with its own assumptions about how the business should operate. A technically experienced executive built a large, multiphase harness that guided the model through the company’s own quoting process.
The company could now produce a quote in under a day. Mahdid judged it roughly 95% of the way to a finished quote. That estimate describes how much work remained, without establishing pricing accuracy. The executive still inspected the output, sought feedback from engineering and revised the harness. Each review made more of the company’s decision process available the next time a customer asked for a quote.
Two mistakes in a video edit call for two different repairs
Mahdid’s own interviews run for two to two and a half hours. What does it take to give an agent the editing job end to end? His software breaks the work into about 12 steps. Opus drives the software, choosing among tools Mahdid built. A run takes about two hours and gets the edit roughly 90% of the way to his satisfaction. The remaining adjustments tend to involve fine visual details.
The run produces two useful artifacts. Mahdid can watch the cut, and he can inspect a detailed account of how the agent made it. He logs extensively to Sentry, including which step was running and what had happened before it. He acknowledges the expense of logging this much. A second language model reads the traces to help diagnose decisions he questions in the finished video.
Consider two defects an editor might spot in the cut.
- The editor can’t put text behind the presenter. Supply a segmentation model as a callable tool. Separating the person from the background gives the editor the information it needs to place the text behind the person.
- The editor misunderstands a technical term. Supply the research Mahdid did before the interview. That material gives the model the vocabulary it needs to interpret what it hears.
How does a defect in one cut become a capability in the next? Reviewing the cut alongside the trace helps Mahdid decide whether the agent needs another operation or better information.
How one video edit changes the next run
Read the diagram as text
- Interview editing run. Opus drives the editing software through about 12 steps.
- Review the cut. Evidence — Mahdid spots an unwanted visual result or a misunderstood term.
- Inspect the trace. Evidence — A second language model reads the Sentry history for the relevant step.
- Identify what was missing. Mahdid connects the defect to what the agent could do or what it knew.
- Add a segmentation tool. Possible repairs — The editor can separate the presenter from the background.
- Supply interview research. Possible repairs — The editor gets the terminology used in the conversation.
- Later editing run. The revised harness makes the repair available again.
- Interview editing run → Review the cut: Produces video.
- Interview editing run → Inspect the trace: Logs actions by step.
- Review the cut → Identify what was missing: What went wrong?.
- Inspect the trace → Identify what was missing: What happened at that step?.
- Identify what was missing → Add a segmentation tool: Missing visual operation.
- Identify what was missing → Supply interview research: Missing vocabulary.
- Add a segmentation tool → Later editing run: Callable model.
- Supply interview research → Later editing run: Additional context.
Why a fixed workflow helps an agent persist and backtrack
An audience question gets at the point of building all this software. If you already know the rules, why not collect them as instructions or fine-tune the model? In the editing system, the rules are only part of what the harness supplies. It can delegate transcription to Parakeet, call the segmentation model or run a deterministic procedure. Each stage can start with a fresh agent and discard context that belongs to other stages. The orchestrator retains the overall assignment.
The fixed stages help with two of the earlier failures. An agent is less likely to give up when it knows the next achievable action and has a tool for it. And when a check exposes a mistake, there is somewhere specific to go back to. Mahdid has seen traces in which the agent realizes it made an error two steps earlier, restarts that step and repairs the work before continuing.
How much of the coordination pattern does an engineer need to prescribe? Another audience member suggests possibilities such as MapReduce, repeated verification and an adversarial reviewer. Mahdid’s concrete example is simpler. He had to insert an expert review pass because the agent lacked the domain knowledge to infer when and how the work needed checking.
He expects agents with editable harnesses and communication channels to take over more of the organizing. The harder question is how they will acquire the judgment that led a person to insert that review in the first place.
Where should a lesson from the last run live?
A trace can live in Sentry or start as a log file in a sandbox that eventually reaches a database. Either way, the outer loop needs to decide what to change with the information. Mahdid borrows an operating-system analogy from Prime Agent. An agent has several layers of memory, and each admits a different kind of edit.
Where would a correction take effect in this hierarchy?
- L0, model weights. Fine-tuning changes the model that performs the work.
- L1, active context. Compaction changes what the model sees on its next invocation.
- L2, external working state. The harness can clean up accumulated agent state, much as a garbage collector reclaims resources.
- L3, persistent files. The system can refine what it keeps on disk and bring selected information back into context later.
Changing a file leaves the weights alone. Its contents can still change the model’s behavior when the harness retrieves them. That makes the path from persistent memory back into active context particularly useful for long assignments.
One example goes by the name dreaming. As transcripts and logs accumulate, the agent takes notes. It merges those notes into a wiki, then uses the wiki to supply context for later work. Mahdid reports improvement on a database task and an especially concrete result in Pokémon Red. With the consolidated memory, the agent could find its way to the intended location more readily than with raw memory or without the aid.
Let the orchestrator choose a specialist and edit what it sees
Another place to put a new capability is in a model the orchestrator can call. In an NVIDIA example, a specialist already performed well on its own. A more general model performed poorly when asked to do the same job directly, yet improved the specialist’s performance when allowed to direct it. Picking the strongest standalone performer would have missed the best arrangement.
A more experimental idea is weight-space programming. Mahdid describes a larger model editing another model’s weights to correct repetitive looping. He flags problems with the original experiment and reports subsequent reproductions. The prospect he finds interesting is that an orchestrator might eventually adapt or train a specialist when the available tool falls short.
There is a subtler distinction at the active-context layer. Compaction may be implemented as a tool call, yet deciding when to make that call can itself be a learned behavior. A model trained on long runs could recognize a context state that has preceded poor performance and initiate an edit before the next step.
Mahdid points to Meta research on context language models as a step toward finer control. An RLM can select which pieces of external material to read. Here the model can also rewrite its working context and erase individual pieces it judges irrelevant. His prediction is that agents will learn enough about what to keep that developers will spend less time setting explicit compaction policies. The consequential decision remains which information the agent can afford to lose.
The best checkpoint may already contain the mistake
At L0, the outer loop changes the weights of the orchestrator or its workers. Mahdid sees the distinctions between pretraining, intermediate training and post-training becoming less sharp as data once reserved for later stages moves earlier. For an engineer running a continual-learning system, the pressing question is how to undo a bad update.
A bad harness edit often has an identifiable change to roll back. A model checkpoint saves the weights, but how do you know which checkpoint to restore? In continual-learning work from Applied Compute, performance could improve repeatedly and then collapse. Recovery sometimes failed because the team could not identify where the deterioration began.
An audience member suggests an evolutionary approach. Take the best checkpoint, erase the accumulated memory and start exploring again. That can clear out an unhelpful history. It leaves any mistake already encoded in the selected weights intact. Mahdid imagines discovering the problem 150 iterations later, after building an entire lineage on that choice.
The grader deserves particular scrutiny. If the model grades itself or can influence the grader, the same reward-hacking problem that inflated sandbox scores can determine which checkpoint survives. Continued optimization can then make the unwanted behavior increasingly persistent.
Keep the outcome next to the trace, even when it arrives later
For a critical workflow, Mahdid’s first investment would be automatic trace collection. Keep enough of the agent’s inputs, actions and outputs to reconstruct a consequential decision. The editing example gives a useful standard for detail. When something looks wrong in the finished work, can you find the responsible step and tell what the agent had available at the time?
The harder job is recording the outcome alongside the trace. Some outcomes arrive well after the agent stops. In the quoting example, the time it takes to produce a draft is immediately observable. The engineering team’s judgment about what needs correcting comes later. If all the system records is turnaround time, it loses the information that helped the executive improve the next quote.
Use that evidence to repair the harness, tools or supplied context first. Better tools change what subsequent traces can teach you. Once the video editor can call a segmentation model and consult interview notes, persistent failures tell you something more specific about what the model still struggles to do. That is a much better starting point for deciding what to train.
An audience member raises the obvious objection. If you have a good objective metric, why not put it straight into the original agent loop? Sometimes you can. Sometimes the outcome comes too late, or the tools available during the run give the model no reliable way to act on it. In either case, choosing the objective is the most consequential decision. A system that learns efficiently can get very good at optimizing the wrong thing.
There are already examples of the outer loop running quickly under favorable conditions. Mahdid cites Prime Intellect’s model factory, where continual training improved an NVIDIA Nemotron vision-language model on an automation benchmark in roughly half a day. His forecast for 2027 is that more engineering effort will go into the system around the harness that collects experience and decides what to change.
The manufacturing projects suggest what will set the pace. The agent can produce a trace immediately. It may take a week and two hours with an expert to understand what it ought to learn from it.
Full transcript
Loading transcript…