Our DeepSearch agent is becoming increasingly capable, but relying on a single, monolithic system prompt for every action from searching and scraping to answering has its limits. It makes the system brittle, sensitive to prompt changes, and restricts our ability to optimize individual tasks (like using different models or temperatures for different steps).
Day 6 is about a fundamental architectural shift: decomposing our agent's operations into distinct, manageable tasks. We'll move from letting the AI SDK manage the tool-calling loop to building our own custom loop, giving us granular control and unlocking a new level of sophistication in our app.
To do this there will be a few major steps you will take.
First you'll create a SystemContext
class in typescript that will act as our container for building out our loop. You'll create a 'Next Action Picker' that will have smart agent decide what step to take next then build the loop.
By the end of Day 6, you will have fundamentally re-architected your DeepSearch agent. You'll have a powerful, custom loop that gives you precise control over each step of its operation, paving the way for more advanced features, better per-task optimization, and a more robust, maintainable system.