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

Hello everyone! :wave:

Here’s the latest update on my Compound Finance Grant project. The past week has been full of challenges and progress, and I’m excited to share what’s new. :rocket:

:hammer_and_wrench: Week 3: Python and Typescript Action Providers

Last week, Coinbase introduced a breaking change with the new v0.1.0 for Python. This meant I had to redo my work on the Python actions I created in Weeks 1 and 2 to fix into the new action provider paradigm.

I ended the week opening a PR for the Compound TypeScript Actions (Milestone 2). While I’m not as familiar with TypeScript, Cursor’s AI features assisted in porting the Python Action Provider to TypeScript. :clap:

:link: PRs from last week:

:robot: Week 4: Complex Example & Bug Fix for Morpho Actions

This week, I started working on a more complex example where an AI would use both Morpho and Compound. However, I quickly ran into an issue—the Morpho Action Provider was broken due to a typo in the deposit and withdraw function headers (wallet should be wallet_provider ). To help fix this, I opened an issue and submitted a PR which was merged right away. :hammer_and_wrench:

:link: PRs from this week:

Beyond that fix, I had a great weekend connecting with two local AIxDeFi developers. I briefed them on the tools and I proposed two applications that I think would be useful:

  1. Financial Planner AI :bar_chart:
    • Helps individuals/businesses responsibly borrow against ETH, implementing borrowing policies defined via prompts. The key feature is the AI’s ability to enforce a natural language financial plan, as well as help with financial literacy by explaining things to the user.
  2. Angel Investor AI :angel:
    • Accepts funding proposals, evaluates them against preset policies, and borrows USDC against ETH collateral to fund approved requests. The key feature here is the ability to enforce a natural language investment policy so the AI will borrow responsibly and invest in entrepreneurs that make proposals that are investable—according to the policy.

:crystal_ball: What’s Next?

  • Wait for the Python & Typescript actions to be merged into coinbase/agentkit (Milestones 1 & 2)
  • Continue to work with AIxDeFi developers to build applications using the Compound actions.

Here at the 4th week, things are on track to be completed in the timeline. PRs are opened for both Milestone 1 & 2. Also, related to Milestone 3, two developers are currently working on apps using the example app template I made.

2 Likes

Hello everyone! :wave:

Here’s the latest update on my Compound Finance Grant project. The past couple of weeks have been exciting as I hit some major milestones and made significant progress on the final phase of the project.

:tada: Week 5: Major Milestones Completed!

Great news! The Compound Finance actions for both TypeScript and Python have been merged into Coinbase’s AgentKit. Available in @coinbase/agentkit v0.2.3 for Typescript coinbase-agentkit v0.1.4 for Python.

I started building a Python chat server for a starter template, as part of the 3rd Milestone. The GitHub templates in Python and TypeScript will make it easy for developers to start building AI x DeFi apps that use Compound Finance. A screenshot of the current application is shown below:


Work in progress: Portfolio details are hardcoded in this screenshot.

:bug: Week 6: Debugging & Frontend Development

While working on the template application, I found a bug in the borrow action. Fortunately, I was able to fix the issue, and the Coinbase team was incredibly responsive in getting my fix merged quickly.
[Compound Borrow Action Error · Issue #496 · coinbase/agentkit · GitHub]

I also made progress on the frontend for my Python chat server backend. The system is designed to receive chat messages from a frontend, but with an important security feature: messages must be signed with an EVM wallet. This ensures that every message is authenticated and tied to the wallet that signed it.

Both the Python and TypeScript templates will use the same React/Vite frontend. While there’s an option to support a Streamlit frontend for Python, I believe most developers will be more comfortable using React/Vite on the Frontend.

:soon_arrow: Basic Features to Add Next

  • Improve Chat History :card_index_dividers:

    • Currently, chat history is stored in memory and only supports a single conversation thread.
    • Updating to support individual chat threads per account.
  • Retrieve Chat History from the Frontend :memo:

    • Right now, when a user logs in, their chat history doesn’t load.
    • Adding an endpoint so that when a user signs in with their wallet, their previous conversations are automatically retrieved and displayed.

Lots of progress in the last two weeks! Looking forward to polishing the final pieces and getting everything ready for developers to start using these templates. Thanks for following along! :rocket:

– Mike

4 Likes

Hello everyone! :wave:

I’m back with a Week 7 and 8 update on my Compound Finance Grant project. The finish line is coming into view, and I’ve got some exciting features and demos to share! :rocket:

:technologist: Week 7: Frontend + Backend Progress

I continued building out the frontend and backend of the Compound Assistant template. A major upgrade this week was integrating Wagmi, which connects the frontend to the blockchain. Now, portfolio data updates in real time without needing to refresh the app whenever a new transaction is made.

Key features related to chat history improvements and multi-user support are still under development:

  • Persistent chat history per wallet.
  • Ability to retrieve previous messages when the user logs back in.
  • One wallet per user.

:open_file_folder: Week 8: Code Live + TypeScript Template Begins

The Python-based Compound Assistant template is now available on GitHub!

:link: GitHub - mikeghen/compound-assistant: AI Portfolio Manager using Compound Finance and Base

I’ve also started implementing the TypeScript version of the template for developers that prefer Typescript. I do think the Typescript template will be more popular.

:test_tube: Feature Demos

  1. :locked_with_pen: Signed Messaging
    Users sign chat messages with their EVM wallet before sending them to the backend. This lets the assistant verify the identity of the user based on the wallet signature. This is a key security feature for financial interactions.

  1. :abacus: Assistant-Powered Math with Python Tooling
    Instead of relying on the LLM to do math (which can be inaccurate), we give the assistant a Python Tool. The assistant now writes Python code to perform calculations, executes it, and returns the result. This ensures more reliable and precise financial computations. In the future I will add the key formulas someone would need (e.g., calculate max borrow) so the Assistant will most certainly get it right.

Prompt: How much can I borrow?

:soon_arrow: What’s Next?

  • Complete the chat history features (support for multiple users).
  • Finish and publish the TypeScript template.
  • Work with developers to build 2 or more applications based on this template.

Thanks again for following along! If you’d like to try out the Compound Assistant or contribute feedback, feel free to reach out.

– Mike

2 Likes