Skip to content

Effective Structures for Long-Running AI Agents

In brief: The Claude Agent SDK requires an intelligent two-part structure for long-term projects: an initializer agent sets up the environment, while specialized coding agents make incremental progress in each run and leave production-ready artifacts behind – without unnecessary redundancy or unfinished features.

As AI agents become increasingly capable, developers face the challenge of deploying them for complex tasks that span hours or even days. The core problem: agents must work in separate sessions, with each new session beginning without memory of the previous one. An intelligent two-part solution enables the Claude Agent SDK to function effectively across many context windows.

When developing powerful AI agents, a fundamental problem emerges: although the Claude Agent SDK has context management functions like compression, even cutting-edge language models such as Claude Opus 4.5 cannot work optimally across multiple context windows when given only an abstract instruction.

In practice, two key errors manifested themselves: first, the agent frequently tried to accomplish too much at once – essentially building the entire application in a single session. This caused the agent to exhaust the context window mid-implementation, while the next session would start with half-finished, undocumented features. The agent then had to guess what had happened and spent considerable time restoring basic functionality.

The second error scenario occurred later in the project: after creating some features, a later agent instance declared the task complete even though it was incomplete.

The solution is to break the problem into two parts. First, an initialized environment must be created that supports all features demanded by the prompt and prepares the agent for stepwise, feature-by-feature work. Second, each agent instance should make incremental progress and leave the environment in clean order at the end of a session – with code quality ready for the main repository: no major bugs, neat and well-documented code that any developer can easily pick up for new features.

To solve these problems, a two-part approach was developed internally: an initializer agent conducts the first agent session and prepares the basic infrastructure. A coding agent then works in each subsequent session to make stepwise progress while leaving clear artifacts for the next session.


Source: www.anthropic.com

Share on: