Agente locale

run()

agent.run({ message | inputs, history?, onEvent?, edit? }) → Promise<Result>

Un intercambio. Il loops fino a che il modele para de pedir utensili, streaming di tutto onEvent, e restitue con quello con cui terminò.

the looponEvent cannot break itone at a time
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

messagestring

Il testo. La forma corta di inputs.

inputsarray

[{ type: "text", content }, { type: "image", content: base64, mime }].

historyarray

[{ role, content }] — una conversazione precedente, per un agente senza sessione.

onEventfunction

Receve ogni event. Mai atteso; tutto ciò che lancia è inghiottito.

editinteger

Torna a quel messaggio prima, poi corre con il nuovo text.

Uno di message e inputs né necessari — né, e lança inputs_required.

Enviando una imagem

await agent.run({
  inputs: [
    { type: "text", content: "What is wrong with this layout?" },
    { type: "image", content: base64, mime: "image/png" },
  ],
});
agent.run(inputs=[
    {"type": "text", "content": "What is wrong with this layout?"},
    {"type": "image", "content": base64_png, "mime": "image/png"},
])

Retorno

{
  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",      // "stopped" | "max_steps" | "budget"
  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",      # "stopped" | "max_steps" | "budget"
    "model": "gemini-3.5-flash",
    "context": {},                 # the context meter, as in agent.context
}
Ler stopReason prima di usar text

Solo end_turn significa il modello che ha finit di dire quello che ha a dir. In max_steps o budget, il testo è quello che ha scritto ultimamente — possibly mid-plan.

historis, per un agente senza sessione

Con memory: true la propria storia della sessione vince, e questo è ignorat — che è la forma giusta quando la conversazione appartiene a sua base di dati e non a la nostra.

edit: cambiando un messaggio anterior

await agent.run({
  edit: 2,
  message: "Actually, rename them to kebab-case.",
});
agent.run(
    edit=2,
    message="Actually, rename them to kebab-case.",
)

Rembobina a poco prima del messaggio 2 — files inclusi — emite rewound, poi run con il nuovo testo. Necessita una sessione e checkpoints, e lança prima di iniziare se uno dei due è mancant.

Ce lo fa respingere

Un virat che non ha scaduto su ogni modela dopo ogni tentazione, un contexto che non vat, una sessione non autorizzata, o un renego de credit.Tudo il resto — un utrel che lança, un utrel che è stato rifiutat — è maneggiat dentro del loop e mai supere qui.

import { NotEnoughCredits, IaGenifyError } from "iagenify";

try {
  await agent.run({ message });
} catch (err) {
  if (err instanceof NotEnoughCredits) { /* never retried, on any model */ }
  else if (err instanceof IaGenifyError && err.code === "context_too_large") await agent.compact();
  else throw err;
}
from iagenify import IaGenifyError, NotEnoughCredits

try:
    agent.run(message=message)
except NotEnoughCredits:
    pass  # never retried, on any model
except IaGenifyError as error:
    if error.code != "context_too_large":
        raise
    agent.compact()