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 SmartTransferAction. 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 SmartTransferAction. It stops answering directly and instead returns a structured request:
{ "name": "SmartTransferAction", "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 AgentKit class?
Section titled “Why AgentKit class?”When you initialize new AgentKit(), you are providing the context that the tools need to execute Step 3.
The actions themselves (SmartTransferAction, GetBalanceAction) don’t know who is sending the transaction until they are wrapped by AgentKit. The AgentKit holds the specific OxGasClient instance bound to the specific API key and private key of the current running session.
If you are running a server with many users, you initialize one AgentKit per user session with their specific keys, so the tools always execute from the correct wallet.