api.agents

create()

api.agents.create(options) → LocalAgent | Agent

Builds an agent from its options. Everything is validated here, nothing is sent — the object is ready and the account knows nothing about it yet.

no requeststrict validationreturns an object
Using Python?

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

A local agent

const agent = api.agents.create({
  runtime: "local",
  machine: pc,                      // required
  model: "gemini-3.5-flash",        // required
  mode: "ask",
  tools: ["read", "list", "glob", "grep", "write", "edit", "bash"],
  budget: 200,
  memory: true,
  onPermission: async ({ tool, category, args }) => "once",
  onQuestion: async ({ question }) => answer(question),
});
agent = api.agents.create(
    runtime="local",
    machine=pc,                       # required
    model="gemini-3.5-flash",         # required
    mode="ask",
    tools=["read", "list", "glob", "grep", "write", "edit", "bash"],
    budget=200,
    memory=True,
    on_permission=lambda request: "once",
    on_question=lambda request: answer(request["question"]),
)

What is required

runtimestring

"local" for the engine in your process. Absent builds the server-side agent.

machineConnectedStoragerequired

A computer, a phone, or a cloud workspace. See machine.

modelstringrequired

Unless you pass id, in which case it comes from the session.

Every option

OptionDefaultPage
machine · workspace—machine
model · fallbackModels · thinking · maxOutputTokens— · [] · null · 16 000model and thinking
tools · skills · subagents · mcp · agentall · all · all · all · nulltools and library
mode · onPermission · onQuestion · system"ask" · — · — · ""mode and permissions
budget · maxSteps · contextTokensnull · 100 · 200 000budget and context
media{}media
memory · id · memories · checkpointsfalse · — · true · truememory and sessions
files · shell · terminals · customTools—bridges

What is refused, and when

CodeWhen
machine_requiredNo machine, or one that is not a computer, a phone or a cloud workspace.
files_requiredA phone or a cloud workspace without the six file operations. The message names the missing ones.
model_requiredNo model and no id.
invalid_modeA mode outside the four.
unknown_toolA tool name the engine does not know. The message lists the ones it does.
invalid_contextcontextTokens that is not a whole number of at least 10 000.
invalid_shellA shell without a run function.
invalid_custom_toolA custom tool with no description, no run, a reserved name, or a category outside the four.
invalid_mediaA media key that is not image, video, voice or music.
invalid_agentAn agent name that is not a library name.
invalid_session_idAn id that is not a session identifier.
workspace_not_allowedA workspace other than the SDK's own folder.
All of them throw at creation, not at run time

That is deliberate: a misconfigured agent should fail on the line that configures it. The one exception is contextTokens being larger than the model's window, which needs the catalogue and therefore surfaces on the first run.