|
| 1 | +This prompt is used to show how to add agent functionality to a Typescript-based AgentKit: |
| 2 | + |
| 3 | +I want to add a new action to my Langchain toolkit. Here's what I need you to do: |
| 4 | + |
| 5 | +1. I'll provide you with a description of the action I want to implement |
| 6 | + |
| 7 | +2. Using the structure I define below supplemented by an example for adding toolkit actions, please generate ALL the required code and file changes needed |
| 8 | + |
| 9 | +3. The code should follow the patterns shown in these examples: |
| 10 | + |
| 11 | +Required Imports |
| 12 | +```typescript |
| 13 | +import { Wallet } from "@coinbase/coinbase-sdk"; |
| 14 | +import { CdpWrapper } from "@coinbase/cdp-agentkit-core"; |
| 15 | +import { CdpTool } from "@coinbase/cdp-langchain"; |
| 16 | +import { z } from "zod"; |
| 17 | +``` |
| 18 | +Action file structure: |
| 19 | +```typescript |
| 20 | +// Define the action's descriptive prompt |
| 21 | +const DESCRIPTIVE_PROMPT = ` |
| 22 | +Detailed description of what this action does and when to use it. |
| 23 | +`; |
| 24 | + |
| 25 | +// Define the input schema using Zod |
| 26 | +const ActionInput = z.object({ |
| 27 | + parameter1: z.string().describe("Description of parameter1. e.g. 'Example value'"), |
| 28 | +}); |
| 29 | + |
| 30 | +/** |
| 31 | + * Brief description of what the action does |
| 32 | + * |
| 33 | + * @param wallet - Description of the wallet parameter |
| 34 | + * @param parameter1 - Description of parameter1 |
| 35 | + * @returns Description of what the function returns |
| 36 | + */ |
| 37 | +async function myCustomAction(wallet: Wallet, parameter1: string): Promise<string> { |
| 38 | + // Implementation |
| 39 | + return result; |
| 40 | +} |
| 41 | + |
| 42 | +// Create the CdpTool instance |
| 43 | +const myCustomActionTool = new CdpTool( |
| 44 | + { |
| 45 | + name: "my_custom_action", |
| 46 | + description: DESCRIPTIVE_PROMPT, |
| 47 | + argsSchema: ActionInput, |
| 48 | + func: myCustomAction |
| 49 | + }, |
| 50 | + agentkit // this should be whatever the instantiation of CdpWrapper is |
| 51 | +); |
| 52 | + |
| 53 | +// Add the tool to your toolkit |
| 54 | +tools.push(myCustomActionTool); |
| 55 | + |
| 56 | +``` |
| 57 | + |
| 58 | +Here's a concrete example of implementing a message signing action: |
| 59 | +```typescript |
| 60 | +import { Wallet, hashMessage } from "@coinbase/coinbase-sdk"; |
| 61 | +import { CdpTool } from "@coinbase/cdp-langchain"; |
| 62 | +import { z } from "zod"; |
| 63 | + |
| 64 | +// Define the prompt for the sign message action |
| 65 | +const SIGN_MESSAGE_PROMPT = ` |
| 66 | +This tool will sign arbitrary messages using EIP-191 Signed Message Standard hashing. |
| 67 | +`; |
| 68 | + |
| 69 | +// Define the input schema using Zod |
| 70 | +const SignMessageInput = z.object({ |
| 71 | + message: z.string().describe("The message to sign. e.g. `hello world`"), |
| 72 | +}); |
| 73 | + |
| 74 | +/** |
| 75 | + * Signs a message using EIP-191 message hash from the wallet |
| 76 | + * |
| 77 | + * @param wallet - The wallet to sign the message from |
| 78 | + * @param message - The message to hash and sign |
| 79 | + * @returns The message and corresponding signature |
| 80 | + */ |
| 81 | +async function signMessage(wallet: Wallet, message: string): Promise<string> { |
| 82 | + const payloadSignature = await wallet.createPayloadSignature(hashMessage(message)); |
| 83 | + return `The payload signature ${payloadSignature}`; |
| 84 | +} |
| 85 | + |
| 86 | +const signMessageTool = new CdpTool( |
| 87 | + { |
| 88 | + name: "sign_message", |
| 89 | + description: SIGN_MESSAGE_PROMPT, |
| 90 | + argsSchema: SignMessageInput, |
| 91 | + func: signMessage |
| 92 | + }, |
| 93 | + agentkit |
| 94 | +); |
| 95 | + |
| 96 | +tools.push(signMessageTool); |
| 97 | +``` |
| 98 | + |
| 99 | +Important Reminders: |
| 100 | + |
| 101 | +Use proper TypeScript type annotations |
| 102 | +Include detailed JSDoc comments with @param and @return tags |
| 103 | +Define clear Zod schemas with descriptions and examples |
| 104 | +Follow TypeScript naming conventions (camelCase for functions/variables, PascalCase for types) |
| 105 | +Make functions async when dealing with wallet operations |
| 106 | +Provide clear implementation details and error handling where appropriate |
| 107 | +Use TypeScript's built-in Promise type for async operations |
0 commit comments