Skip to content

Commit ed71815

Browse files
authored
Update insight tools and prompts (#5)
1 parent 4a96dc5 commit ed71815

File tree

1 file changed

+27
-100
lines changed
  • python/thirdweb-ai/src/thirdweb_ai/services

1 file changed

+27
-100
lines changed

python/thirdweb-ai/src/thirdweb_ai/services/insight.py

Lines changed: 27 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, secret_key: str, chain_id: int | list[int]):
1212
@tool(
1313
description="Retrieve blockchain events with flexible filtering options. Use this to search for specific events or to analyze event patterns across multiple blocks."
1414
)
15-
def get_events(
15+
def get_all_events(
1616
self,
1717
chain: Annotated[
1818
list[int] | int | None,
@@ -22,10 +22,6 @@ def get_events(
2222
str | None,
2323
"Contract address to filter events by (e.g., '0x1234...'). Only return events emitted by this contract.",
2424
] = None,
25-
decode: Annotated[
26-
bool | None, "Set to True to decode event data into human-readable format using contract ABIs."
27-
] = None,
28-
block_number: Annotated[int | None, "Exact block number to query events from (e.g., 15000000)."] = None,
2925
block_number_gte: Annotated[int | None, "Minimum block number to start querying from (inclusive)."] = None,
3026
block_number_lt: Annotated[int | None, "Maximum block number to query up to (exclusive)."] = None,
3127
transaction_hash: Annotated[
@@ -42,17 +38,21 @@ def get_events(
4238
page: Annotated[
4339
int | None, "Page number for paginated results, starting from 0. Use with limit parameter."
4440
] = None,
41+
sort_order: Annotated[
42+
str | None,
43+
"Sort order for the events. Default is 'desc' for descending order. Use 'asc' for ascending order.",
44+
] = "desc",
4545
) -> dict[str, Any]:
46-
params = {}
46+
params: dict[str, Any] = {
47+
"sort_by": "block_number",
48+
"sort_order": sort_order if sort_order in ["asc", "desc"] else "desc",
49+
"decode": True,
50+
}
4751
chain = chain or self.chain_ids
4852
if chain:
4953
params["chain"] = chain
5054
if address:
5155
params["filter_address"] = address
52-
if decode:
53-
params["decode"] = decode
54-
if block_number:
55-
params["filter_block_number"] = block_number
5656
if block_number_gte:
5757
params["filter_block_number_gte"] = block_number_gte
5858
if block_number_lt:
@@ -79,9 +79,6 @@ def get_contract_events(
7979
list[int] | int | None,
8080
"Chain ID(s) to query (e.g., 1 for Ethereum Mainnet, 137 for Polygon). Specify multiple IDs as a list for cross-chain queries (max 5).",
8181
] = None,
82-
decode: Annotated[
83-
bool | None, "Set to True to decode event data into human-readable format using the contract's ABI."
84-
] = None,
8582
block_number_gte: Annotated[
8683
int | None,
8784
"Only return events from blocks with number greater than or equal to this value. Useful for querying recent history.",
@@ -97,13 +94,19 @@ def get_contract_events(
9794
int | None,
9895
"Page number for paginated results, starting from 0. Use with limit parameter for browsing large result sets.",
9996
] = None,
97+
sort_order: Annotated[
98+
str | None,
99+
"Sort order for the events. Default is 'desc' for descending order. Use 'asc' for ascending order.",
100+
] = "desc",
100101
) -> dict[str, Any]:
101-
params = {}
102+
params: dict[str, Any] = {
103+
"sort_by": "block_number",
104+
"sort_order": sort_order if sort_order in ["asc", "desc"] else "desc",
105+
"decode": True,
106+
}
102107
chain = chain or self.chain_ids
103108
if chain:
104109
params["chain"] = chain
105-
if decode:
106-
params["decode"] = decode
107110
if block_number_gte:
108111
params["filter_block_number_gte"] = block_number_gte
109112
if topic_0:
@@ -114,51 +117,6 @@ def get_contract_events(
114117
params["page"] = page
115118
return self._get(f"events/{contract_address}", params)
116119

117-
@tool(
118-
description="Get events for a specific contract filtered by event signature. Useful for tracking particular event types like Transfers, Approvals, or custom events."
119-
)
120-
def get_contract_events_by_signature(
121-
self,
122-
contract_address: Annotated[
123-
str, "The contract address to query events for (e.g., '0x1234...'). Must be a valid Ethereum address."
124-
],
125-
signature: Annotated[
126-
str,
127-
"Event signature to filter by (e.g., 'Transfer(address,address,uint256)' or the hash '0xddf252ad...'). This determines which type of events to retrieve.",
128-
],
129-
chain: Annotated[
130-
list[int] | int | None,
131-
"Chain ID(s) to query (e.g., 1 for Ethereum, 137 for Polygon). Specify multiple IDs as a list for cross-chain queries.",
132-
] = None,
133-
decode: Annotated[
134-
bool | None,
135-
"Set to True to decode event data into human-readable format. Recommended for easier interpretation.",
136-
] = None,
137-
block_number_gte: Annotated[
138-
int | None,
139-
"Only return events from blocks with number greater than or equal to this value. Useful for recent history.",
140-
] = None,
141-
limit: Annotated[
142-
int | None, "Maximum number of events to return per request. Default is 20, adjust based on your needs."
143-
] = None,
144-
page: Annotated[
145-
int | None, "Page number for paginated results, starting from 0. Use for browsing large result sets."
146-
] = None,
147-
) -> dict[str, Any]:
148-
params = {}
149-
chain = chain or self.chain_ids
150-
if chain:
151-
params["chain"] = chain
152-
if decode:
153-
params["decode"] = decode
154-
if block_number_gte:
155-
params["filter_block_number_gte"] = block_number_gte
156-
if limit:
157-
params["limit"] = limit
158-
if page:
159-
params["page"] = page
160-
return self._get(f"events/{contract_address}/{signature}", params)
161-
162120
@tool(
163121
description="Retrieve blockchain transactions with flexible filtering options. Use this to analyze transaction patterns, track specific transactions, or monitor wallet activity."
164122
)
@@ -180,10 +138,6 @@ def get_all_transactions(
180138
str | None,
181139
"Filter by function selector (e.g., '0x095ea7b3' for the approve function). Useful for finding specific contract interactions.",
182140
] = None,
183-
decode: Annotated[
184-
bool,
185-
"Set to True to decode transaction input data using contract ABIs. Makes contract interactions human-readable.",
186-
] = True,
187141
sort_order: Annotated[
188142
str | None,
189143
"Sort order for the transactions. Default is 'asc' for ascending order. Use 'desc' for descending order.",
@@ -198,8 +152,9 @@ def get_all_transactions(
198152
] = None,
199153
) -> dict[str, Any]:
200154
params: dict[str, Any] = {
201-
"sort_by": "block_timestamp",
155+
"sort_by": "block_number",
202156
"sort_order": sort_order if sort_order in ["asc", "desc"] else "desc",
157+
"decode": True,
203158
}
204159
chain = chain or self.chain_ids
205160
if chain:
@@ -210,8 +165,6 @@ def get_all_transactions(
210165
params["filter_to_address"] = to_address
211166
if function_selector:
212167
params["filter_function_selector"] = function_selector
213-
if decode:
214-
params["decode"] = decode
215168
if limit:
216169
params["limit"] = limit
217170
if page:
@@ -313,53 +266,27 @@ def get_erc1155_tokens(
313266
return self._get(f"tokens/erc1155/{owner_address}", params)
314267

315268
@tool(
316-
description="Get current market prices for specified tokens. Useful for valuation, tracking portfolio value, or monitoring price changes."
269+
description="Get current market prices for native and ERC20 tokens. Useful for valuation, tracking portfolio value, or monitoring price changes."
317270
)
318271
def get_token_prices(
319272
self,
320273
token_addresses: Annotated[
321274
list[str],
322-
"List of token contract addresses to get prices for (e.g., ['0x1234...', '0x5678...']). Can include ERC20 tokens.",
275+
"List of token contract addresses to get prices for (e.g., ['0x1234...', '0x5678...']). Can include ERC20 tokens. Use '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' for native tokens (ETH, POL, MATIC, etc.).",
323276
],
324277
chain: Annotated[
325278
list[int] | int | None,
326279
"Chain ID(s) where the tokens exist (e.g., 1 for Ethereum, 137 for Polygon). Must match the token network.",
327280
] = None,
328-
currencies: Annotated[
329-
list[str] | None,
330-
"List of currencies to return prices in (e.g., ['usd', 'eth']). Default is USD if not specified.",
331-
] = None,
332281
) -> dict[str, Any]:
333-
params: dict[str, Any] = {"token_addresses": token_addresses}
282+
params: dict[str, Any] = {"address": token_addresses}
334283
chain = chain or self.chain_ids
335284
if chain:
336285
params["chain"] = chain
337-
if currencies:
338-
params["currencies"] = currencies
339286
return self._get("tokens/price", params)
340287

341288
@tool(
342-
description="Retrieve the Application Binary Interface (ABI) for a smart contract. Essential for decoding contract data and interacting with the contract."
343-
)
344-
def get_contract_abi(
345-
self,
346-
contract_address: Annotated[
347-
str,
348-
"The contract address to get the ABI for (e.g., '0x1234...'). Must be a deployed and verified contract.",
349-
],
350-
chain: Annotated[
351-
list[int] | int | None,
352-
"Chain ID(s) where the contract is deployed (e.g., 1 for Ethereum). Specify the correct network.",
353-
] = None,
354-
) -> dict[str, Any]:
355-
params = {}
356-
chain = chain or self.chain_ids
357-
if chain:
358-
params["chain"] = chain
359-
return self._get(f"contracts/abi/{contract_address}", params)
360-
361-
@tool(
362-
description="Get metadata about a smart contract, including name, symbol, decimals, and other contract-specific information."
289+
description="Get contract ABI and metadata about a smart contract, including name, symbol, decimals, and other contract-specific information. This tool also retrieve the Application Binary Interface (ABI) for a smart contract. Essential for decoding contract data and interacting with the contract"
363290
)
364291
def get_contract_metadata(
365292
self,
@@ -489,13 +416,13 @@ def get_nft_transfers(
489416
return self._get(f"nfts/transfers/{contract_address}", params)
490417

491418
@tool(
492-
description="Resolve ENS names to Ethereum addresses or vice versa. Useful for working with human-readable names instead of addresses."
419+
description="Search and analyze blockchain input data: block number, transaction or block hash, wallet or contract address, event signature or function selector. It returns a detailed analyzed information about the input data."
493420
)
494421
def resolve(
495422
self,
496423
input_data: Annotated[
497424
str,
498-
"The ENS name (e.g., 'thirdweb.eth') or address (e.g., '0x1234...') to resolve. Works in both directions.",
425+
"Any blockchain input data: block number, transaction or block hash, address, event signature or function selector",
499426
],
500427
chain: Annotated[
501428
list[int] | int | None,

0 commit comments

Comments
 (0)