Compound Actions for Coinbase AgentKit

Hello Compound Community :wave:

I’m excited to share a proposal to the Compound Grants Program (CGP): Compound Actions for Coinbase AgentKit. With the proposal’s approval, I’m creating this post here as the place for project updates.

This initiative aims to streamline the integration of Compound Finance contract interactions Supply, Borrow, Withdraw, and Repay into AI agent workflows using Coinbase’s AgentKit.

What are Compound Actions for Coinbase AgentKit?

This project will introduce pre-built Compound Actions that allow AI agents to interact with Compound’s lending and borrowing markets without requiring direct knowledge of smart contracts. Developers will be able to integrate Compound into AI-driven applications effortlessly, unlocking new possibilities in AIxDeFi automation.

Why This Matters

  • Increases Compound adoption by making it more accessible to developers building AI agents.
  • Simplifies smart contract interactions, abstracting complexities so developers don’t need to know that supply and repay share the same function.
  • Boosts lending and borrowing activity by enabling AI-driven execution of DeFi strategies.
  • Places Compound in front of AI developers through Coinbase’s developer ecosystem, ensuring Compound is an integral part of emerging AI automation.

Project Scope & Deliverables

The project is structured into three key milestones, each focused on delivering an essential piece of the integration. I expect the project to last for 7 to 10 weeks to have all the milestones completed and to have the new tools in the hands of AIxDeFi developers.

Milestone 1: Develop and Test Python Actions for AgentKit

  • Duration: 3-4 weeks
  • Deliverables:
    • Python Supply, Borrow, Withdraw, Repay Actions
    • Unit and integration tests with documentation
  • :ship: This milestone’s completed when these tools are merged into the Coinbase/agentkit Github repository.

Milestone 2: Port Actions to TypeScript

  • Duration: 2-3 weeks
  • Deliverables:
    • Typescript Supply, Borrow, Withdraw, Repay Actions
    • Unit and integration tests with documentation
  • :ship: This milestone’s completed when these tools are merged into the Coinbase/agentkit Github repository.

Milestone 3: Develop a Full AgentKit Template Using Compound Actions

  • Duration: 3-4 weeks
  • Deliverables:
    • AI Agent template demonstrating integration of Compound Actions in Python and TypeScript
    • Step-by-step documentation and best practices for developers
    • Published GitHub template for easy adoption and customization
  • :ship: This milestone’s completed when at least three developers have forked/cloned the Compound agentkit template and used it to build an AI agent with Compound Actions to ensure real-world adoption.

Feedback Welcome

With the CGP grant approved, I’ll be completing the KYC verification and contracting process before moving into development.

I’d love to hear from the Compound community:

  • Would you use Compound in your AI agent applications?
  • What features or optimizations would be most useful for your workflows?

Let’s discuss it below!

1 Like

I dont see how this isnt good for Compound, it needs more users.

I am wary of AI agents in general as most of them are untested / unaudited. Doesnt mean people shouldnt use them but I think they are mostly unproven at this point.

Interested to see what people want.

I would like an autocompound feature, maybe a looper 2-4 times depending on profitablility, or perhaps a position that autobalances stablecoin rates across Comets (might be too difficult).

3 Likes

Hello Compound Community! :wave:

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.

:gear: 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. :bar_chart:

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!
-------------------

:computer: 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. :white_check_mark:

Here’s what the agent can now do:

  • :bank: 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!
-------------------
  • :money_with_wings: 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!
-------------------
  • :recycle: 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!
-------------------
  • :outbox_tray: 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!
-------------------

:ocean: :ship: 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.

:crystal_ball: What’s Next?

  • Address any feedback on my pull request when it arrives.
  • Start porting the actions to TypeScript. :keyboard:
  • 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. :rocket:

– Mike

2 Likes