Hello Compound Community! 
I’m back with an update on my Compound Finance Grant Project. Over the past two weeks, I’ve made great progress integrating Compound actions into the Coinbase AgentKit! Here’s what’s new.
Last Week 1: Developing the Core Actions
I kicked things off by building out the key Compound Finance actions: Supply, Borrow, Repay, and Withdraw. To make sure these worked seamlessly, I created an integration test on Sepolia to verify compatibility with the Base USDC Comet contract.
Developer Notes
This section has some notes I think would be helpful to other future AgentKit developers that are working on onchain actions:
- ERC-20 Approvals: Originally, I thought I’d need a separate approval action, but I later streamlined the integration by embedding approvals directly into Supply and Repay tools as suggested by the Coinbase team. This is how the Morpho Deposit action works, calling approve before the deposit.
- Wrap and Unwrap ETH: There was only a
wrap_eth
action so I had to add a unwrap_eth
action as well. Compound Actions today use WETH, not native ETH. To avoid repeated code, I moved both wrap and unwrap actions in to an actions/weth
directory and created a constants.py
file with the WETH address and ABI. This is inline with the other action directories which contain their own constants file for the relevant contract addresses and ABIs.
- Liquidation Safe Guard: A check on the portfolio’s health ratio is performed before Borrow and Repay to prevent the agent from putting the position into an unhealthy state.
- AI-Friendly Error Handling: One big improvement over the other actions I see is making errors more readable so AI agents can self-correct when things go wrong. Preconditions can be checked and the Agent can be alerted about the problem in the action’s response. You can see two examples of where this helps with:
- Supply & Repay: Checking if the user has enough wallet or supply balance and replying with a AI-friendly response if not:
# Check wallet balance before proceeding
wallet_balance = wallet.default_address.balance(asset_id)
if Decimal(wallet_balance) < Decimal(amount):
return f"Error: Insufficient balance. You have {wallet_balance} {asset_id.upper()}, but trying to repay {amount} {asset_id.upper()}"
- Deposit & Withdraw: Ensuring the agent doesn’t push itself into a risky collateral position (e.g., maintaining a safe ratio under 0.85).
# Check if position would be healthy after borrow
projected_health_ratio = get_health_ratio_after_borrow(
wallet,
compound_address,
adjusted_amount
)
if projected_health_ratio < 1:
return f"Error: Borrowing {amount} {asset_id.upper()} would result in an unhealthy position. Health ratio would be {projected_health_ratio:.2f}"
I also realized agents needed a way to view their Compound portfolio, so I built a fifth action: Get Portfolio Details. Now, users can check their balances and positions before making transactions. 
Prompt: What is my health ratio on Compound?
-------------------
# Portfolio Details
## Supply Details
### WETH
- **Supply Amount:** 0.000100000000000000
- **Price:** $3477.28
- **Collateral Factor:** 0.78
- **Asset Value:** $0.35
### Total Supply Value: $0.35
## Borrow Details
### 0x036CbD53842c5426634e7929541eC2318f3dCF7e
- **Borrow Amount:** 0.010000
- **Price:** $1.00
- **Borrow Value:** $0.01
## Overall Health
- **Health Ratio:** 26.95
-------------------
Your health ratio on Compound is **26.95**.
If you need any further assistance or have more questions, feel free to ask!
-------------------
This Week 2: Testing & Demonstration
After finalizing the tools, I worked on a full demonstration. I ran into some issues configuring Poetry to reference my local AgentKit, but luckily, I found a newly added Python contributor guide from Coinbase that helped solve it. 
Here’s what the agent can now do:
Supply WETH into Compound’s Base Sepolia USDC Comet
Prompt: Next, supply the 0.0001 WETH to compound finance.
-------------------
Supplied 0.0001 WETH to Compound V3.
Transaction hash: 0xbe800f1eb3c7e4d7067addb016a7d78c341f879d9aee22c12be02f4cea5d13ef
Transaction link: https://sepolia.basescan.org/tx/0xbe800f1eb3c7e4d7067addb016a7d78c341f879d9aee22c12be02f4cea5d13ef
-------------------
I have successfully supplied **0.0001 WETH** to Compound Finance. You can view the transaction details [here](https://sepolia.basescan.org/tx/0xbe800f1eb3c7e4d7067addb016a7d78c341f879d9aee22c12be02f4cea5d13ef).
If you have any more requests or questions, just let me know!
-------------------
Borrow USDC
Prompt: Next, borrow 0.01 USDC from compound
-------------------
Borrowed 0.01 USDC from Compound V3.
Transaction hash: 0x1d2c8e7f18d8dd9fa5410f4e6444751fa95b6c4ccfa4a4d4be1c594dba0ca215
Transaction link: https://sepolia.basescan.org/tx/0x1d2c8e7f18d8dd9fa5410f4e6444751fa95b6c4ccfa4a4d4be1c594dba0ca215
-------------------
I have successfully borrowed **0.01 USDC** from Compound. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x1d2c8e7f18d8dd9fa5410f4e6444751fa95b6c4ccfa4a4d4be1c594dba0ca215).
If you have any further requests or questions, feel free to ask!
-------------------
Repay USDC
Prompt: Repay 0.01 USDC to Compound
-------------------
Repaid 0.01 USDC to Compound V3.
Transaction hash: 0x0de530f9b7dd0045b9581e0768547f538407b9e01312e44aee904a8215833b4f
Transaction link: https://sepolia.basescan.org/tx/0x0de530f9b7dd0045b9581e0768547f538407b9e01312e44aee904a8215833b4f
-------------------
I have successfully repaid **0.01 USDC** to Compound. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x0de530f9b7dd0045b9581e0768547f538407b9e01312e44aee904a8215833b4f).
If you have any more requests or questions, just let me know!
-------------------
Withdraw collateral
Prompt: Withdraw half of the WETH we have in Compound
-------------------
Withdrew 0.00005 WETH from Compound V3.
Transaction hash: 0x1d55b5d75468877cfe96d2ccf878fb264744fb76af0e754fc4fea6aed8cf8977
Transaction link: https://sepolia.basescan.org/tx/0x1d55b5d75468877cfe96d2ccf878fb264744fb76af0e754fc4fea6aed8cf8977
-------------------
I have successfully withdrawn **0.00005 WETH** from Compound. You can view the transaction details [here](https://sepolia.basescan.org/tx/0x1d55b5d75468877cfe96d2ccf878fb264744fb76af0e754fc4fea6aed8cf8977).
If you have any more requests or questions, feel free to ask!
-------------------
Compound Actions Pull Request
This week, I submitted a pull request for the Compound Python Actions, which is now pending review. You can review the PR yourself here: feat: Added Compound Finance Python Actions by mikeghen · Pull Request #248 · coinbase/agentkit · GitHub.
What’s Next?
- Address any feedback on my pull request when it arrives.
- Start porting the actions to TypeScript.

- Publish the basic Python Compound agent example to it’s own repository so it works as a template.
- Evangelize the new tools to start recruiting some developers to make their own Compound-enabled Agents, beyond the basic example I provide.
This update marks an exciting step forward in making Compound Finance more accessible to AI agents. Thanks for following along! Looking forward to your feedback. 
– Mike