Okay, now we've got our loop set up, it's time to reveal my trump card. The whole point of having agentic behavior is to hand control of the control flow to the LLM. Our current setup is too deterministic.
Our current flow always goes through the loop. We're going to give the LLM the ability to break out of the loop early. Here's the current loop:
while (step < 2) {// Write Slack messageconst writeSlackResult = streamText({model: google('gemini-2.0-flash-001'),system: WRITE_SLACK_MESSAGE_FIRST_DRAFT_SYSTEM,prompt: `/* prompt content */`,});
Whatever happens, we're always going to go back to the top of the loop. There's no way to break out of it here. We're going to force the LLM to essentially choose whether it should break out or not.
In other words, it doesn't just need to return the reasoning and the feedback, it also needs to return an "is this good enough" Boolean. We're not going to be able to scrape that out of a lowly streamText call:
Instead we should use streamObject. streamObject is going to give us the best of both worlds:
We need to:
streamText call with a streamObject callstreamObject call says we should break out of the loop, we should do soGood luck, and I'll see you in the solution.