-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add READMEs to Python Package Dirs to Unblock Poetry Publish (#…
…132)
- Loading branch information
1 parent
2dcb58e
commit b5f1cce
Showing
6 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Agentkit Core | ||
|
||
Framework agnostic primitives that are meant to be composable and used via Agentkit framework extensions. | ||
|
||
You can find all of the supported actions under | ||
|
||
Actions - `./cdp_agentkit_core/actions` | ||
|
||
## Contributing | ||
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# CDP Agentkit Extension - Langchain Toolkit | ||
|
||
CDP integration with Langchain to enable agentic workflows using the core primitives defined in `cdp-agentkit-core`. | ||
|
||
This toolkit contains tools that enable an LLM agent to interact with the [Coinbase Developer Platform](https://docs.cdp.coinbase.com/). The toolkit provides a wrapper around the CDP SDK, allowing agents to perform onchain operations like transfers, trades, and smart contract interactions. | ||
|
||
## Setup | ||
|
||
### Prerequisites | ||
|
||
#### CDP | ||
|
||
- [CDP API Key](https://portal.cdp.coinbase.com/access/api) | ||
|
||
#### OpenAI | ||
|
||
- [OpenAI API Key](https://platform.openai.com/docs/quickstart#create-and-export-an-api-key) | ||
|
||
#### Python | ||
|
||
- Python 3.10 or higher | ||
|
||
### Installation | ||
|
||
```bash | ||
pip install cdp-langchain | ||
``` | ||
|
||
### Environment Setup | ||
|
||
Set the following environment variables: | ||
|
||
```bash | ||
export CDP_API_KEY_NAME=<your-api-key-name> | ||
export CDP_API_KEY_PRIVATE_KEY=$'<your-private-key>' | ||
export OPENAI_API_KEY=<your-openai-api-key> | ||
export NETWORK_ID=base-sepolia # Optional: Defaults to base-sepolia | ||
``` | ||
|
||
## Usage | ||
|
||
### Basic Setup | ||
|
||
```python | ||
from cdp_langchain.agent_toolkits import CdpToolkit | ||
from cdp_langchain.utils import CdpAgentkitWrapper | ||
|
||
# Initialize CDP wrapper | ||
cdp = CdpAgentkitWrapper() | ||
|
||
# Create toolkit from wrapper | ||
toolkit = CdpToolkit.from_cdp_agentkit_wrapper(cdp) | ||
|
||
# Get available tools | ||
tools = toolkit.get_tools() | ||
for tool in tools: | ||
print(tool.name) | ||
``` | ||
|
||
The toolkit provides the following tools: | ||
|
||
1. **get_wallet_details** - Get details about the MPC Wallet | ||
2. **get_balance** - Get balance for specific assets | ||
3. **request_faucet_funds** - Request test tokens from faucet | ||
4. **transfer** - Transfer assets between addresses | ||
5. **trade** - Trade assets (Mainnet only) | ||
6. **deploy_token** - Deploy ERC-20 token contracts | ||
7. **mint_nft** - Mint NFTs from existing contracts | ||
8. **deploy_nft** - Deploy new NFT contracts | ||
9. **register_basename** - Register a basename for the wallet | ||
10. **wow_create_token** - Deploy a token using Zora's Wow Launcher (Bonding Curve) | ||
11. **wow_buy_token** - Buy Zora Wow ERC20 memecoin with ETH | ||
12. **wow_sell_token** - Sell Zora Wow ERC20 memecoin for ETH | ||
13. **wrap_eth** - Wrap ETH to WETH | ||
14. **pyth_fetch_price_feed_id** Fetch the price feed ID for a given token symbol from Pyth Network | ||
15. **pyth_fetch_price** fetch the price of a given price feed from Pyth Network | ||
16. **get_balance_nft** Get balance for specific NFTs (ERC-721) | ||
17. **transfer_nft** Transfer an NFT (ERC-721) | ||
|
||
### Using with an Agent | ||
|
||
```python | ||
from langchain_openai import ChatOpenAI | ||
from langgraph.prebuilt import create_react_agent | ||
|
||
# Initialize LLM | ||
llm = ChatOpenAI(model="gpt-4o-mini") | ||
|
||
# Get tools and create agent | ||
tools = toolkit.get_tools() | ||
agent_executor = create_react_agent(llm, tools) | ||
|
||
# Example usage | ||
events = agent_executor.stream( | ||
{"messages": [("user", "Send 0.005 ETH to john2879.base.eth")]}, | ||
stream_mode="values" | ||
) | ||
|
||
for event in events: | ||
event["messages"][-1].pretty_print() | ||
``` | ||
Expected output: | ||
``` | ||
Transferred 0.005 of eth to john2879.base.eth. | ||
Transaction hash for the transfer: 0x78c7c2878659a0de216d0764fc87eff0d38b47f3315fa02ba493a83d8e782d1e | ||
Transaction link for the transfer: https://sepolia.basescan.org/tx/0x78c7c2878659a0de216d0764fc87eff0d38b47f3315fa02ba493a83d8e782d1 | ||
``` | ||
|
||
## CDP Tookit Specific Features | ||
|
||
### Wallet Management | ||
|
||
The toolkit maintains an MPC wallet that persists between sessions: | ||
|
||
```python | ||
# Export wallet data | ||
wallet_data = cdp.export_wallet() | ||
|
||
# Import wallet data | ||
values = {"cdp_wallet_data": wallet_data} | ||
cdp = CdpAgentkitWrapper(**values) | ||
``` | ||
|
||
### Network Support | ||
|
||
The toolkit supports [multiple networks](https://docs.cdp.coinbase.com/cdp-sdk/docs/networks). | ||
|
||
### Gasless Transactions | ||
|
||
The following operations support gasless transactions on Base Mainnet: | ||
- USDC transfers | ||
- EURC transfers | ||
- cbBTC transfers | ||
|
||
## Examples | ||
|
||
Check out [cdp-langchain/examples](../examples) for inspiration and help getting started! | ||
- [Chatbot Python](../examples/chatbot-python/README.md): Simple example of a Python Chatbot that can perform complex onchain interactions, using OpenAI. | ||
|
||
## Contributing | ||
|
||
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for detailed setup instructions and contribution guidelines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Twitter (X) Langchain Toolkit | ||
Twitter integration with Langchain to enable agentic workflows using the core primitives defined in `cdp-agentkit-core`. | ||
|
||
This toolkit contains tools that enable an LLM agent to interact with [Twitter](https://developer.x.com/en/docs/x-api). The toolkit provides a wrapper around the Twitter (X) API, allowing agents to perform social operations like posting text. | ||
|
||
## Setup | ||
|
||
### Prerequisites | ||
|
||
#### OpenAI | ||
|
||
- [OpenAI API Key](https://platform.openai.com/api-keys) | ||
|
||
#### Twitter (X) | ||
|
||
- [Twitter (X) App Developer Keys](https://developer.x.com/en/portal/dashboard) | ||
|
||
#### Python | ||
|
||
- Python 3.10 or higher | ||
|
||
### Installation | ||
|
||
```bash | ||
pip install twitter-langchain | ||
``` | ||
|
||
### Environment Setup | ||
|
||
Set the following environment variables: | ||
|
||
```bash | ||
export OPENAI_API_KEY=<your-openai-api-key> | ||
export TWITTER_API_KEY=<your-api-key> | ||
export TWITTER_API_SECRET=<your-api-secret> | ||
export TWITTER_ACCESS_TOKEN=<your-access-token> | ||
export TWITTER_ACCESS_TOKEN_SECRET=<your-access-token-secret> | ||
export TWITTER_BEARER_TOKEN=<your-bearer-token> | ||
``` | ||
|
||
## Usage | ||
|
||
### Basic Setup | ||
|
||
```python | ||
from twitter_langchain import ( | ||
TwitterApiWrapper, | ||
TwitterToolkit | ||
) | ||
|
||
# Initialize TwitterApiwrapper | ||
twitter_api_wrapper = TwitterApiWrapper() | ||
|
||
# Create TwitterToolkit from the api wrapper | ||
twitter_toolkit = TwitterToolkit.from_twitter_api_wrapper(twitter_api_wrapper) | ||
``` | ||
|
||
View available tools: | ||
```python | ||
tools = twitter_toolkit.get_tools() | ||
for tool in tools: | ||
print(tool.name) | ||
``` | ||
|
||
### Available Tools | ||
|
||
The toolkit provides the following tools: | ||
|
||
1. **account_details** - Get the authenticated account details | ||
2. **account_mentions** - Get mentions for the account | ||
3. **post_tweet** - Post a tweet to the account | ||
3. **post_tweet_reply** - Post a reply to a tweet on Twitter | ||
|
||
### Using with an Agent | ||
|
||
```python | ||
import uuid | ||
|
||
from langchain_openai import ChatOpenAI | ||
from langchain_core.messages import HumanMessage | ||
from langgraph.prebuilt import create_react_agent | ||
|
||
llm = ChatOpenAI(model="gpt-4o-mini") | ||
|
||
# Create agent | ||
agent_executor = create_react_agent(llm, tools) | ||
|
||
# Example - post tweet | ||
events = agent_executor.stream( | ||
{ | ||
"messages": [ | ||
HumanMessage(content=f"Please post 'hello, world! {uuid.uuid4().hex}' to twitter"), | ||
], | ||
}, | ||
stream_mode="values", | ||
) | ||
|
||
for event in events: | ||
event["messages"][-1].pretty_print() | ||
``` | ||
|
||
Expected output: | ||
``` | ||
================================ Human Message ================================= | ||
Please post 'hello, world! c4b8e3744c2e4345be9e0622b4c0a8aa' to twitter | ||
================================== Ai Message ================================== | ||
Tool Calls: | ||
post_tweet (call_xVx4BMCSlCmCcbEQG1yyebbq) | ||
Call ID: call_xVx4BMCSlCmCcbEQG1yyebbq | ||
Args: | ||
tweet: hello, world! c4b8e3744c2e4345be9e0622b4c0a8aa | ||
================================= Tool Message ================================= | ||
Name: post_tweet | ||
Successfully posted! | ||
================================== Ai Message ================================== | ||
The message "hello, world! c4b8e3744c2e4345be9e0622b4c0a8aa" has been successfully posted to Twitter! | ||
``` | ||
|
||
## Examples | ||
|
||
Check out [twitter-langchain/examples](../examples) for inspiration and help getting started! | ||
- [Chatbot Python](../examples/chatbot-python/README.md): Simple example of a Python Chatbot that can interact on Twitter (X), using OpenAI. | ||
|
||
## Contributing | ||
|
||
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for detailed setup instructions and contribution guidelines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters