Ce succede in un pas
- Se si chiamava
stop(), se si raggiungeva il limite d'escalade, o se si spargeva il budget. - Construi il prompt del sistema — spazio de lavoro, modo, utensili, storages, memoria.
- Clear old tool results se il contesto è pesante, então compact se non era suficiente.
- Pedir un virat di modello, con le declarazion di utensili. Emit
turn. - Se il model scrise text, emit
text. - Se non si chiesse un utensilio, il loop termina.
- Sen dane ergue le chiamali — in paralel o uno a la volta — e anexi ogni risultato come un messaggio
tool.
Nulla di più decide quando stop: il proprio silenzio del modele è il final normal.
I 4 finals
| Reson | Significado |
|---|---|
end_turn | Il modele rispondit senza chiamare un utensilio. |
stopped | stop() fu chiamato. L'outil actual termina, niente di nuovo inizia. |
max_steps | Il tectus di step è alcantat — maxSteps, 100 per omissió. |
budget | I crediti scaduts rèallès budget. |
const result = await agent.run({ inputs: "…" });
switch (result.stopReason) {
case "end_turn": break; // it answered
case "max_steps": console.warn("ceiling reached — the work is unfinished"); break;
case "budget": console.warn("budget spent — ", result.usage.credits); break;
case "stopped": break; // you asked it to stop
}result = agent.run(inputs="…")
reason = result["stopReason"]
if reason == "max_steps":
print("ceiling reached — the work is unfinished")
elif reason == "budget":
print("budget spent — ", result["usage"]["credits"])
# "end_turn": it answered · "stopped": you asked it to stopLa run termina con quels texts il modele prodotto da ultimo, che può essere un pensòn semi-finit. Tratte ognuna ragion come «inacabat» e non come una risposta, e o elevare il tetto o restrinse la task.
Qua run() restitue
{
text: "I read the four notes. Two are unfinished: …",
todos: [{ content: "Check the figures", status: "completed" }],
usage: { credits: 31, turns: 6, toolCalls: 9 },
stopReason: "end_turn",
model: "gemini-3.5-flash"
}{
"text": "I read the four notes. Two are unfinished: …",
"todos": [{"content": "Check the figures", "status": "completed"}],
"usage": {"credits": 31, "turns": 6, "toolCalls": 9},
"stopReason": "end_turn",
"model": "gemini-3.5-flash",
}text è l'ultima cosa che il model scrise, che non è sempre l'ultimo passo: una run che termina a max_steps restituisce il testo più recente, anche se un utensilu lo seguisse.
Il tecturat de step
maxSteps predefinitos a 100, che è alto a propósito — é un guarda fuga, non un budget. La cosa que normalmente deve parare una run é budget, porque é denominata in quello de cui realmente te importa.
Un subagente è plafonat a 40passs quel che il plafond del padre, dal momento che è dato un lavoro autonomo.
Abortare un run
const running = agent.run({ inputs: "…" });
setTimeout(() => agent.stop(), 30_000);
const result = await running; // stopReason: "stopped"import threading
threading.Timer(30, agent.stop).start()
result = agent.run(inputs="…") # stopReason: "stopped"stop() aborta la richiesta del modelo in volo e imposta la bandera che il buco lee in cima di ogni passo. Le chiamate di ferramentas già in fila in fila nella stessa volta risposta « Interrompeu dal utente. » in lugar de rulare. I bambini sono interrompeti troppo.
Un errore termina la run
Qualsiase cosa un utrel è presa e restituit al modele come un resultado utrel failed — il model adapts. What is no capturat è un fallo del turn stesso dopo tentas e replies: un error evento è emit e run() rejets.