Skip to content

Commit b76ed93

Browse files
authored
CDP Knowledge Base
CDP Knowledge Base
2 parents c6e39cc + c30d328 commit b76ed93

12 files changed

+2963
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
This prompt is used to show how to add agent functionality to a Python-based AgentKit:
2+
3+
4+
I want to add a new action to my Langchain toolkit. Here's what I need you to do:
5+
6+
1. I'll provide you with a description of the action I want to implement
7+
8+
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
9+
10+
3. The code should follow the patterns shown in these examples:
11+
12+
Import the following files:
13+
14+
from cdp import Wallet
15+
from cdp_langchain.tools import CdpTool
16+
17+
18+
Action file structure:
19+
20+
```python
21+
22+
DESCRIPTIVE_PROMPT = """
23+
24+
Description of what this action does and when to use it.
25+
26+
"""
27+
28+
class ActionInput(BaseModel):
29+
30+
parameter1: str = Field(
31+
32+
description="Description of parameter1",
33+
34+
example="Example value"
35+
)
36+
def my_custom_action(parameter1: str) -> str:
37+
38+
"""
39+
Docstring describing the action.
40+
Args:
41+
parameter1: Description
42+
Returns:
43+
str: Description of return value
44+
"""
45+
# Implementation
46+
47+
return result
48+
49+
```
50+
51+
signMessageTool = CdpTool(
52+
name="my_custom_action",
53+
description=DESCRIPTIVE_PROMPT,
54+
cdp_agentkit_wrapper=cdp_agentkit_wrapper, # this should be whatever the instantiation of CdpAgentkitWrapper is, typically `agentkit`
55+
args_schema=ActionInput,
56+
func=my_custom_action,
57+
)
58+
59+
Here's an example of what this looks like for adding message signing using the Coinbase Developer Platform SDK:
60+
61+
# Define a custom action example.
62+
63+
SIGN_MESSAGE_PROMPT = """
64+
This tool will sign arbitrary messages using EIP-191 Signed Message Standard hashing.
65+
"""
66+
67+
class SignMessageInput(BaseModel):
68+
"""Input argument schema for sign message action."""
69+
70+
message: str = Field(
71+
...,
72+
description="The message to sign. e.g. `hello world`"
73+
)
74+
75+
def sign_message(wallet: Wallet, message: str) -> str: # note that wallets is an object, it should not be in quotes
76+
"""Sign message using EIP-191 message hash from the wallet.
77+
78+
Args:
79+
wallet (Wallet): The wallet to sign the message from.
80+
message (str): The message to hash and sign.
81+
82+
Returns:
83+
str: The message and corresponding signature.
84+
85+
"""
86+
payload_signature = wallet.sign_payload(hash_message(message)).wait()
87+
88+
return f"The payload signature {payload_signature}"
89+
90+
91+
signMessageTool = CdpTool(
92+
name="sign_message",
93+
description=SIGN_MESSAGE_PROMPT,
94+
cdp_agentkit_wrapper=agentkit, # this should be whatever the instantiation of CdpAgentkitWrapper is
95+
args_schema=SignMessageInput,
96+
func=sign_message,
97+
)
98+
99+
tools.append(signMessageTool)
100+
101+
Remember to:
102+
103+
- Include proper type hints
104+
105+
- Add detailed docstrings
106+
107+
- Include Field descriptions and examples in the Pydantic model
108+
109+
- Follow existing naming conventions
110+
111+
- Provide clear implementation details
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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

info-for-ai/agentkit.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Common questions:
2+
3+
1. How do I change the network?
4+
There is a environment variable called "NETWORK_ID" that you can use to change the network. If you do so, you should also change where the wallet file is saved to something else.

info-for-ai/commerce.md

Whitespace-only changes.

info-for-ai/onchainkit.md

Whitespace-only changes.

0 commit comments

Comments
 (0)