Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cdp-langchain README quickstart code samples #24

Merged
merged 1 commit into from
Dec 7, 2024
Merged
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
21 changes: 11 additions & 10 deletions cdp-langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -66,25 +66,26 @@ 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({
model: "gpt-4o-mini",
});

// 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
Expand All @@ -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
Expand Down
Loading