LocalAgent

Properties

What the object carries, and which of it is live during a run.

live while runningid before the first runtoolNames is what was selected
Using Python?

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

idstring|null

The session identifier, set at creation when memory is on. null otherwise.

modelstring

The agent's model. For which model served a turn, read the turn events.

modestring

The mode in force. Changed with setMode().

titlestring

Taken from the first message of a session.

usageobject

{ credits, turns, toolCalls } — reset at the start of each run, subagents included.

contextobject

{ tokens, limit, window, cachedTokens, cleared, parts }.

todosarray

The current plan.

toolNamesstring[]

The tools this agent was given, custom ones included.

libraryobject

{ skills, subagents } — what the last run loaded.

libraryStatusobject

Why a library is empty, when it is.

mcpServersarray

The connected servers this run may use.

machine · files · shellobject

What it was given.

What changes during a run

const running = agent.run({ message: "…" });

const timer = setInterval(() => {
  console.log(agent.usage.credits, "credits ·", agent.context.tokens, "tokens");
}, 1000);

await running;
clearInterval(timer);
import threading

done = threading.Event()

def watch():
    while not done.wait(1):
        print(agent.usage["credits"], "credits ·", agent.context["tokens"], "tokens")

threading.Thread(target=watch, daemon=True).start()
agent.run(message="…")
done.set()

usage, context, todos and library are all updated as the loop goes. Events are the better channel — they carry the same numbers at the moment they change — but polling works.

usage is per run

It is reset at the start of every run

It is not a running total for the agent object. Keep your own sum across runs if you need the conversation's whole cost.

context, field by field

FieldIs
tokensThe last turn's size, as the provider measured it
limitThe limit in force
windowThe model's own window, or null if the catalogue could not be read
cachedTokensWhat the provider served from cache
clearedHow many tool results have been emptied
parts{ system, tools, memory, messages }

toolNames is what was selected, not what is declared

A tool that cannot run on this machine — bash with no shell on a phone — is already out of it. skill and task appear only once a library has something in it, so they are not in this list before the first run.