Skip to content

Commit

Permalink
cdp-agentkit-core + cdp-langchain
Browse files Browse the repository at this point in the history
  • Loading branch information
John-peterson-coinbase committed Nov 4, 2024
1 parent f67ec4d commit c9524a7
Show file tree
Hide file tree
Showing 55 changed files with 8,830 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
**/.DS_Store

**/.python-version

# IDE
.idea/*

## Emacs
*~
\#*\#
.\#*
**/.projectile

# Python cache files
**/__pycache__/

# Wallet data
**/wallet_data.txt

# Tools
**/.pytest_cache

**/.ruff_cache

**/.mypy_cache

**/.coverage

# Build
**/_build/

**/build/

**/dist/

# Virtual Environments
**/venv/
**/.venv/

# Environment Configurations
**/env/
**/.env/
**/.env.local/
**/.env.test/
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# CDP Agentkit Contributing Guide

## Development

### Python Version

Developing in this repository requires Python 3.10 or higher.

### Set-up

Clone the repo by running:

```bash
git clone [email protected]:coinbase/cdp-agentkit.git
```
15 changes: 15 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Apache-2.0 License

Copyright 2024 Coinbase

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
# CDP Agentkit

[![Release Notes](https://img.shields.io/github/release/coinbase/?style=flat-square)](https://github.com/coinbase/cdp-agentkit/releases)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/cdp-agentkitcore?style=flat-square)](https://pypistats.org/packages/cdp-agentkit-core)
[![GitHub star chart](https://img.shields.io/github/stars/coinbase/cdp-agentkit?style=flat-square)](https://star-history.com/#coinbase/cdp-agentkit)
[![Open Issues](https://img.shields.io/github/issues-raw/coinbase/cdp-agentkit?style=flat-square)](https://github.com/coinbase/cdp-agentkit/issues)

The Coinbase Developer Platform (CDP) Agentkit simplifies bringing your AI Agents onchain!

Agentkit is powered by the [CDP SDK](https://github.com/coinbase/cdp-sdk-python)

Every AI Agent deserves a Wallet!

## Examples
Check out `cdp-langchain/examples` for inspiration and help getting started! Learn more about each one in its README.

- [Chatbot](./cdp-langchain/examples/chatbot/README.md): Simple example of a Chatbot that can perform complex onchain interactions.

## Repository Structure
CDP Agentkit is organized as a [monorepo](https://en.wikipedia.org/wiki/Monorepo) that contains multiple packages.

### cdp-agentkit-core
Core primitives and framework agnostic tools that are meant to be composable and used via CDP Agentkit framework extensions.
See [CDP Agentkit Core](./cdp-agentkit-core/README.md) to get started!

### CDP Agentkit Extensions
CDP Agentkit integrations with popular AI frameworks.

#### cdp-langchain
Langchain Toolkit extension of CDP Agentkit.
See [CDP Langchain](./cdp-langchain/README.md) to get started!

## Contributing
CDP Agentkit welcomes community contributions.
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

## Contributors
<a href="https://github.com/coinbase/cdp-agentkit/graphs/contributors">
<img src="https://contrib.rocks/image?repo=coinbase/cdp-agentkit" />
</a>

7 changes: 7 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Security Policy

The Coinbase team takes security seriously. Please do not file a public ticket discussing a potential vulnerability.

Please report your findings through our [HackerOne][1] program.

[1]: https://hackerone.com/coinbase
15 changes: 15 additions & 0 deletions cdp-agentkit-core/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: format
format:
ruff format .

.PHONY: lint
lint:
ruff check .

.PHONY: lint-fix
lint-fix:
ruff check . --fix

.PHONY: test
test:
pytest
72 changes: 72 additions & 0 deletions cdp-agentkit-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Agentkit Core
Core primitives and framework agnostic tools that are meant to be composable and used via Agentkit framework extensions.

## Developing
- Agentkit uses `poetry` for package management and tooling
- [Poetry Installation Instructions](https://python-poetry.org/docs/#installation)
- Run `poetry install` to install `cdp-agentkit-core` dependencies
- Run `poetry shell` to activate the virtual environment

### Formatting
`make format`

### Linting
- Check linter
`make lint`

- Fix linter errors
`make lint-fix`

### Unit Testing
- Run unit tests
`make test`

## Contributing Agentic Actions
- Actions are defined in `./cdp_agentkit_core/actions` module. See `./cdp_agentkit_core/actions/mint_nft.py` for an example.

### Components of an Agentic Action
Each action will define and export 3 components:
- Prompt - A string that will provide the AI Agent with context on what the function does and a natural language description of the input.
- E.g.
```python
MINT_NFT_PROMPT = """
This tool will mint an NFT (ERC-721) to a specified destination address onchain via a contract invocation. It takes the contract address of the NFT onchain and the destination address onchain that will receive the NFT as inputs."""
```
- ArgSchema - A Pydantic Model that defines the input argument schema for the action.
- E.g.
```python
class MintNftInput(BaseModel):
"""Input argument schema for mint NFT action."""

contract_address: str = Field(
...,
description="The contract address of the NFT (ERC-721) to mint, e.g. `0x036CbD53842c5426634e7929541eC2318f3dCF7e`",
)
destination: str = Field(
...,
description="The destination address that will receieve the NFT onchain, e.g. `0x036CbD53842c5426634e7929541eC2318f3dCF7e`",
)
```
- Action Callable - A function (or Callable class) that executes the action.
- E.g.
```python
def mint_nft(wallet: Wallet, contract_address: str, destination: str) -> str:
"""Mint an NFT (ERC-721) to a specified destination address onchain via a contract invocation.
Args:
wallet (Wallet): The wallet to trade the asset from.
contract_address (str): The contract address of the NFT (ERC-721) to mint, e.g. `0x036CbD53842c5426634e7929541eC2318f3dCF7e`.
destination (str): The destination address that will receieve the NFT onchain, e.g. `0x036CbD53842c5426634e7929541eC2318f3dCF7e`.
Returns:
str: A message containing the NFT mint details.
"""
mint_args = {"to": destination, "quantity": "1"}

mint_invocation = wallet.invoke_contract(
contract_address=contract_address, method="mint", args=mint_args
).wait()

return f"Minted NFT from contract {contract_address} to address {destination} on network {wallet.network_id}.\nTransaction hash for the mint: {mint_invocation.transaction.transaction_hash}\nTransaction link for the mint: {mint_invocation.transaction.transaction_link}"
```
Empty file.
75 changes: 75 additions & 0 deletions cdp-agentkit-core/cdp_agentkit_core/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from cdp_agentkit_core.actions.deploy_nft import (
DEPLOY_NFT_PROMPT,
DeployNftInput,
deploy_nft,
)
from cdp_agentkit_core.actions.deploy_token import (
DEPLOY_TOKEN_PROMPT,
DeployTokenInput,
deploy_token,
)
from cdp_agentkit_core.actions.get_balance import (
GET_BALANCE_PROMPT,
GetBalanceInput,
get_balance,
)
from cdp_agentkit_core.actions.get_wallet_details import (
GET_WALLET_DETAILS_PROMPT,
GetWalletDetailsInput,
get_wallet_details,
)
from cdp_agentkit_core.actions.mint_nft import (
MINT_NFT_PROMPT,
MintNftInput,
mint_nft,
)
from cdp_agentkit_core.actions.register_basename import (
REGISTER_BASENAME_PROMPT,
RegisterBasenameInput,
register_basename,
)
from cdp_agentkit_core.actions.request_faucet_funds import (
REQUEST_FAUCET_FUNDS_PROMPT,
RequestFaucetFundsInput,
request_faucet_funds,
)
from cdp_agentkit_core.actions.trade import (
TRADE_PROMPT,
TradeInput,
trade,
)
from cdp_agentkit_core.actions.transfer import (
TRANSFER_PROMPT,
TransferInput,
transfer,
)

__all__ = [
"DEPLOY_NFT_PROMPT",
"DeployNftInput",
"deploy_nft",
"DEPLOY_TOKEN_PROMPT",
"DeployTokenInput",
"deploy_token",
"GET_BALANCE_PROMPT",
"GetBalanceInput",
"get_balance",
"GET_WALLET_DETAILS_PROMPT",
"GetWalletDetailsInput",
"get_wallet_details",
"MINT_NFT_PROMPT",
"MintNftInput",
"mint_nft",
"REGISTER_BASENAME_PROMPT",
"RegisterBasenameInput",
"register_basename",
"REQUEST_FAUCET_FUNDS_PROMPT",
"RequestFaucetFundsInput",
"request_faucet_funds",
"TRADE_PROMPT",
"TradeInput",
"trade",
"TRANSFER_PROMPT",
"TransferInput",
"transfer",
]
40 changes: 40 additions & 0 deletions cdp-agentkit-core/cdp_agentkit_core/actions/deploy_nft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from cdp import Wallet
from pydantic import BaseModel, Field

DEPLOY_NFT_PROMPT = """
This tool will deploy an NFT (ERC-721) contract onchain from the wallet. It takes the name of the NFT collection, the symbol of the NFT collection, and the base URI for the token metadata as inputs."""


class DeployNftInput(BaseModel):
"""Input argument schema for deploy NFT action."""

name: str = Field(
...,
description="The name of the NFT (ERC-721) token collection to deploy, e.g. `Helpful Hippos`",
)
symbol: str = Field(
...,
description="The symbol of the NFT (ERC-721) token collection to deploy, e.g. `HIPPO`",
)
base_uri: str = Field(
...,
description="The base URI for the NFT (ERC-721) token collection's metadata, e.g. `https://www.helpfulhippos.xyz/metadata/`",
)


def deploy_nft(wallet: Wallet, name: str, symbol: str, base_uri: str) -> str:
"""Deploy an NFT (ERC-721) token collection onchain from the wallet.
Args:
wallet (Wallet): The wallet to deploy the NFT from.
name (str): The name of the NFT (ERC-721) token collection to deploy, e.g. `Helpful Hippos`.
symbol (str): The symbol of the NFT (ERC-721) token collection to deploy, e.g. `HIPPO`.
base_uri (str): The base URI for the NFT (ERC-721) token collection's metadata, e.g. `https://www.helpfulhippos.xyz/metadata/`.
Returns:
str: A message containing the NFT token deployment details.
"""
nft_contract = wallet.deploy_nft(name=name, symbol=symbol, base_uri=base_uri).wait()

return f"Deployed NFT Collection {name} to address {nft_contract.contract_address} on network {wallet.network_id}.\nTransaction hash for the deployment: {nft_contract.transaction.transaction_hash}\nTransaction link for the deployment: {nft_contract.transaction.transaction_link}"
36 changes: 36 additions & 0 deletions cdp-agentkit-core/cdp_agentkit_core/actions/deploy_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from cdp import Wallet
from pydantic import BaseModel, Field

DEPLOY_TOKEN_PROMPT = """
This tool will deploy an ERC20 token smart contract. It takes the token name, symbol, and total supply as input. The token will be deployed using the wallet's default address as the owner and initial token holder.
"""


class DeployTokenInput(BaseModel):
"""Input argument schema for deploy token action."""

name: str = Field(..., description='The name of the token (e.g., "My Token")')
symbol: str = Field(..., description='The token symbol (e.g., "USDC", "MEME", "SYM")')
total_supply: str = Field(
..., description='The total supply of tokens to mint (e.g., "1000000")'
)


def deploy_token(wallet: Wallet, name: str, symbol: str, total_supply: str) -> str:
"""Deploy an ERC20 token smart contract.
Args:
wallet (wallet): The wallet to deploy the Token from.
name (str): The name of the token (e.g., "My Token")
symbol (str): The token symbol (e.g., "USDC", "MEME", "SYM")
total_supply (str): The total supply of tokens to mint (e.g., "1000000")
Returns:
str: A message containing the deployed token contract address and details
"""
token_contract = wallet.deploy_token(name=name, symbol=symbol, total_supply=total_supply)

token_contract.wait()

return f"Deployed ERC20 token contract {name} ({symbol}) with total supply of {total_supply} tokens at address {token_contract.contract_address}. Transaction link: {token_contract.transaction.transaction_link}"
Loading

0 comments on commit c9524a7

Please sign in to comment.