Skip to content

Commit 88d7a8b

Browse files
use llms parsing for getTransaction
Signed-off-by: Agustín Ramiro Díaz <agustin.ramiro.diaz@gmail.com>
1 parent 3d1e65d commit 88d7a8b

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

packages/plugin-genlayer/src/actions/getTransaction.ts

+39-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,33 @@ import {
33
HandlerCallback,
44
IAgentRuntime,
55
Memory,
6+
State,
67
elizaLogger,
78
} from "@ai16z/eliza";
89
import { TransactionHash } from "genlayer-js/types";
910
import { ClientProvider } from "../providers/client";
11+
import { getParamsWithLLM } from "../utils/llm";
12+
13+
const getTransactionTemplate = `
14+
# Task: Extract the transaction hash from the user's message.
15+
16+
# Instructions: The user is requesting transaction details from the GenLayer protocol.
17+
18+
<latest user message>
19+
{{userMessage}}
20+
</latest user message>
21+
22+
<data from recent messages>
23+
{{recentMessagesData}}
24+
</data from recent messages>
25+
26+
# Your response must be formatted as a JSON block with this structure:
27+
\`\`\`json
28+
{
29+
"hash": "<Transaction Hash>"
30+
}
31+
\`\`\`
32+
`;
1033

1134
export const getTransactionAction: Action = {
1235
name: "GET_TRANSACTION",
@@ -19,26 +42,36 @@ export const getTransactionAction: Action = {
1942
handler: async (
2043
runtime: IAgentRuntime,
2144
message: Memory,
22-
_state: any,
45+
state: State,
2346
_options: any,
2447
callback: HandlerCallback
2548
) => {
2649
elizaLogger.info("Starting get transaction action");
2750
elizaLogger.debug("User message:", message.content.text);
2851

2952
const clientProvider = new ClientProvider(runtime);
30-
// Extract transaction hash from message
31-
const hashMatch = message.content.text.match(/0x[a-fA-F0-9]{64}/);
32-
if (!hashMatch) {
53+
54+
const options = await getParamsWithLLM<{ hash: TransactionHash }>(
55+
runtime,
56+
message,
57+
getTransactionTemplate,
58+
state
59+
);
60+
61+
if (
62+
!options ||
63+
!options.hash ||
64+
!/^0x[a-fA-F0-9]{64}$/.test(options.hash)
65+
) {
3366
elizaLogger.error("No valid transaction hash found in message");
3467
throw new Error("No valid transaction hash found in message");
3568
}
3669

3770
elizaLogger.info(
38-
`Getting transaction details for hash: ${hashMatch[0]}`
71+
`Getting transaction details for hash: ${options.hash}`
3972
);
4073
const result = await clientProvider.client.getTransaction({
41-
hash: hashMatch[0] as TransactionHash,
74+
hash: options.hash,
4275
});
4376

4477
elizaLogger.success("Successfully retrieved transaction details");

packages/plugin-genlayer/src/utils/llm.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export async function getParamsWithLLM<T>(
1212
runtime: IAgentRuntime,
1313
message: Memory,
1414
template: string,
15+
state: State = null,
1516
maxAttempts: number = 5
1617
): Promise<T | null> {
1718
const context = composeContext({
1819
state: {
20+
...state,
1921
userMessage: message.content.text,
20-
} as unknown as State,
22+
},
2123
template,
2224
});
2325

0 commit comments

Comments
 (0)