diff --git a/cdp-agentkit-core/python/README.md b/cdp-agentkit-core/python/README.md deleted file mode 120000 index 32d46ee8..00000000 --- a/cdp-agentkit-core/python/README.md +++ /dev/null @@ -1 +0,0 @@ -../README.md \ No newline at end of file diff --git a/cdp-agentkit-core/python/README.md b/cdp-agentkit-core/python/README.md new file mode 100644 index 00000000..cfd870fa --- /dev/null +++ b/cdp-agentkit-core/python/README.md @@ -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. diff --git a/cdp-langchain/README.md b/cdp-langchain/README.md index 02ae48cc..bf325fd5 100644 --- a/cdp-langchain/README.md +++ b/cdp-langchain/README.md @@ -102,6 +102,10 @@ The toolkit provides the following tools: 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 diff --git a/cdp-langchain/python/README.md b/cdp-langchain/python/README.md new file mode 100644 index 00000000..ae4453ba --- /dev/null +++ b/cdp-langchain/python/README.md @@ -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= +export CDP_API_KEY_PRIVATE_KEY=$'' +export 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. diff --git a/cdp-langchain/python/pyproject.toml b/cdp-langchain/python/pyproject.toml index 566ac020..f732eac3 100644 --- a/cdp-langchain/python/pyproject.toml +++ b/cdp-langchain/python/pyproject.toml @@ -3,7 +3,7 @@ name = "cdp-langchain" version = "0.0.11" description = "CDP Agentkit Langchain Extension" authors = ["John Peterson "] -readme = "../README.md" +readme = "README.md" license = "Apache-2.0" keywords = ["coinbase", "sdk", "crypto", "cdp", "agentkit", "ai", "agent", "langchain", "toolkit"] packages = [{ include = "cdp_langchain" }] diff --git a/twitter-langchain/python/README.md b/twitter-langchain/python/README.md new file mode 100644 index 00000000..f1db4afb --- /dev/null +++ b/twitter-langchain/python/README.md @@ -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= +export TWITTER_API_KEY= +export TWITTER_API_SECRET= +export TWITTER_ACCESS_TOKEN= +export TWITTER_ACCESS_TOKEN_SECRET= +export TWITTER_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. diff --git a/twitter-langchain/python/pyproject.toml b/twitter-langchain/python/pyproject.toml index 24b14085..64a2d8d7 100644 --- a/twitter-langchain/python/pyproject.toml +++ b/twitter-langchain/python/pyproject.toml @@ -4,7 +4,7 @@ version = "0.0.9" description = "Twitter Langchain Toolkit" authors = ["John Peterson "] license = "Apache-2.0" -readme = "../README.md" +readme = "README.md" [tool.poetry.dependencies] python = "^3.10"