From e55b25c4fe8b736a80aedf168370783913a98901 Mon Sep 17 00:00:00 2001 From: John Peterson <98187317+John-peterson-coinbase@users.noreply.github.com> Date: Sat, 7 Dec 2024 11:57:43 -0500 Subject: [PATCH] fix: cdp-langchain README quickstart code samples (#24) --- cdp-langchain/README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cdp-langchain/README.md b/cdp-langchain/README.md index b34b756..a8c3c2e 100644 --- a/cdp-langchain/README.md +++ b/cdp-langchain/README.md @@ -33,10 +33,10 @@ export NETWORK_ID=base-sepolia # Optional: Defaults to base-sepolia ```typescript import { CdpToolkit } from "@coinbase/cdp-langchain"; -import { CdpAgentKit } from "@coinbase/cdp-agentkit-core"; +import { CdpAgentkit } from "@coinbase/cdp-agentkit-core"; // Initialize CDP AgentKit -const agentkit = CdpAgentKit.configureWithWallet(); +const agentkit = await CdpAgentkit.configureWithWallet(); // Create toolkit const toolkit = new CdpToolkit(agentkit); @@ -66,7 +66,8 @@ The toolkit provides the following tools: ```typescript import { ChatOpenAI } from "@langchain/openai"; -import { initializeAgentExecutorWithOptions } from "langchain/agents"; +import { HumanMessage } from "@langchain/core/messages"; +import { createReactAgent } from "@langchain/langgraph/prebuilt"; // Initialize LLM const model = new ChatOpenAI({ @@ -74,17 +75,17 @@ const model = new ChatOpenAI({ }); // Create agent executor -const executor = await initializeAgentExecutorWithOptions(toolkit.getTools(), model, { - agentType: "chat-conversational-react-description", - verbose: true, +const agent = createReactAgent({ + llm: model, + tools, }); // Example usage -const result = await executor.invoke({ - input: "Send 0.005 ETH to john2879.base.eth", +const result = await agent.invoke({ + messages: [new HumanMessage("Send 0.005 ETH to john2879.base.eth")], }); -console.log(result.output); +console.log(result.messages[result.messages.length - 1].content); ``` ## CDP Toolkit Specific Features @@ -98,7 +99,7 @@ The toolkit maintains an MPC wallet that persists between sessions: const walletData = await agentkit.exportWallet(); // Import wallet data -const importedAgentKit = CdpAgentKit.configureWithWallet({ cdpWalletData: walletData }); +const importedAgentkit = await CdpAgentkit.configureWithWallet({ cdpWalletData: walletData }); ``` ### Network Support