LocalAgent

run()

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

One exchange. It loops until the model stops asking for tools, streaming everything through onEvent, and returns what it ended with.

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

The text. The short form of inputs.

inputsarray

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

historyarray

[{ role, content }] — a previous conversation, for an agent without a session.

onEventfunction

Receives every event. Never awaited; anything it throws is swallowed.

editinteger

Go back to that message first, then run with the new text.

One of message and inputs is required — neither, and it throws inputs_required.

Sending an image

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"},
])

Returns

{
  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
}
Read stopReason before using text

Only end_turn means the model finished saying what it had to say. On max_steps or budget, text is whatever it last wrote — possibly mid-plan.

history, for an agent without a session

It seeds the conversation when the agent holds none. With memory: true the session's own history wins, and this is ignored — which is the right shape when the conversation belongs to your database rather than to ours.

edit: changing an earlier message

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

It rewinds to just before message 2 — files included — emits rewound, then runs with the new text. It needs a session and checkpoints, and it throws before starting if either is missing.

What makes it reject

A turn that failed on every model after every retry, a context that will not fit, an unauthorised session, or a credit refusal. Everything else — a tool that threw, a tool that was refused — is handled inside the loop and never surfaces here.

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()