Skip to content

createAgent

Provision a smart account, issue an ENS subname, and grant onchain policies in one call.

Signature

import type { CreateAgentParams, Agent } from "@agensai/sdk";
 
declare function createAgent(params: CreateAgentParams): Promise<Agent>;

Example

import { createAgent } from "@agensai/sdk";
 
const agent = await createAgent({
  name: "my-agent",
  chainId: 8453,
  apiKey: process.env.AGENSAI_API_KEY!,
  ownerPrivateKey: process.env.AGENSAI_OWNER_PRIVATE_KEY! as `0x${string}`,
  policies: [
    { type: "spend", token: "USDC", amount: 50, period: "weekly" },
    { type: "contract", whitelist: ["uniswap.eth"] },
    { type: "expires", at: "2026-08-01" },
  ],
});

Parameters

FieldTypeRequiredDescription
namestringyesAgent label. Becomes <name>.agensai.eth. Must be unique within your namespace.
chainIdnumberyesInitial chain. Base (8453), Ethereum (1), or Optimism (10).
apiKeystringyesYour AGENSAI API key.
ownerPrivateKey`0x${string}`yesServer-side owner key that grants the policies.
policiesPolicy[]yesInitial policy bundle. See Policies.
namespacestringnoPro-tier custom namespace (default agensai.eth).

Returns

An Agent instance, fully provisioned and ready to act.

What happens onchain

  1. A counterfactual smart account is computed from the owner and the agent name.
  2. The ENS subname is issued (gasless) under the configured namespace.
  3. Owner signs the ERC-7715 grant for each policy.
  4. The grants are submitted onchain.

The agent is operational the moment this call resolves.