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