← All IntelClip / OtherAnti-Pattern: Not Checking Stop Reason in Agent Loops
From Anthropic's CCA Exam as a Field-Guide for Agentic Engineering — Frank Coyle, UC Berkeley · ≈7:51
“It is just a probabilistic next word predictor.”
“So it's important to understand that the LLM is not executing these tools.”
What’s in it
- Explains the agent loop pattern using LLM stop reasons
- Shows why LLMs can't execute tools, only request them
- Walks through code for a tool-use loop step by step
Clip transcript
Okay. I'm start with uh with scenario one, customer support resolution. So here we have a loop operating and the I'm going to jump to the anti-pattern. What you don't want is just to let the agent go and do something and get the response back and use it, okay? What you want to do is you want to loop with something called the stop reason. So I'm going to show you a little code here. So here we have while loop. It's a while true, it's a loop. We're looping right here, okay? So the first little block is where we call uh we call the model, okay? And we pass it the messages. The messages are essentially the sequence of prompts that exist in the context window, okay? And we are asking the and we have a we have a prompt and we have we have the context and we have a tool. And we're asking the LLM to do something with this tool and help us out. The problem is the LLM can't do anything. It is just a probabilistic next word predictor. It can't execute tools. So what it does though is it can figure out if you point it to a tool, it can figure out how to set things up so that you or your code can execute it. So it's important to understand that the LLM is not executing these tools. It can't do anything except talk back to you, very intelligently sometimes, but all it can do is talk back to you. So when it finishes this task and has a result which is basically here is I've I know what you want. I know what the tool can do. Here's how I It sets up the parameters that can then be or that then used to actually execute the tool. So, the second block you see why did the LLM come back to us? That's our stop reason. Tool use. Oh, okay. We've stopped because the LLM it wants to use the tool. So, let's just run the tool. So, that's what the second block is. Run tool, the response is what the LLM said, and it's basically the parameters that it has extracted from the data that you provided it. Okay? Then it executes that. Then it goes back. That then it continues. Continues means the LLM sees it and says, "Oh, successful run. So, okay." Come back down. We're not running a tool anymore. We're end the end of our loop. Bingo.
Comments
Sign in to comment.
Loading comments…