Skip to content

Commit

Permalink
Refactoring READMEs and CONTRIBUTING.md (#11)
Browse files Browse the repository at this point in the history
* Changes so far

* details

* changes

* feedback

* fix
  • Loading branch information
rohan-agarwal-coinbase authored Nov 5, 2024
1 parent b4214af commit 39b4c2a
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 143 deletions.
124 changes: 122 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# CDP Agentkit Contributing Guide
Thank you for your interest in contributing to CDP Agentkit! We welcome all contributions, no matter how big or small. Some of the ways you can contribute include:
- Adding new actions to the core package
- Updating existing Langchain Toolkits or adding new Langchain Toolkits to support new tools
- Creating new AI frameworks extensions
- Adding tests and improving documentation

## Development

### Python Version
### Prerequisites
- Python 3.10 or higher
- Rust/Cargo installed ([Rust Installation Instructions](https://doc.rust-lang.org/cargo/getting-started/installation.html))
- Poetry for package management and tooling
- [Poetry Installation Instructions](https://python-poetry.org/docs/#installation)

Developing in this repository requires Python 3.10 or higher.
`cdp-langchain` also requires a [CDP API Key](https://portal.cdp.coinbase.com/access/api).

### Set-up

Expand All @@ -13,3 +22,114 @@ Clone the repo by running:
```bash
git clone git@github.com:coinbase/cdp-agentkit.git
```

## Adding an Action to Agentkit Core
- 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}"
```

## Adding an Agentic Action to Langchain Toolkit
1. Ensure the action is implemented in `cdp-agentkit-core`.
2. Add a wrapper method to `CdpAgentkitWrapper` in `./cdp_langchain/utils/cdp_agentkit_wrapper.py`
- E.g.
```python
def mint_nft_wrapper(self, contract_address: str, destination: str) -> str:
"""Mint an NFT (ERC-721) to a specified destination address onchain via a contract invocation.
Args:
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.
"""
return mint_nft(
wallet=self.wallet,
contract_address=contract_address,
destination=destination,
)
```
3. Add call to the wrapper in `CdpAgentkitWrapper.run` in `./cdp_langchain/utils/cdp_agentkit_wrapper.py`
- E.g.
```python
if mode == "mint_nft":
return self.mint_nft_wrapper(**kwargs)

```
4. Add the action to the list of available tools in the `CdpToolkit` in `./cdp_langchain/agent_toolkits/cdp_toolkit.py`
- E.g.
```python
actions: List[Dict] = [
{
"mode": "mint_nft",
"name": "mint_nft",
"description": MINT_NFT_PROMPT,
"args_schema": MintNftInput,
},
]
```
5. Add the action to the list of tools in the `CdpToolkit` class documentation.

## Development Tools
### Formatting
`make format`

### Linting
- Check linter
`make lint`

- Fix linter errors
`make lint-fix`

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

## Changelog
- For new features and bug fixes, please add a new changelog entry to the `CHANGELOG.md` file in the appropriate packages and include that in your Pull Request.
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
[![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!
The Coinbase Developer Platform (CDP) Agentkit simplifies bringing your AI Agents onchain. Every AI Agent deserves a crypto wallet!

## Key Features
- Framework-agnostic: Common AI Agent primitives that can be used with any AI framework.
- Langchain Toolkit: Integration with Langchain for easy agentic workflows. More frameworks coming soon!
- Support for various on-chain actions:
- Faucet for testnet funds
- Getting wallet details and balances
- Transferring and trading tokens
- Registering Basenames
- Deploying ERC20 tokens and creating uniswap_v3 pools for trading
- Deploying ERC721 tokens and minting NFTs

## 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.
Check out `cdp-langchain/examples` for inspiration and help getting started!
- [Chatbot](./cdp-langchain/examples/chatbot/README.md): Simple example of a Chatbot that can perform complex onchain interactions, using OpenAI.

## Repository Structure
CDP Agentkit is organized as a [monorepo](https://en.wikipedia.org/wiki/Monorepo) that contains multiple packages.
Expand All @@ -23,13 +29,14 @@ CDP Agentkit is organized as a [monorepo](https://en.wikipedia.org/wiki/Monorepo
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.
### cdp-langchain
Langchain Toolkit extension of CDP Agentkit. Enables agentic workflows to interact with onchain actions.
See [CDP Langchain](./cdp-langchain/README.md) to get started!

### twitter-langchain
Langchain Toolkit extension for Twitter. Enables agentic workflows to interact with Twitter, such as to post a tweet.
See [Twitter Langchain](./twitter-langchain/README.md) to get started!

## Contributing
CDP Agentkit welcomes community contributions.
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
Expand Down
79 changes: 4 additions & 75 deletions cdp-agentkit-core/README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,7 @@
# Agentkit Core
Core primitives and framework agnostic tools that are meant to be composable and used via Agentkit framework extensions.
Framework agnostic primitives that are meant to be composable and used via Agentkit framework extensions.

## Developing
- `cdp-sdk` has a dependency on `cargo`, please install rust and add `cargo` to your path
- [Rust Installation Instructions](https://doc.rust-lang.org/cargo/getting-started/installation.html)
- `export PATH="$HOME/.cargo/bin:$PATH"`
- 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
You can find all of the supported actions under `./cdp_agentkit_core/actions`

## Documentation
- [Agentkit-Core](https://coinbase.github.io/cdp-agentkit-core)

### 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}"
```
## Contributing
See [CONTRIBUTING.md](../CONTRIBUTING.md) for more information.
Loading

0 comments on commit 39b4c2a

Please sign in to comment.