Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ body:
from coinbase_agentkit import (
AgentKit,
AgentKitConfig,
CdpWalletProvider,
CdpWalletProviderConfig,
CdpEvmWalletProvider,
CdpEvmWalletProviderConfig,
erc20_action_provider
)
from coinbase_agentkit_langchain import get_langchain_tools

# A succinct reproducing example trimmed down to the essential parts:
cdp_config = CdpWalletProviderConfig(
cdp_config = CdpEvmWalletProviderConfig(
network_id="base-sepolia"
)
wallet_provider = CdpWalletProvider(cdp_config)
wallet_provider = CdpEvmWalletProvider(cdp_config)
agentkit = AgentKit(AgentKitConfig(
wallet_provider=wallet_provider,
action_providers=[
Expand All @@ -49,20 +49,20 @@ body:
```

```typescript
# All necessary imports at the beginning
import { AgentKit, CdpWalletProvider, cdpWalletActionProvider } from '@coinbase/agentkit';
// All necessary imports at the beginning
import { AgentKit, CdpEvmWalletProvider, walletActionProvider } from '@coinbase/agentkit';
import { getLangChainTools } from '@coinbase/agentkit-langchain';

# A succinct reproducing example trimmed down to the essential parts:
// A succinct reproducing example trimmed down to the essential parts:
const config = {
networkId: "base-sepolia"
};

const walletProvider = await CdpWalletProvider.configureWithWallet(config);
const walletProvider = await CdpEvmWalletProvider.configureWithWallet(config);
const agentkit = await AgentKit.from({
walletProvider,
actionProviders: [
cdpWalletActionProvider()
walletActionProvider()
]
});

Expand Down
37 changes: 26 additions & 11 deletions CONTRIBUTING-PYTHON.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ This says that the input schema has two fields: `contract_address` and `destinat
### Implementing the action provider

```python
class CdpWalletActionProvider(ActionProvider[CdpWalletProvider]):
"""Provides actions for interacting with CDP wallets."""
from coinbase_agentkit import ActionProvider, EvmWalletProvider
from coinbase_agentkit.network import Network

class Erc721ActionProvider(ActionProvider[EvmWalletProvider]):
"""Provides ERC-721 actions for EVM wallets."""

def __init__(self):
super().__init__("cdp-wallet", [])
super().__init__("erc721", [])

def supports_network(self, network: Network) -> bool:
return network.protocol_family == "evm"
Expand All @@ -123,6 +126,11 @@ class CdpWalletActionProvider(ActionProvider[CdpWalletProvider]):
Now we need to implement the actual function that the AI will call when using your action. Actions are defined using the `@create_action` decorator. The function receives as input the wallet provider that the Agent has access to, along with the inputs defined in the input schema, and it must return a string. Here's an example of the Mint NFT implementation:

```python
from eth_typing import HexStr
from web3 import Web3

from coinbase_agentkit import EvmWalletProvider, create_action

@create_action(
name="mint",
description="""
Expand All @@ -132,20 +140,27 @@ Do not use the contract address as the destination address. If you are unsure of
""",
schema=MintSchema,
)
def mint(self, wallet_provider: CdpWalletProvider, args: dict[str, Any]) -> str:
def mint(self, wallet_provider: EvmWalletProvider, args: dict[str, Any]) -> str:
"""Mint an NFT."""
try:
nft_contract = wallet_provider.mint(
contract_address=args["contract_address"],
destination=args["destination"]
).wait()
contract = Web3().eth.contract(address=args["contract_address"], abi=ERC721_ABI)
data = contract.encode_abi("mint", args=[args["destination"], 1])

tx_hash = wallet_provider.send_transaction(
{
"to": HexStr(args["contract_address"]),
"data": HexStr(data),
}
)

wallet_provider.wait_for_transaction_receipt(tx_hash)
except Exception as e:
return f"Error deploying NFT {e!s}"
return f"Error minting NFT {args['contract_address']} to {args['destination']}: {e!s}"

return f"Minted NFT to address {args['destination']}.\nTransaction hash: {nft_contract.transaction.transaction_hash}\nTransaction link: {nft_contract.transaction.transaction_link}"
return f"Successfully minted NFT {args['contract_address']} to {args['destination']}"
```

Notice the return value contains useful information for the user, such as the transaction hash and link. It's important to include this information in the return value so that the user can easily see the result of the action.
Notice the return value contains useful information for the user about the result of the action. When possible, include details such as transaction hashes so the user can inspect what happened onchain.

This class is then exported out of [python/coinbase-agentkit/coinbase_agentkit/\_\_init\_\_.py](https://github.com/coinbase/agentkit/blob/master/python/coinbase-agentkit/coinbase_agentkit/__init__.py) so that it is consumable by users of the `coinbase-agentkit` package.

Expand Down
54 changes: 7 additions & 47 deletions python/coinbase-agentkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
- [EthAccountWalletProvider](#ethaccountwalletprovider)
- [Configuring gas parameters](#configuring-ethaccountwalletprovider-gas-parameters)
- [Configuring `EthAccountWalletProvider` rpc url](#configuring-ethaccountwalletprovider-rpc-url)
- [SmartWalletProvider](#smartwalletprovider)
- [CdpSolanaWalletProvider](#cdpsolanawalletprovider)
- [Configuring with API credentials](#configuring-with-api-credentials)
- [Using environment variables](#using-environment-variables)
Expand All @@ -56,10 +55,10 @@ pip install coinbase-agentkit

### Create an AgentKit instance

If no wallet or action providers are specified, the agent will use the `CdpWalletProvider` and `WalletActionProvider` action provider by default.
If no wallet or action providers are specified, the agent will use the `CdpEvmWalletProvider` and `WalletActionProvider` action provider by default. Make sure `CDP_API_KEY_ID`, `CDP_API_KEY_SECRET`, and `CDP_WALLET_SECRET` are set in your environment if you rely on this default.

```python
from coinbase_agentkit import AgentKit, AgentKitConfig
from coinbase_agentkit import AgentKit

agent_kit = AgentKit()
```
Expand All @@ -70,13 +69,14 @@ agent_kit = AgentKit()
from coinbase_agentkit import (
AgentKit,
AgentKitConfig,
CdpWalletProvider,
CdpWalletProviderConfig
CdpEvmWalletProvider,
CdpEvmWalletProviderConfig,
)

wallet_provider = CdpWalletProvider(CdpWalletProviderConfig(
wallet_provider = CdpEvmWalletProvider(CdpEvmWalletProviderConfig(
api_key_id="CDP API KEY NAME",
api_key_secret="CDP API KEY SECRET",
wallet_secret="CDP WALLET SECRET",
network_id="base-mainnet"
))

Expand All @@ -98,10 +98,7 @@ from coinbase_agentkit import (
agent_kit = AgentKit(AgentKitConfig(
wallet_provider=wallet_provider,
action_providers=[
cdp_api_action_provider(
api_key_id="CDP API KEY NAME",
api_key_secret="CDP API KEY SECRET"
),
cdp_api_action_provider(),
pyth_action_provider()
]
))
Expand Down Expand Up @@ -958,43 +955,6 @@ agent_kit = AgentKit(AgentKitConfig(
))
```

### CDPSmartWalletProvider

The `CDPSmartWalletProvider` is a wallet provider that uses [CDP Smart Wallets](https://docs.cdp.coinbase.com/wallet-api/docs/smart-wallets).

```python
import os
from eth_account import Account

from coinbase_agentkit import (
AgentKit,
AgentKitConfig,
SmartWalletProvider,
SmartWalletProviderConfig
)

# See here for creating a private key:
# https://web3py.readthedocs.io/en/stable/web3.eth.account.html#creating-a-private-key
private_key = os.environ.get("PRIVATE_KEY")
assert private_key is not None, "You must set PRIVATE_KEY environment variable"
assert private_key.startswith("0x"), "Private key must start with 0x hex prefix"

signer = Account.from_key(private_key)

network_id = os.getenv("NETWORK_ID", "base-sepolia")

wallet_provider = SmartWalletProvider(SmartWalletProviderConfig(
network_id=network_id,
signer=signer,
smart_wallet_address=None, # If not provided, a new smart wallet will be created
paymaster_url=None, # Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome
))

agent_kit = AgentKit(AgentKitConfig(
wallet_provider=wallet_provider
))
```

### CdpSolanaWalletProvider

The `CdpSolanaWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) API for Solana networks. It supports SOL transfers and message signing on Solana mainnet, devnet, and testnet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ from coinbase_agentkit.action_providers.compound.compound_action_provider import
CompoundActionProvider,
)
from coinbase_agentkit.action_providers.weth.weth_action_provider import WethActionProvider
from coinbase_agentkit.wallet_providers import CdpWalletProvider
from coinbase_agentkit.wallet_providers import (
CdpEvmWalletProvider,
CdpEvmWalletProviderConfig,
)

# Constants
USDC_ASSET = "usdc"
Expand All @@ -71,7 +74,7 @@ WAIT_TIME = 15
@pytest.fixture
def wallet():
"""Create a real wallet instance for testing using the CDP wallet provider."""
return CdpWalletProvider()
return CdpEvmWalletProvider(CdpEvmWalletProviderConfig())

@pytest.fixture
def compound_provider():
Expand Down
3 changes: 2 additions & 1 deletion python/framework-extensions/autogen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Set the following environment variables:
```bash
export OPENAI_API_KEY=<your-openai-api-key>
export CDP_API_KEY_ID=<your-cdp-api-key-id>
export CDP_API_KEY_PRIVATE=<your-cdp-api-key-private>
export CDP_API_KEY_SECRET=<your-cdp-api-key-secret>
export CDP_WALLET_SECRET=<your-cdp-wallet-secret>
```

## Usage
Expand Down
3 changes: 2 additions & 1 deletion python/framework-extensions/langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Set the following environment variables:
```bash
export OPENAI_API_KEY=<your-openai-api-key>
export CDP_API_KEY_ID=<your-cdp-api-key-id>
export CDP_API_KEY_PRIVATE=<your-cdp-api-key-private>
export CDP_API_KEY_SECRET=<your-cdp-api-key-secret>
export CDP_WALLET_SECRET=<your-cdp-wallet-secret>
```

## Usage
Expand Down
3 changes: 2 additions & 1 deletion python/framework-extensions/openai-agents-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Set the following environment variables:
```bash
export OPENAI_API_KEY=<your-openai-api-key>
export CDP_API_KEY_ID=<your-cdp-api-key-id>
export CDP_API_KEY_PRIVATE=<your-cdp-api-key-private>
export CDP_API_KEY_SECRET=<your-cdp-api-key-secret>
export CDP_WALLET_SECRET=<your-cdp-wallet-secret>
```

## Usage
Expand Down
Loading
Loading