Custom AI Agents Need Better Runtime Controls
If I’m choosing an architecture for custom AI agents, I’m not asking which model has the biggest context window anymore. I’m asking which runtime controls keep the agent on task after 50 tool calls, a few large file reads, and one bad summary. That is the actual decision behind the recent wave of long-horizon agent docs from AWS, Anthropic, LangChain, OpenAI, and Manus.
The useful shift is simple: reliability is moving out of the model layer and into AI integration architecture. According to the MarkTechPost summary of current agent guidance, teams are converging on four controls: context budgeting, compaction, todo-state, and memory.
Comparison table: which control fixes which failure?
| Runtime control | Best at fixing | Cost trade-off | When I would use it | Main risk |
|---|---|---|---|---|
| Context budgeting and offloading | Context overflow | Extra file I/O, retrieval logic | Any agent expected to read long tool outputs or documents | Pointer strategy gets messy if retrieval is weak |
| Compaction | Window resets on long sessions | Summary quality work, eval overhead | Multi-step tasks that will definitely cross a threshold | Goal loss if the summary drops a constraint |
| Todo-state and recitation | Goal drift between compactions | Small token tax every turn | Long tasks with many branches or handoffs | Extra chatter can raise cost without improving reward |
| Persistent memory | Cross-session continuity | Standing attention tax, stale memory cleanup | Repeated workflows in AI workflow automation | Reloading too much context every run |
In practice, these are not substitutes. They stack. But the order matters. I start with budgeting because every token I keep out of the prompt is one I do not need to summarize later.
Why custom AI agents fail on long-horizon tasks
In one client build for internal support workflows, the first failure was never model intelligence. It was accumulation. The agent kept appending tool output until the original instruction slid into the middle of the prompt, and then the plan started to wobble. That pattern lines up with the AWS framing cited by MarkTechPost: shallow agents hit context overflow, lose the goal, and fail to maintain state.
The bigger-window argument sounds appealing, but the evidence is weaker than most teams expect. Chroma’s Context Rot report found reliability degrades as input length grows, even on retrieval tasks. Anthropic’s prompt engineering guidance explains why runtime scaffolding matters as context windows stretch: Anthropic explicitly recommends telling the model when context will be compacted and using memory before a refresh. Manus adds the operator view: a typical task may need around 50 tool calls with an input-to-output ratio near 100:1, which means prompt bloat becomes a runtime problem fast.
From the Encorp playbook: I treat long-running agents like distributed systems, not fancy prompts. Put hard limits on what enters context, decide what survives a reset, and test compaction on purpose before the workflow ever reaches production. For teams building AI Automation Implementation, the runtime policy matters as much as model choice.
Mechanism 1: Budget context before it enters the window
This is the cleanest trade-off of the four. If a tool response is too large to be useful in-context, do not keep it there. LangChain’s context engineering docs for Deep Agents uses hard thresholds that are worth copying as a starting point: tool responses over 20,000 tokens get offloaded to disk, and when session context crosses 85% of the window, older edits can be replaced with pointers. That is good AI agent development because it avoids wasting compaction passes on garbage you never needed in the first place.
Claude’s prompt engineering guidance shows a similar pattern by recommending that developers tell the model when context will be automatically compacted and instruct it to save state to memory before refresh. The same principle appears in Amazon Bedrock AgentCore memory documentation, where short-term and long-term memory are separated and extracted insights can persist beyond a single session. I like that design because it changes the unit of context from raw trace to decision-ready summary.
The trade-off is implementation complexity. Once you offload aggressively, retrieval quality matters. If file pointers are inconsistent or your read-back step is slow, the agent starts thrashing. In enterprise AI integrations, I would rather accept a little extra storage logic than pay for bloated prompts on every turn.
Mechanism 2: Compaction must preserve the goal
Compaction is the control I reach for when long tasks are unavoidable, but it is also the one I distrust most until I see evals. A bad summary does not fail loudly. It quietly deletes the one business rule, path constraint, or unresolved bug that the next 30 minutes depended on.
That is why implementation details matter. LangChain’s Deep Agents context engineering docs says in-context summaries preserve session intent, artifacts created, and next steps. OpenAI’s Responses API guide pushes the same general idea into the API layer by making it easier to build multi-turn, tool-using agents with stored state and tracing. Deep Agents reportedly improved performance by structuring summaries around session intent, artifacts created, and next steps.
The trade-off here is engineering discipline. Summary prompts are not setup fluff; they are production artifacts. In AI implementation services, I test them the same way I test retry logic. Force compaction at 10% to 25% of the window during evals, then look for the failures LangChain calls out: the agent asks for clarification after a summary or declares victory early.
Mechanism 3: Recite the plan with todo-state
Todo-state looks primitive, which is why teams dismiss it too early. I would not. A short task file rewritten every few turns keeps the objective near the recent end of context, where the model is more likely to attend to it. Manus describes this directly with todo.md, and Anthropic’s prompt engineering guidance points to multiwindow workflows that iterate on a todo list after the first context window.
The trade-off is measurable token cost. LangChain Deep Agents customization docs confirms todo tracking is middleware rather than a universal requirement, which fits the broader lesson that planning scaffolds help some categories more than others. That matches what I have seen: for short support automations, todo recitation is usually noise; for branched AI business automation with retries and approvals, it often pays for itself.
My rule is simple. If the workflow has more than one branch, any human approval step, or a likely runtime above 10 minutes, I keep a durable task file. If not, I skip it until the traces prove I need it.
Mechanism 4: Add memory that survives the session
Persistent memory is the most tempting and the easiest to overdo. Yes, cross-session continuity helps. Amazon Bedrock AgentCore Memory and Anthropic’s file-based memory patterns both support recall on later runs. For repeated support, analytics, or software delivery tasks, that can cut redundant research.
But memory is not free context. The ETH Zurich study on repository context files found cost increases from always-on context files without consistent success gains, including inference cost increases of over 20% on the evaluated tasks. Anthropic’s Claude Code memory guidance also recommends keeping memory specific, organized, and regularly reviewed. Claude’s own guidance to keep project memory concise is the right instinct.
The trade-off is long-term prompt tax versus recall. In AI workflow automation, I persist stable rules, IDs, and environment facts. I do not persist every observation. If you reload everything every session, you are just moving overflow from today’s run into tomorrow’s startup prompt.
The trade-offs by criterion
Overflow protection
Budgeting wins this one. Offloading and subagent summaries stop token growth before the window gets polluted. Compaction only helps after the problem already exists.
Goal preservation
Todo-state is the most direct defense between compactions, while structured compaction is the defense during resets. If I had to choose one for long coding or ops agents, I would combine both and keep the goal in a file, not only in chat history.
Cross-session continuity
Memory wins, but only when the workflow repeats. For one-off jobs, persistent memory is just extra baggage. For recurring AI automation agents working across support queues, cloud tasks, or analytics pipelines, it becomes worthwhile.
Engineering effort
Budgeting is usually the fastest high-value addition. Compaction takes more evaluation work. Memory takes the most operational discipline because stale facts linger unless someone owns cleanup.
What teams should implement first
If I were building custom AI agents for production this quarter, I would do the runtime controls in this order:
- Budget context first with hard thresholds for large tool outputs and file reads.
- Add compaction second with a structured summary that explicitly preserves intent, constraints, artifacts, and next steps.
- Turn on todo-state third for workflows that branch, wait, or run long enough to drift.
- Add persistent memory last only for workflows that repeat across sessions.
The non-obvious part is testing. Do not wait for real overflow. Trigger compaction early in staging, summarize away one recoverable fact on purpose, and verify the agent can fetch it back from storage. If it cannot, the system is not production-ready regardless of the model.
Verdict
Pick context budgeting if your main problem is prompt bloat from tools and documents. Pick compaction if the task will certainly outgrow the window and you can invest in evals. Pick todo-state if the agent loses the thread between steps. Pick memory if the same workflow comes back tomorrow and repeated discovery is the real waste.
For most teams, the right answer is not one mechanism. It is budgeting first, compaction second, and then selective recitation or memory where the traces justify the extra cost.
Martin Kuvandzhiev
CEO and Founder of Encorp.io with expertise in AI and business transformation