Agente locale

Visão geral

Quale api.agents.create({ runtime: "local" }) restitue: il loop agente come un oggetto che sostende, run, stop, inspection e rebobina.

8 methodsthe loop is hereread its state as it works
Using Python?

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

MétodoFunção
run(options)Un intercambio: il tuo messaggio dentro, la risposta.
stop()Fine la runtura corrente.
setMode(mode)Cambia il modo, medio-run, subagentes inclusa.
compact()Resumis la conversazione ora.
getHistory()La conversa, in forma di display.
Punti di controllo()A qua pots retornar.
rewind(n)Retorna a un messaggio.
destroy()Rimueve la sessione.
const agent = api.agents.create({ runtime: "local", machine: pc, model, memory: true });

const result = await agent.run({
  message: "Read the notes and list what is unfinished.",
  onEvent: (e) => { if (e.type === "text_delta") process.stdout.write(e.delta); },
});

console.log(agent.usage, agent.context.tokens, result.stopReason);
agent = api.agents.create(runtime="local", machine=pc, model=model, memory=True)

result = agent.run(
    message="Read the notes and list what is unfinished.",
    on_event=lambda e: print(e["text"]) if e["type"] == "text" else None,
)

print(agent.usage, agent.context["tokens"], result["stopReason"])

run() è un intercambio, non un task

Prende il vostro messaggio, loops fino che il modello cessa de chiedere utensili, e retorna. Calling-lo continua di nuovo la stessa conversa — l'oggetto detiene la historis.

L'obiet è reutilizable, e non consistit

Un run per volta

Una seconda run() mentre uno è in volo condivide la stessa lista de messaggi e i medesime contadores d'uso. Aspetta il primo, o construir un second agente.

Può lere il suo stato mentre funciona

usage, context, todos, mode e messages sono live. Una interface pode sondar-les, ou escuchar events, o que é mais barato e preciso.