← All articles

How to let an AI agent automate on-chain actions safely

Give the agent tools that ask for specific actions, keep the keys and the rules for those actions in a secure enclave, and run recurring work on a schedule instead of leaving the agent in charge of timing. Here is how to set that up.

Lit Protocol

To let an AI agent automate on-chain actions safely, give it tools that ask for specific actions, and keep the keys and the rules for those actions where the agent cannot reach them. On Lit Protocol, each tool calls a Lit Action, a JavaScript function that runs inside a secure enclave next to the wallet's key. The action checks every request against limits written into its code before it signs. Recurring work, like a weekly rebalance, runs on a schedule with Lit Triggers, so it runs even when the agent is not running.

Why agents need limits next to the key

An agent does what its context tells it to. A prompt injection in a web page, an email, or a tool result can tell it to send funds somewhere new. If the agent holds the private key, nothing stops that. If the key and the rules live in an enclave, the worst a confused or hijacked agent can do is make a request that passes the rules.

Give the agent tools that call Lit Actions

Each on-chain capability becomes a tool. A tool might pay an approved vendor, swap within a size limit, or rebalance within a band. When the agent calls the tool, your code sends the request to the Lit Action, and the action decides whether to sign. The post on giving your AI agent a crypto wallet has a payment tool and its rule, with a cap and a vendor allowlist.

Put the limits in the action's code. The tool's description only helps the agent choose which tool to call.

Let a schedule handle the timing

Some work should happen whether or not the agent is running, like topping up gas, rebalancing, or sweeping. Put that work in an action and run it on a schedule with Lit Triggers. The agent can still propose changes, such as a new target, but a person approves them before they become part of the code. The post on running a scheduled job that signs transactions shows the setup.

Keep the agent's other credentials out of its context

Agents also need API keys for data providers, exchanges, and internal services. Those keys leak the same way, through logs and transcripts. Agent Keychain has connected services for Stripe, OpenAI, GitHub, Slack, and Supabase, where the credential is used inside a Lit enclave and never returned to the agent. Other secrets stored in Keychain are delivered to the agent's machine when it uses them. For a key that should never reach the agent, such as an exchange API key, write a Lit Action that decrypts it and makes the call inside the enclave. The post on giving an AI agent production credentials without the agent seeing them walks through it.

What to decide before you start

Decide which actions the agent may take, the most it may move in one request and in total, and who approves a change to those limits. Actions do not keep state between runs, so a total limit needs a spending record the action checks, such as a contract or signed storage. Fund the agent's wallet with what it may spend, and keep the rest elsewhere. If the agent's actions need to answer to more than one person, convert the account to ChainSecured mode with a Safe as the owner, so changes to the rules need your signers.

Get started

To create an account, go to the Lit dashboard and click Create an account. Lit Triggers is documented at developer.litprotocol.com/lit-triggers, and Agent Keychain at developer.litprotocol.com/keychain.