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
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes | Agent label. Becomes <name>.agensai.eth. Must be unique within your namespace. |
chainId | number | yes | Initial chain. Base (8453), Ethereum (1), or Optimism (10). |
apiKey | string | yes | Your AGENSAI API key. |
ownerPrivateKey | `0x${string}` | yes | Server-side owner key that grants the policies. |
policies | Policy[] | yes | Initial policy bundle. See Policies. |
namespace | string | no | Pro-tier custom namespace (default agensai.eth). |
Returns
An Agent instance, fully provisioned and ready to act.
What happens onchain
- A counterfactual smart account is computed from the owner and the agent name.
- The ENS subname is issued (gasless) under the configured namespace.
- Owner signs the ERC-7715 grant for each policy.
- The grants are submitted onchain.
The agent is operational the moment this call resolves.