|
| 1 | +import { sendMetric, type ResponseMetricTags } from "@helpers/datadog"; |
| 2 | +import { Agent, type XmtpEnv } from "@helpers/versions"; |
| 3 | +import { setupDurationTracking } from "@helpers/vitest"; |
| 4 | +import { ActionsCodec } from "agents/utils/inline-actions/types/ActionsContent"; |
| 5 | +import { IntentCodec } from "agents/utils/inline-actions/types/IntentContent"; |
| 6 | +import { describe, it } from "vitest"; |
| 7 | +import productionAgents from "./agents"; |
| 8 | +import { |
| 9 | + AGENT_RESPONSE_TIMEOUT, |
| 10 | + waitForResponse, |
| 11 | + type AgentConfig, |
| 12 | +} from "./helper"; |
| 13 | + |
| 14 | +const testName = "agents-stress"; |
| 15 | + |
| 16 | +describe(testName, () => { |
| 17 | + setupDurationTracking({ testName, initDataDog: true }); |
| 18 | + const env = process.env.XMTP_ENV as XmtpEnv; |
| 19 | + const filteredAgents = productionAgents.filter((agent) => |
| 20 | + agent.networks.includes(env), |
| 21 | + ); |
| 22 | + |
| 23 | + const createMetricTags = (agentConfig: AgentConfig): ResponseMetricTags => ({ |
| 24 | + test: testName, |
| 25 | + metric_type: "agent", |
| 26 | + metric_subtype: "stress", |
| 27 | + live: agentConfig.live ? "true" : "false", |
| 28 | + agent: agentConfig.name, |
| 29 | + address: agentConfig.address, |
| 30 | + sdk: "", |
| 31 | + }); |
| 32 | + |
| 33 | + for (const agentConfig of filteredAgents) { |
| 34 | + it(`${testName}: ${agentConfig.name} Stress : ${agentConfig.address}`, async () => { |
| 35 | + const agent = await Agent.createFromEnv({ |
| 36 | + codecs: [new ActionsCodec(), new IntentCodec()], |
| 37 | + }); |
| 38 | + |
| 39 | + try { |
| 40 | + const conversation = await agent.createDmWithAddress( |
| 41 | + agentConfig.address as `0x${string}`, |
| 42 | + ); |
| 43 | + |
| 44 | + console.log( |
| 45 | + `📤 Sending "${agentConfig.sendMessage}" to ${agentConfig.name} (${agentConfig.address})`, |
| 46 | + ); |
| 47 | + |
| 48 | + const result = await waitForResponse({ |
| 49 | + client: agent.client as any, |
| 50 | + conversation: { |
| 51 | + send: (content: string) => conversation.send(content), |
| 52 | + }, |
| 53 | + conversationId: conversation.id, |
| 54 | + senderInboxId: agent.client.inboxId, |
| 55 | + timeout: AGENT_RESPONSE_TIMEOUT, |
| 56 | + messageText: agentConfig.sendMessage, |
| 57 | + }); |
| 58 | + |
| 59 | + const responseTime = Math.max(result.responseTime || 0, 0.0001); |
| 60 | + sendMetric("response", responseTime, createMetricTags(agentConfig)); |
| 61 | + |
| 62 | + if (result.success && result.responseMessage) |
| 63 | + console.log( |
| 64 | + `✅ ${agentConfig.name} responded in ${responseTime.toFixed(2)}ms`, |
| 65 | + ); |
| 66 | + else |
| 67 | + console.error(`❌ ${agentConfig.name} - NO RESPONSE within timeout`); |
| 68 | + } finally { |
| 69 | + await agent.stop(); |
| 70 | + } |
| 71 | + }); |
| 72 | + } |
| 73 | +}); |
0 commit comments