Quickstart (SDK)
Five lines from install to a named, policy-bound agent acting onchain.
1. Install
npm install @agensai/sdk2. Configure
AGENSAI_API_KEY=...
AGENSAI_OWNER_PRIVATE_KEY=...3. Create an agent
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" },
],
});
console.log(agent.name); // "my-agent.agensai.eth"
console.log(agent.address); // "0x7a3b…c2f1"createAgent is one call. Internally it provisions the smart account, issues the ENS subname, and grants the ERC-7715 permissions.
4. Execute
const txHash = await agent.execute({
to: "treasury.acme.eth",
amount: "10 USDC",
});Atomic batch:
const { id } = await agent.batch([
{ to: "uniswap.eth", value: 0n, data: swapCalldata },
{ to: "treasury.acme.eth", amount: "5 USDC" },
]);ENS names are resolved automatically.
5. Restore an existing agent
import { getAgent } from "@agensai/sdk";
const agent = await getAgent("my-agent.agensai.eth", {
apiKey: process.env.AGENSAI_API_KEY!,
ownerPrivateKey: process.env.AGENSAI_OWNER_PRIVATE_KEY! as `0x${string}`,
});
await agent.execute({ to: "bob.eth", amount: "1 USDC" });6. Inspect policies
const policies = await agent.policies();7. Revoke
await agent.revoke();Revocation is permanent and onchain. The ENS subname survives.
8. List agents
import { listAgents } from "@agensai/sdk";
const agents = await listAgents({ apiKey: process.env.AGENSAI_API_KEY! });
for (const a of agents) {
console.log(a.name, a.address, a.status);
}Key rules
- You MUST set
AGENSAI_API_KEY. - You MUST provide an
ownerPrivateKey. - You MUST fund the owner address with gas and tokens.
- You MUST NOT expose
AGENSAI_API_KEYin client-side code. - You MUST NOT reuse a revoked permission.