← All labs
D1·Fix the code
Breaking out of a Managed Agents session
A Managed Agents client returns as soon as the session reports idle. It works for simple prompts, but any run involving a confirmation-gated tool ends early with the task half-finished.
for await (const event of stream) {
handle(event);
if (event.type === "session.status_idle") break;
if (event.type === "session.status_terminated") break;
}1.Why does the loop exit while work remains?
2.Which stop_reason means the agent is waiting on the client?