How Agents Work
At its core, Agentkit translates natural language intent into on-chain UserOperations. But the LLM itself cannot sign transactions or connect to RPC nodes.
Agentkit provides the bridge through a pattern called Tool Calling (or Function Calling).
The Life of an Action
Section titled “The Life of an Action”Let’s say a user types: “Send 5 USDC to vitalik.eth”
Here is step-by-step how Agentkit handles it:
1. The Prompt
Section titled “1. The Prompt”You pass the user’s message to your LLM (e.g., GPT-4), along with the Agentkit tools.
The LLM reads the tools and sees smart_transfer. The prompt tells the LLM:
“If you want to transfer tokens, return a JSON object with
to,amount, andtokenAddress. Use this tool.”
2. The LLM Response
Section titled “2. The LLM Response”The LLM realizes it needs to use smart_transfer. It stops answering directly and instead returns a structured request:
{ "name": "smart_transfer", "arguments": { "to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", // Resolved vitalik.eth "amount": "5", "tokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" // USDC address }}3. Agentkit Execution
Section titled “3. Agentkit Execution”Your code receives this JSON from the LLM and hands it to Agentkit.
- Agentkit sees it’s a
SmartTransferAction. - It fetches the USDC contract’s decimals using a public RPC.
- It encodes the
transfer(address,uint256)data payload. - It constructs a
UserOperationfor the Agent’s smart account. - It asks the Agent’s signer (e.g., KMS or a local key) to sign the hash.
- It submits the
UserOperationto the 0xGasless Bundler.
4. Returning to the LLM
Section titled “4. Returning to the LLM”Once the transaction is submitted, Agentkit returns the result (e.g., “Transaction submitted: 0xhash”) back to the LLM.
The LLM receives this result, realizes the job is done, and finally writes a human-readable response to the user:
“I have successfully sent 5 USDC to vitalik.eth. Here is the transaction hash: 0xhash.”
Why the Agentkit class?
Section titled “Why the Agentkit class?”When you call Agentkit.configureWithPlatform() (or configureWithWallet()),
you are providing the context that the tools need to execute Step 3.
The actions themselves (smart_transfer, get_balance, pay_api) don’t know
which wallet acts until they run through an Agentkit instance. In platform
mode it holds the authenticated @0xgasless/agent client bound to your API
key and agent — signing happens in 0xGasless KMS under the project’s spending
policy. In self-custody mode it holds the local key’s smart-account
session.
If you are running a server with many users, configure one Agentkit per
agent so the tools always execute from the correct wallet.