forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.ts
72 lines (71 loc) · 2.21 KB
/
query.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import {
elizaLogger,
type Action,
type ActionExample,
type HandlerCallback,
type IAgentRuntime,
type Memory,
type State,
} from "@elizaos/core";
import { validateAsteraiConfig } from "../environment";
import {getInitAsteraiClient} from "../index.ts";
export const queryAction = {
name: "QUERY_ASTERAI_AGENT",
similes: [
"MESSAGE_ASTERAI_AGENT",
"TALK_TO_ASTERAI_AGENT",
"SEND_MESSAGE_TO_ASTERAI_AGENT",
"COMMUNICATE_WITH_ASTERAI_AGENT",
],
description:
"Call this action to send a message to the asterai agent which " +
"has access to external plugins and functionality to answer " +
"the user you are assisting, to help perform a workflow task, etc.",
validate: async (runtime: IAgentRuntime, _message: Memory) => {
const config = await validateAsteraiConfig(runtime);
getInitAsteraiClient(
config.ASTERAI_AGENT_ID,
config.ASTERAI_PUBLIC_QUERY_KEY
);
return true;
},
handler: async (
runtime: IAgentRuntime,
message: Memory,
_state: State,
_options: { [key: string]: unknown },
callback?: HandlerCallback
): Promise<boolean> => {
const config = await validateAsteraiConfig(runtime);
const asteraiClient = getInitAsteraiClient(
config.ASTERAI_AGENT_ID,
config.ASTERAI_PUBLIC_QUERY_KEY
);
elizaLogger.debug("called QUERY_ASTERAI_AGENT action with message:", message.content);
const response = await asteraiClient.query({
query: message.content.text
});
const textResponse = await response.text();
callback({
text: textResponse
});
return true;
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "How's the weather in LA?",
},
},
{
user: "{{user2}}",
content: {
text: "Let me check that for you, just a moment.",
action: "QUERY_ASTERAI_AGENT",
},
},
],
] as ActionExample[][],
} as Action;