@itachisol/plugin-x402-swarms 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +323 -0
- package/dist/actions/delegateToSwarm.d.ts +8 -0
- package/dist/actions/delegateToSwarm.d.ts.map +1 -0
- package/dist/actions/delegateToSwarm.js +296 -0
- package/dist/actions/delegateToSwarm.js.map +1 -0
- package/dist/actions/delegateToSwarmWithPayment.d.ts +8 -0
- package/dist/actions/delegateToSwarmWithPayment.d.ts.map +1 -0
- package/dist/actions/delegateToSwarmWithPayment.js +323 -0
- package/dist/actions/delegateToSwarmWithPayment.js.map +1 -0
- package/dist/actions/discoverServices.d.ts +3 -0
- package/dist/actions/discoverServices.d.ts.map +1 -0
- package/dist/actions/discoverServices.js +63 -0
- package/dist/actions/discoverServices.js.map +1 -0
- package/dist/actions/index.d.ts +6 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +6 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/payForService.d.ts +3 -0
- package/dist/actions/payForService.d.ts.map +1 -0
- package/dist/actions/payForService.js +115 -0
- package/dist/actions/payForService.js.map +1 -0
- package/dist/actions/runSwarmAgent.d.ts +7 -0
- package/dist/actions/runSwarmAgent.d.ts.map +1 -0
- package/dist/actions/runSwarmAgent.js +131 -0
- package/dist/actions/runSwarmAgent.js.map +1 -0
- package/dist/client/index.d.ts +512 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +469 -0
- package/dist/client/index.js.map +1 -0
- package/dist/evaluators/paymentEvaluator.d.ts +7 -0
- package/dist/evaluators/paymentEvaluator.d.ts.map +1 -0
- package/dist/evaluators/paymentEvaluator.js +104 -0
- package/dist/evaluators/paymentEvaluator.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/marketing/index.d.ts +7 -0
- package/dist/marketing/index.d.ts.map +1 -0
- package/dist/marketing/index.js +7 -0
- package/dist/marketing/index.js.map +1 -0
- package/dist/marketing/milestoneAgent.d.ts +54 -0
- package/dist/marketing/milestoneAgent.d.ts.map +1 -0
- package/dist/marketing/milestoneAgent.js +121 -0
- package/dist/marketing/milestoneAgent.js.map +1 -0
- package/dist/marketing/tweetTemplates.d.ts +32 -0
- package/dist/marketing/tweetTemplates.d.ts.map +1 -0
- package/dist/marketing/tweetTemplates.js +60 -0
- package/dist/marketing/tweetTemplates.js.map +1 -0
- package/dist/marketing/xMonitor.d.ts +51 -0
- package/dist/marketing/xMonitor.d.ts.map +1 -0
- package/dist/marketing/xMonitor.js +141 -0
- package/dist/marketing/xMonitor.js.map +1 -0
- package/dist/providers/x402Provider.d.ts +7 -0
- package/dist/providers/x402Provider.d.ts.map +1 -0
- package/dist/providers/x402Provider.js +72 -0
- package/dist/providers/x402Provider.js.map +1 -0
- package/dist/providers/x402ServerProvider.d.ts +7 -0
- package/dist/providers/x402ServerProvider.d.ts.map +1 -0
- package/dist/providers/x402ServerProvider.js +48 -0
- package/dist/providers/x402ServerProvider.js.map +1 -0
- package/dist/routes/advancedRoutes.d.ts +5 -0
- package/dist/routes/advancedRoutes.d.ts.map +1 -0
- package/dist/routes/advancedRoutes.js +869 -0
- package/dist/routes/advancedRoutes.js.map +1 -0
- package/dist/routes/batchRoutes.d.ts +13 -0
- package/dist/routes/batchRoutes.d.ts.map +1 -0
- package/dist/routes/batchRoutes.js +496 -0
- package/dist/routes/batchRoutes.js.map +1 -0
- package/dist/routes/codeAuditRoutes.d.ts +6 -0
- package/dist/routes/codeAuditRoutes.d.ts.map +1 -0
- package/dist/routes/codeAuditRoutes.js +415 -0
- package/dist/routes/codeAuditRoutes.js.map +1 -0
- package/dist/routes/contentRoutes.d.ts +5 -0
- package/dist/routes/contentRoutes.d.ts.map +1 -0
- package/dist/routes/contentRoutes.js +370 -0
- package/dist/routes/contentRoutes.js.map +1 -0
- package/dist/routes/cryptoAnalysisRoutes.d.ts +5 -0
- package/dist/routes/cryptoAnalysisRoutes.d.ts.map +1 -0
- package/dist/routes/cryptoAnalysisRoutes.js +641 -0
- package/dist/routes/cryptoAnalysisRoutes.js.map +1 -0
- package/dist/routes/cryptoRoutes.d.ts +5 -0
- package/dist/routes/cryptoRoutes.d.ts.map +1 -0
- package/dist/routes/cryptoRoutes.js +1225 -0
- package/dist/routes/cryptoRoutes.js.map +1 -0
- package/dist/routes/heliusDataRoutes.d.ts +14 -0
- package/dist/routes/heliusDataRoutes.d.ts.map +1 -0
- package/dist/routes/heliusDataRoutes.js +388 -0
- package/dist/routes/heliusDataRoutes.js.map +1 -0
- package/dist/routes/taskRoutes.d.ts +5 -0
- package/dist/routes/taskRoutes.d.ts.map +1 -0
- package/dist/routes/taskRoutes.js +574 -0
- package/dist/routes/taskRoutes.js.map +1 -0
- package/dist/routes/tradingRoutes.d.ts +5 -0
- package/dist/routes/tradingRoutes.d.ts.map +1 -0
- package/dist/routes/tradingRoutes.js +500 -0
- package/dist/routes/tradingRoutes.js.map +1 -0
- package/dist/routes/walletAnalyzerRoutes.d.ts +12 -0
- package/dist/routes/walletAnalyzerRoutes.d.ts.map +1 -0
- package/dist/routes/walletAnalyzerRoutes.js +316 -0
- package/dist/routes/walletAnalyzerRoutes.js.map +1 -0
- package/dist/routes/x402Routes.d.ts +9 -0
- package/dist/routes/x402Routes.d.ts.map +1 -0
- package/dist/routes/x402Routes.js +474 -0
- package/dist/routes/x402Routes.js.map +1 -0
- package/dist/schemas/budgetState.d.ts +250 -0
- package/dist/schemas/budgetState.d.ts.map +1 -0
- package/dist/schemas/budgetState.js +20 -0
- package/dist/schemas/budgetState.js.map +1 -0
- package/dist/schemas/endpointScores.d.ts +182 -0
- package/dist/schemas/endpointScores.d.ts.map +1 -0
- package/dist/schemas/endpointScores.js +17 -0
- package/dist/schemas/endpointScores.js.map +1 -0
- package/dist/schemas/index.d.ts +4 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +4 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/paymentHistory.d.ts +284 -0
- package/dist/schemas/paymentHistory.d.ts.map +1 -0
- package/dist/schemas/paymentHistory.js +24 -0
- package/dist/schemas/paymentHistory.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/x402Gate.d.ts +56 -0
- package/dist/server/x402Gate.d.ts.map +1 -0
- package/dist/server/x402Gate.js +240 -0
- package/dist/server/x402Gate.js.map +1 -0
- package/dist/server/x402ServerService.d.ts +30 -0
- package/dist/server/x402ServerService.d.ts.map +1 -0
- package/dist/server/x402ServerService.js +79 -0
- package/dist/server/x402ServerService.js.map +1 -0
- package/dist/services/paymentMemoryService.d.ts +73 -0
- package/dist/services/paymentMemoryService.d.ts.map +1 -0
- package/dist/services/paymentMemoryService.js +247 -0
- package/dist/services/paymentMemoryService.js.map +1 -0
- package/dist/services/swarmsService.d.ts +66 -0
- package/dist/services/swarmsService.d.ts.map +1 -0
- package/dist/services/swarmsService.js +102 -0
- package/dist/services/swarmsService.js.map +1 -0
- package/dist/services/x402WalletService.d.ts +57 -0
- package/dist/services/x402WalletService.d.ts.map +1 -0
- package/dist/services/x402WalletService.js +258 -0
- package/dist/services/x402WalletService.js.map +1 -0
- package/dist/templates/index.d.ts +24 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +51 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/swarmTemplates.d.ts +22 -0
- package/dist/templates/swarmTemplates.d.ts.map +1 -0
- package/dist/templates/swarmTemplates.js +225 -0
- package/dist/templates/swarmTemplates.js.map +1 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/cache.d.ts +17 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +32 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/llm.d.ts +16 -0
- package/dist/utils/llm.d.ts.map +1 -0
- package/dist/utils/llm.js +32 -0
- package/dist/utils/llm.js.map +1 -0
- package/dist/utils/reportStore.d.ts +45 -0
- package/dist/utils/reportStore.d.ts.map +1 -0
- package/dist/utils/reportStore.js +164 -0
- package/dist/utils/reportStore.js.map +1 -0
- package/dist/utils/taskQueue.d.ts +54 -0
- package/dist/utils/taskQueue.d.ts.map +1 -0
- package/dist/utils/taskQueue.js +124 -0
- package/dist/utils/taskQueue.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ItachiDevv
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# SwarmX (@elizaos/plugin-x402-swarms)
|
|
2
|
+
|
|
3
|
+
ElizaOS v2 plugin that gives AI agents the ability to **pay for APIs** using the [x402 HTTP payment protocol](https://www.x402.org/) via the [Dexter SDK](https://dexter.cash/) and **orchestrate multi-agent tasks** using [Swarms](https://swarms.world/) — settled in USDC across 5 networks (Base, Ethereum, Solana, Polygon, Arbitrum).
|
|
4
|
+
|
|
5
|
+
## What This Enables
|
|
6
|
+
|
|
7
|
+
- **Hire AI agent teams** — code review (3 agents), research (3 agents), multi-angle analysis (4 agents), debate (3 agents) — one API call, one USDC payment
|
|
8
|
+
- **Consume paid APIs autonomously** — agent detects HTTP 402, pays with USDC via Dexter SDK, retries automatically
|
|
9
|
+
- **Discover x402 services** — browse the [OpenDexter marketplace](https://dexter.cash/opendexter) of pay-per-call AI/data APIs
|
|
10
|
+
- **Delegate to Swarms** — route complex tasks to multi-agent systems (15+ architectures) via the Swarms cloud API
|
|
11
|
+
- **Delegate with x402 data** — combine x402 data fetching with swarm analysis in a single action
|
|
12
|
+
- **Run single agents** — execute focused tasks with a specific agent role via Swarms
|
|
13
|
+
- **Sell agent services** — expose your agent's capabilities as x402-gated HTTP endpoints
|
|
14
|
+
- **Budget controls** — per-request, per-hour, and total session spending limits with persistent DB state
|
|
15
|
+
- **Access Passes** — time-limited unlimited access for frequently-used endpoints
|
|
16
|
+
|
|
17
|
+
## Featured Endpoints
|
|
18
|
+
|
|
19
|
+
| Endpoint | Team | Agents | Price | What You Get |
|
|
20
|
+
|----------|------|--------|-------|--------------|
|
|
21
|
+
| `POST /x402/code-review` | **Code Review** | Security Auditor + Performance Reviewer + Style Checker | $0.03 | Three specialists audit your code in parallel — security, performance, and style — merged into one report |
|
|
22
|
+
| `POST /x402/research` | **Deep Research** | Researcher → Fact Checker → Writer | $0.05 | A pipeline that investigates any topic, verifies claims, and delivers a polished report |
|
|
23
|
+
| `POST /x402/analyze` | **Multi-Angle Analysis** | Technical + Economic + Risk → Synthesizer | $0.03 | Four domain experts analyze your topic from every angle, then synthesize actionable intelligence |
|
|
24
|
+
| `POST /x402/debate` | **Debate & Decide** | Proponent + Opponent + Judge | $0.03 | Two agents argue opposing sides while a neutral judge weighs evidence and delivers a verdict |
|
|
25
|
+
|
|
26
|
+
All endpoints accept JSON via HTTP POST and settle payments in USDC via the x402 protocol. 3 free calls/day — no wallet needed to start.
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full system diagram.
|
|
31
|
+
|
|
32
|
+
See [docs/TOKENOMICS.md](docs/TOKENOMICS.md) for the economic model.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### 1. Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
bun add @elizaos/plugin-x402-swarms
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Configure
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
cp .env.example .env
|
|
46
|
+
# Fill in: EVM_PRIVATE_KEY (or SOLANA_PRIVATE_KEY), OPENAI_API_KEY (or ANTHROPIC_API_KEY)
|
|
47
|
+
# Optional: SWARMS_API_KEY for multi-agent features
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 3. Add to Your Agent (ElizaOS v2)
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import type { Project, ProjectAgent } from "@elizaos/core";
|
|
54
|
+
import { x402SwarmsPlugin } from "@elizaos/plugin-x402-swarms";
|
|
55
|
+
|
|
56
|
+
const character = {
|
|
57
|
+
name: "PayAgent",
|
|
58
|
+
bio: ["An AI agent that can pay for APIs and orchestrate multi-agent tasks."],
|
|
59
|
+
system: "You are PayAgent. Use DISCOVER_X402_SERVICES to find paid APIs, PAY_FOR_X402_SERVICE to access them, DELEGATE_TO_SWARM for multi-agent tasks, or RUN_SWARM_AGENT for single-agent tasks.",
|
|
60
|
+
plugins: [],
|
|
61
|
+
settings: {
|
|
62
|
+
EVM_PRIVATE_KEY: process.env.EVM_PRIVATE_KEY ?? "",
|
|
63
|
+
X402_NETWORK_ID: "base-sepolia",
|
|
64
|
+
X402_MAX_AUTO_PAY_USD: "0.10",
|
|
65
|
+
X402_BUDGET_USD: "10.00",
|
|
66
|
+
SWARMS_API_KEY: process.env.SWARMS_API_KEY ?? "",
|
|
67
|
+
OPENAI_API_KEY: process.env.OPENAI_API_KEY ?? "",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const agent: ProjectAgent = { character, plugins: [x402SwarmsPlugin] };
|
|
72
|
+
export const project: Project = { agents: [agent] };
|
|
73
|
+
export default project;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 4. Run
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# As an ElizaOS project:
|
|
80
|
+
elizaos start
|
|
81
|
+
|
|
82
|
+
# Or run the standalone demo:
|
|
83
|
+
bun run example
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 5. Chat with Your Agent
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
You: What x402 services are available?
|
|
90
|
+
Agent: Found 5 x402 service(s) on OpenDexter:
|
|
91
|
+
WETH On-Chain Price ($0.01/call), Solana Token Price ($0.01/call)...
|
|
92
|
+
|
|
93
|
+
You: Access the x402 endpoint at https://pro-api.coingecko.com/api/v3/x402/onchain/simple/net
|
|
94
|
+
Agent: Access successful.
|
|
95
|
+
- Endpoint: GET https://pro-api.coingecko.com/...
|
|
96
|
+
- Amount paid: $0.0100 USDC
|
|
97
|
+
- Tx: 5abc...xyz (eip155:84532)
|
|
98
|
+
- Remaining budget: $9.99
|
|
99
|
+
|
|
100
|
+
You: Use the swarm to analyze top DeFi protocols and summarize risks
|
|
101
|
+
Agent: Swarm completed (SequentialWorkflow)
|
|
102
|
+
Agents: 2, Execution time: 12.3s
|
|
103
|
+
Result: [detailed analysis]...
|
|
104
|
+
|
|
105
|
+
You: Run a code review agent to check this smart contract
|
|
106
|
+
Agent: Agent "CodeReviewer" completed.
|
|
107
|
+
[detailed review]...
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Plugin Components
|
|
111
|
+
|
|
112
|
+
| Component | Type | Name | Purpose |
|
|
113
|
+
|-----------|------|------|---------|
|
|
114
|
+
| Action | | `PAY_FOR_X402_SERVICE` | Access x402-protected APIs with automatic USDC payment |
|
|
115
|
+
| Action | | `DISCOVER_X402_SERVICES` | Browse OpenDexter marketplace for paid APIs |
|
|
116
|
+
| Action | | `DELEGATE_TO_SWARM` | Delegate to 15+ multi-agent swarm architectures |
|
|
117
|
+
| Action | | `RUN_SWARM_AGENT` | Run a single specialized agent via Swarms |
|
|
118
|
+
| Action | | `DELEGATE_TO_SWARM_WITH_PAYMENT` | Fetch x402 data then feed it into a swarm analysis |
|
|
119
|
+
| Provider | | `X402_PAYMENT_CONTEXT` | Injects wallet/budget/spending into LLM prompt |
|
|
120
|
+
| Provider | | `X402_SERVER_CONTEXT` | Injects sell-side revenue and endpoint catalog into LLM prompt |
|
|
121
|
+
| Evaluator | | `PAYMENT_EVALUATOR` | Warns at >80% budget usage, logs summaries |
|
|
122
|
+
| Service | | `X402WalletService` | Dexter SDK wallet with budget controls |
|
|
123
|
+
| Service | | `SwarmsService` | swarms-ts SDK wrapper for agent/swarm runs |
|
|
124
|
+
| Service | | `X402ServerService` | Server-side x402 gate for selling agent services |
|
|
125
|
+
| Service | | `PaymentMemoryService` | Persistent payment history and endpoint scoring |
|
|
126
|
+
|
|
127
|
+
## Routes
|
|
128
|
+
|
|
129
|
+
The plugin registers 5 HTTP routes for selling agent capabilities via x402 micropayments:
|
|
130
|
+
|
|
131
|
+
| Route | Method | Price | Description |
|
|
132
|
+
|-------|--------|-------|-------------|
|
|
133
|
+
| `/x402/research` | POST | $0.05 | Multi-agent research pipeline (Researcher + FactChecker + Writer) |
|
|
134
|
+
| `/x402/analyze` | POST | $0.03 | Multi-perspective analysis panel (Technical + Economic + Risk experts) |
|
|
135
|
+
| `/x402/agent` | POST | $0.02 | Run a single AI agent with custom task, model, and system prompt |
|
|
136
|
+
| `/x402/catalog` | GET | FREE | List all available paid endpoints with pricing |
|
|
137
|
+
| `/x402/health` | GET | FREE | Service health, revenue stats, and network info |
|
|
138
|
+
|
|
139
|
+
Paid routes use `x402Gate` to require USDC payment before processing. Free routes are publicly accessible.
|
|
140
|
+
|
|
141
|
+
## Templates
|
|
142
|
+
|
|
143
|
+
4 pre-built swarm templates map user intent to specific architectures and agent configurations:
|
|
144
|
+
|
|
145
|
+
| Template | Swarm Type | Agents | Trigger Examples |
|
|
146
|
+
|----------|-----------|--------|------------------|
|
|
147
|
+
| `ResearchPipeline` | SequentialWorkflow | Researcher, FactChecker, Writer | "research X", "write a report on X" |
|
|
148
|
+
| `AnalysisPanel` | MixtureOfAgents | TechnicalExpert, EconomicExpert, RiskExpert, Synthesizer | "analyze X from multiple perspectives" |
|
|
149
|
+
| `CodeReview` | ConcurrentWorkflow | SecurityAuditor, PerformanceReviewer, StyleChecker | "audit this smart contract", "review this code" |
|
|
150
|
+
| `DebateAndDecide` | MajorityVoting | Proponent, Opponent, Judge | "should I do X?", "pros and cons of X" |
|
|
151
|
+
|
|
152
|
+
Templates are matched via regex trigger patterns. Custom templates can be registered at runtime with `registerSwarmTemplate()`.
|
|
153
|
+
|
|
154
|
+
## DB Schemas
|
|
155
|
+
|
|
156
|
+
3 Drizzle ORM tables provide persistent storage for payment analytics and budget tracking:
|
|
157
|
+
|
|
158
|
+
| Table | Purpose | Key Columns |
|
|
159
|
+
|-------|---------|-------------|
|
|
160
|
+
| `x402_payment_history` | Every payment the agent makes | endpoint, amountUsd, txHash, network, qualityScore, responseTimeMs |
|
|
161
|
+
| `x402_endpoint_scores` | Aggregate quality scores per domain | totalCalls, totalSpentUsd, avgQualityScore, errorCount |
|
|
162
|
+
| `x402_budget_state` | Cross-session budget state per agent | dailySpentUsd, weeklySpentUsd, monthlySpentUsd, lifetimeSpentUsd |
|
|
163
|
+
|
|
164
|
+
Schemas are exported as `schema` on the plugin object and auto-migrated by ElizaOS v2.
|
|
165
|
+
|
|
166
|
+
## Environment Variables
|
|
167
|
+
|
|
168
|
+
| Variable | Required | Default | Description |
|
|
169
|
+
|----------|----------|---------|-------------|
|
|
170
|
+
| `EVM_PRIVATE_KEY` | One of EVM/Solana | — | EVM private key (hex) for Base/Polygon/Arbitrum |
|
|
171
|
+
| `SOLANA_PRIVATE_KEY` | One of EVM/Solana | — | Solana private key (base58) |
|
|
172
|
+
| `X402_NETWORK_ID` | No | `base-mainnet` | Network: `base-mainnet`, `base-sepolia`, `solana-mainnet`, `polygon-mainnet`, `arbitrum-mainnet`, `ethereum-mainnet` |
|
|
173
|
+
| `X402_MAX_AUTO_PAY_USD` | No | `0.10` | Max USDC per auto-pay request |
|
|
174
|
+
| `X402_BUDGET_USD` | No | `10.00` | Total session budget in USD |
|
|
175
|
+
| `X402_RECEIVE_ADDRESS` | No | — | Your address for receiving payments |
|
|
176
|
+
| `X402_ACCESS_PASS_TIER` | No | — | Access pass tier to offer/purchase: `24h` ($1), `7d` ($5), `30d` ($25) |
|
|
177
|
+
| `X402_ACCESS_PASS_MAX_SPEND` | No | `25.00` | Max spend for access pass purchase |
|
|
178
|
+
| `X402_FACILITATOR_URL` | No | Dexter default | Custom facilitator URL |
|
|
179
|
+
| `SWARMS_API_KEY` | For swarms | — | Swarms API key from [swarms.world](https://swarms.world/platform/api-keys) |
|
|
180
|
+
| `OPENAI_API_KEY` | One LLM key | — | OpenAI API key (used directly for single-agent tasks; falls back to Swarms if absent) |
|
|
181
|
+
| `ANTHROPIC_API_KEY` | One LLM key | — | Anthropic API key |
|
|
182
|
+
|
|
183
|
+
### Access Passes
|
|
184
|
+
|
|
185
|
+
For data and trading endpoints called at high frequency (100-10K calls/day), per-call x402 pricing adds unacceptable latency (~200-500ms per request for the 402 negotiate/pay/retry cycle). Access passes solve this: buyers pay once for time-limited unlimited access, then all subsequent calls are served at native HTTP latency.
|
|
186
|
+
|
|
187
|
+
| Tier | Price | Duration |
|
|
188
|
+
|------|-------|----------|
|
|
189
|
+
| Day Pass | $1 | 24 hours |
|
|
190
|
+
| Week Pass | $5 | 7 days |
|
|
191
|
+
| Month Pass | $25 | 30 days |
|
|
192
|
+
|
|
193
|
+
**Selling passes (operators):** Set `X402_ACCESS_PASS_TIER` in your env to configure which tiers you offer. The Dexter SDK advertises available tiers in the 402 response and handles pass verification internally.
|
|
194
|
+
|
|
195
|
+
**Buying passes (consumers):** When your agent or bot calls a data endpoint, the 402 response includes access pass options alongside per-call pricing. The Dexter SDK can automatically purchase a pass if `X402_ACCESS_PASS_TIER` is configured (e.g., `24h`, `7d`, `30d`). After purchase, all calls from that wallet are served instantly until expiry.
|
|
196
|
+
|
|
197
|
+
Per-call pricing ($0.001-$0.10) remains the default for multi-agent AI tasks (research, analyze, debate) where the x402 latency is negligible relative to the task execution time.
|
|
198
|
+
|
|
199
|
+
See [docs/TOKENOMICS.md](docs/TOKENOMICS.md) for the full access pass economic model.
|
|
200
|
+
|
|
201
|
+
## How x402 Works
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
Agent --> GET /data --> 402 Payment Required
|
|
205
|
+
|
|
|
206
|
+
{ price: "$0.01", payTo: "0x...", network: "eip155:8453" }
|
|
207
|
+
|
|
|
208
|
+
Dexter SDK: signs USDC transfer, checks budget
|
|
209
|
+
|
|
|
210
|
+
Agent --> GET /data (with payment proof) --> 200 OK + data
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
x402 is an open standard. No API keys, no subscriptions — just HTTP + stablecoins. The Dexter SDK handles the 402 -> sign -> retry flow automatically with budget controls and access pass support. Gas fees are sponsored by the Dexter facilitator.
|
|
214
|
+
|
|
215
|
+
## Swarm Architectures
|
|
216
|
+
|
|
217
|
+
The `DELEGATE_TO_SWARM` action supports these architectures (set via `swarmType`):
|
|
218
|
+
|
|
219
|
+
| Type | Use Case |
|
|
220
|
+
|------|----------|
|
|
221
|
+
| `SequentialWorkflow` | Step-by-step pipelines (research -> write -> edit) |
|
|
222
|
+
| `ConcurrentWorkflow` | Independent parallel tasks |
|
|
223
|
+
| `MixtureOfAgents` | Multiple expert perspectives, synthesized |
|
|
224
|
+
| `HiearchicalSwarm` | Director + workers for complex projects |
|
|
225
|
+
| `GroupChat` | Brainstorming or collaborative discussion |
|
|
226
|
+
| `HeavySwarm` | Deep research requiring thorough investigation |
|
|
227
|
+
| `MajorityVoting` | Decisions needing consensus |
|
|
228
|
+
| `DeepResearchSwarm` | Extended research pipelines |
|
|
229
|
+
| `AgentRearrange` | Custom DAG-based agent topology |
|
|
230
|
+
| `MultiAgentRouter` | Intelligent task routing to best agent |
|
|
231
|
+
| `AutoSwarmBuilder` | API auto-generates the right swarm |
|
|
232
|
+
| `auto` | Let the API pick (default) |
|
|
233
|
+
|
|
234
|
+
## LLM Routing
|
|
235
|
+
|
|
236
|
+
SwarmX uses a cost-optimized dual-backend strategy for LLM calls:
|
|
237
|
+
|
|
238
|
+
| Endpoint Type | Endpoints | Backend | Why |
|
|
239
|
+
|---------------|-----------|---------|-----|
|
|
240
|
+
| **Single-agent** | `/x402/agent`, summarize, translate, extract, sentiment | Direct OpenAI API | No orchestration overhead. ~$0.001/call, ~95% margin. |
|
|
241
|
+
| **Multi-agent** | `/x402/research`, `/x402/analyze`, code-review, write, debate | Swarms API | Requires multi-agent orchestration (2-4 agents). ~40-60% margin. |
|
|
242
|
+
|
|
243
|
+
- Single-agent tasks use `src/utils/llm.ts` which calls OpenAI directly with `OPENAI_API_KEY`
|
|
244
|
+
- Multi-agent tasks use `SwarmsService` which calls the Swarms cloud API with `SWARMS_API_KEY`
|
|
245
|
+
- **Fallback**: if `OPENAI_API_KEY` is not set, all tasks route through Swarms (works but costs more)
|
|
246
|
+
|
|
247
|
+
## Examples
|
|
248
|
+
|
|
249
|
+
### Basic Agent (`examples/basic-agent.ts`)
|
|
250
|
+
|
|
251
|
+
Minimal ElizaOS v2 project with x402 payments and swarm delegation. Run with `bun run example`.
|
|
252
|
+
|
|
253
|
+
### SignalHawk (`examples/signalhawk/`)
|
|
254
|
+
|
|
255
|
+
Full-featured autonomous trading intelligence agent that:
|
|
256
|
+
- Buys on-chain and market data via x402 micropayments
|
|
257
|
+
- Runs multi-analyst MajorityVoting swarms for consensus signals
|
|
258
|
+
- Sells structured signal cards with confidence %, analyst agreement, and cost breakdown
|
|
259
|
+
|
|
260
|
+
See `examples/signalhawk/` for the complete implementation.
|
|
261
|
+
|
|
262
|
+
## GitHub Action
|
|
263
|
+
|
|
264
|
+
Audit smart contracts on every PR with 4 AI agents. See [`github-action/`](github-action/) for full docs.
|
|
265
|
+
|
|
266
|
+
```yaml
|
|
267
|
+
name: Contract Audit
|
|
268
|
+
on:
|
|
269
|
+
pull_request:
|
|
270
|
+
paths:
|
|
271
|
+
- 'contracts/**/*.sol'
|
|
272
|
+
|
|
273
|
+
permissions:
|
|
274
|
+
contents: read
|
|
275
|
+
pull-requests: write
|
|
276
|
+
|
|
277
|
+
jobs:
|
|
278
|
+
audit:
|
|
279
|
+
runs-on: ubuntu-latest
|
|
280
|
+
steps:
|
|
281
|
+
- uses: actions/checkout@v4
|
|
282
|
+
|
|
283
|
+
- uses: ItachiDevv/swarmx-audit@v1
|
|
284
|
+
with:
|
|
285
|
+
files: 'contracts/**/*.sol'
|
|
286
|
+
fail-on-critical: true
|
|
287
|
+
env:
|
|
288
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
The action posts a structured audit report as a PR comment (security findings, economic attack vectors, gas optimizations) and fails the check if critical issues are found. Free tier (10 calls/day) works without a wallet.
|
|
292
|
+
|
|
293
|
+
## Development
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
bun install # Install dependencies
|
|
297
|
+
bun run build # Compile TypeScript
|
|
298
|
+
bun run test # Run unit + integration tests (162 cases)
|
|
299
|
+
bun run test:smoke # Marketplace smoke tests (needs network)
|
|
300
|
+
bun run dev # Watch mode
|
|
301
|
+
bun run example # Run standalone demo
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Key Dependencies
|
|
305
|
+
|
|
306
|
+
- `@elizaos/core@2.0.0-alpha.32` — ElizaOS v2 runtime
|
|
307
|
+
- `@dexterai/x402@^2.0.0` — Dexter SDK for x402 payments
|
|
308
|
+
- `swarms-ts@^0.1.0-alpha.10` — Swarms TypeScript SDK
|
|
309
|
+
- `drizzle-orm@^0.45.1` — Database schemas for payment persistence
|
|
310
|
+
- `zod@^3.22.0` — Runtime validation
|
|
311
|
+
|
|
312
|
+
## Roadmap
|
|
313
|
+
|
|
314
|
+
See [TODO-NEXT.md](TODO-NEXT.md) for post-MVP next steps:
|
|
315
|
+
- CI/CD with GitHub Actions
|
|
316
|
+
- npm publish to registry
|
|
317
|
+
- Server-side x402 middleware (sell your agent's services)
|
|
318
|
+
- Event hooks for payment analytics
|
|
319
|
+
- Custom HTTP routes for wallet status
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Action } from "@elizaos/core";
|
|
2
|
+
/**
|
|
3
|
+
* Delegate a task to a Swarms multi-agent system.
|
|
4
|
+
* Supports 15+ swarm architectures: sequential, concurrent, hierarchical, mixture-of-agents, etc.
|
|
5
|
+
* Uses pre-built templates for common patterns, with full LLM extraction as fallback.
|
|
6
|
+
*/
|
|
7
|
+
export declare const delegateToSwarm: Action;
|
|
8
|
+
//# sourceMappingURL=delegateToSwarm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegateToSwarm.d.ts","sourceRoot":"","sources":["../../src/actions/delegateToSwarm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EAMZ,MAAM,eAAe,CAAC;AAmFvB;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAiQ7B,CAAC"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { ModelType, } from "@elizaos/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { findMatchingTemplate, SWARM_TEMPLATES, buildClassificationPrompt, } from "../templates/index.js";
|
|
4
|
+
const VALID_SWARM_TYPES = [
|
|
5
|
+
"SequentialWorkflow",
|
|
6
|
+
"ConcurrentWorkflow",
|
|
7
|
+
"MixtureOfAgents",
|
|
8
|
+
"AgentRearrange",
|
|
9
|
+
"HiearchicalSwarm",
|
|
10
|
+
"GroupChat",
|
|
11
|
+
"MultiAgentRouter",
|
|
12
|
+
"AutoSwarmBuilder",
|
|
13
|
+
"MajorityVoting",
|
|
14
|
+
"HeavySwarm",
|
|
15
|
+
"DeepResearchSwarm",
|
|
16
|
+
"auto",
|
|
17
|
+
];
|
|
18
|
+
const DelegateSchema = z.object({
|
|
19
|
+
task: z.string().min(1),
|
|
20
|
+
swarmType: z.enum(VALID_SWARM_TYPES).optional().default("auto"),
|
|
21
|
+
agents: z
|
|
22
|
+
.array(z.object({
|
|
23
|
+
agent_name: z.string(),
|
|
24
|
+
system_prompt: z.string().optional(),
|
|
25
|
+
model_name: z.string().optional(),
|
|
26
|
+
role: z.string().optional(),
|
|
27
|
+
}))
|
|
28
|
+
.optional(),
|
|
29
|
+
maxLoops: z.number().positive().optional(),
|
|
30
|
+
});
|
|
31
|
+
/** Schema for LLM classification when no keyword match */
|
|
32
|
+
const ClassificationSchema = z.object({
|
|
33
|
+
templateId: z.string(),
|
|
34
|
+
task: z.string().min(1),
|
|
35
|
+
});
|
|
36
|
+
/** Schema for minimal task extraction when template is pre-matched */
|
|
37
|
+
const TaskExtractionSchema = z.object({
|
|
38
|
+
task: z.string().min(1),
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Build SwarmRunParams from a matched template and extracted task string.
|
|
42
|
+
*/
|
|
43
|
+
function buildParamsFromTemplate(template, task) {
|
|
44
|
+
return {
|
|
45
|
+
task,
|
|
46
|
+
swarmType: template.swarmType,
|
|
47
|
+
agents: template.agents.map((a) => ({
|
|
48
|
+
agent_name: a.agent_name,
|
|
49
|
+
system_prompt: a.system_prompt ?? null,
|
|
50
|
+
model_name: a.model_name ?? "gpt-4o-mini",
|
|
51
|
+
role: a.role ?? "worker",
|
|
52
|
+
max_loops: a.max_loops ?? 1,
|
|
53
|
+
max_tokens: a.max_tokens ?? 4096,
|
|
54
|
+
temperature: a.temperature ?? 0.5,
|
|
55
|
+
})),
|
|
56
|
+
maxLoops: template.maxLoops ?? 1,
|
|
57
|
+
rules: template.rules,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Delegate a task to a Swarms multi-agent system.
|
|
62
|
+
* Supports 15+ swarm architectures: sequential, concurrent, hierarchical, mixture-of-agents, etc.
|
|
63
|
+
* Uses pre-built templates for common patterns, with full LLM extraction as fallback.
|
|
64
|
+
*/
|
|
65
|
+
export const delegateToSwarm = {
|
|
66
|
+
name: "DELEGATE_TO_SWARM",
|
|
67
|
+
description: "Delegate a complex task to a Swarms multi-agent system. Supports sequential pipelines, concurrent processing, mixture-of-agents, hierarchical delegation, group chat, and more. Set swarm_type to control the architecture.",
|
|
68
|
+
similes: [
|
|
69
|
+
"RUN_SWARM_TASK",
|
|
70
|
+
"USE_SWARM_AGENT",
|
|
71
|
+
"MULTI_AGENT_TASK",
|
|
72
|
+
"SWARMS_PAY_AND_RUN",
|
|
73
|
+
"RUN_MULTI_AGENT",
|
|
74
|
+
],
|
|
75
|
+
validate: async (runtime, _message, _state) => {
|
|
76
|
+
return !!runtime.getSetting("SWARMS_API_KEY");
|
|
77
|
+
},
|
|
78
|
+
handler: async (runtime, message, _state, _options, callback) => {
|
|
79
|
+
const swarmsService = runtime.getService("SWARMS");
|
|
80
|
+
if (!swarmsService || !swarmsService.isAvailable()) {
|
|
81
|
+
await callback?.({
|
|
82
|
+
text: "Swarms service not initialized. Set SWARMS_API_KEY in your environment.",
|
|
83
|
+
error: true,
|
|
84
|
+
});
|
|
85
|
+
return { success: false, error: "Swarms service not initialized" };
|
|
86
|
+
}
|
|
87
|
+
const userText = message.content.text ?? "";
|
|
88
|
+
let task;
|
|
89
|
+
let swarmType;
|
|
90
|
+
let agents;
|
|
91
|
+
let maxLoops;
|
|
92
|
+
let templateName = null;
|
|
93
|
+
// --- Step 1: Try keyword pre-filter for fast template matching ---
|
|
94
|
+
let matchedTemplate = findMatchingTemplate(userText);
|
|
95
|
+
// --- Step 2: If no keyword match, use LLM classification ---
|
|
96
|
+
if (!matchedTemplate) {
|
|
97
|
+
const classificationPrompt = buildClassificationPrompt(userText);
|
|
98
|
+
const classificationResult = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
99
|
+
prompt: classificationPrompt,
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
const parsed = ClassificationSchema.parse(JSON.parse(String(classificationResult)));
|
|
103
|
+
if (parsed.templateId !== "custom") {
|
|
104
|
+
matchedTemplate =
|
|
105
|
+
SWARM_TEMPLATES.find((t) => t.id === parsed.templateId) ?? null;
|
|
106
|
+
}
|
|
107
|
+
// Use the LLM-extracted task if we got one (useful for both template and custom paths)
|
|
108
|
+
if (parsed.task) {
|
|
109
|
+
task = parsed.task;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Classification failed — fall through to custom path
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// --- Step 3: Build params from template or fall back to full custom extraction ---
|
|
117
|
+
if (matchedTemplate) {
|
|
118
|
+
// Template matched — only need to extract the task string if not already set
|
|
119
|
+
if (!task) {
|
|
120
|
+
const taskExtraction = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
121
|
+
prompt: `Extract the specific task the user wants performed from their message. Return JSON: { "task": "<the task>" }
|
|
122
|
+
|
|
123
|
+
User message: "${userText}"
|
|
124
|
+
|
|
125
|
+
Return only valid JSON, no markdown.`,
|
|
126
|
+
});
|
|
127
|
+
try {
|
|
128
|
+
const parsed = TaskExtractionSchema.parse(JSON.parse(String(taskExtraction)));
|
|
129
|
+
task = parsed.task;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
task = userText;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const templateParams = buildParamsFromTemplate(matchedTemplate, task);
|
|
136
|
+
swarmType = templateParams.swarmType;
|
|
137
|
+
agents = templateParams.agents;
|
|
138
|
+
maxLoops = templateParams.maxLoops;
|
|
139
|
+
templateName = matchedTemplate.name;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Custom path — full LLM extraction with VALID_SWARM_TYPES and DelegateSchema
|
|
143
|
+
const extraction = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
144
|
+
prompt: `Extract swarm task details from the user message. Return JSON with:
|
|
145
|
+
- task: string (the task description)
|
|
146
|
+
- swarmType: one of ${VALID_SWARM_TYPES.join(", ")} (default "auto" if unclear)
|
|
147
|
+
- agents: optional array of { agent_name, system_prompt?, model_name?, role? }
|
|
148
|
+
Only include agents if the user specifies specific agent roles.
|
|
149
|
+
- maxLoops: optional number (default 1)
|
|
150
|
+
|
|
151
|
+
Guidelines for swarmType selection:
|
|
152
|
+
- "SequentialWorkflow" for step-by-step pipelines (research -> write -> edit)
|
|
153
|
+
- "ConcurrentWorkflow" for independent parallel tasks
|
|
154
|
+
- "MixtureOfAgents" for getting multiple expert perspectives synthesized
|
|
155
|
+
- "HiearchicalSwarm" for complex projects needing a director + workers
|
|
156
|
+
- "GroupChat" for brainstorming or collaborative discussion
|
|
157
|
+
- "HeavySwarm" for deep research requiring thorough investigation
|
|
158
|
+
- "MajorityVoting" for decisions needing consensus
|
|
159
|
+
- "auto" when unsure — the API picks the best architecture
|
|
160
|
+
|
|
161
|
+
User message: "${userText}"
|
|
162
|
+
|
|
163
|
+
Return only valid JSON, no markdown.`,
|
|
164
|
+
});
|
|
165
|
+
let params;
|
|
166
|
+
try {
|
|
167
|
+
params = DelegateSchema.parse(JSON.parse(String(extraction)));
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
params = { task: userText || "unspecified task", swarmType: "auto" };
|
|
171
|
+
}
|
|
172
|
+
task = params.task;
|
|
173
|
+
swarmType = params.swarmType;
|
|
174
|
+
maxLoops = params.maxLoops ?? 1;
|
|
175
|
+
// Build agent specs — use extracted agents or sensible defaults
|
|
176
|
+
agents =
|
|
177
|
+
params.agents && params.agents.length > 0
|
|
178
|
+
? params.agents.map((a) => ({
|
|
179
|
+
agent_name: a.agent_name,
|
|
180
|
+
system_prompt: a.system_prompt ?? null,
|
|
181
|
+
model_name: a.model_name ?? "gpt-4o-mini",
|
|
182
|
+
role: a.role ?? "worker",
|
|
183
|
+
max_loops: 1,
|
|
184
|
+
max_tokens: 4096,
|
|
185
|
+
temperature: 0.5,
|
|
186
|
+
}))
|
|
187
|
+
: [
|
|
188
|
+
{
|
|
189
|
+
agent_name: "Researcher",
|
|
190
|
+
system_prompt: "You are a thorough researcher. Analyze the task, gather key information, and provide detailed findings.",
|
|
191
|
+
model_name: "gpt-4o-mini",
|
|
192
|
+
role: "worker",
|
|
193
|
+
max_loops: 1,
|
|
194
|
+
max_tokens: 4096,
|
|
195
|
+
temperature: 0.5,
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
agent_name: "Analyst",
|
|
199
|
+
system_prompt: "You are an expert analyst. Take the research findings and produce actionable insights and recommendations.",
|
|
200
|
+
model_name: "gpt-4o-mini",
|
|
201
|
+
role: "worker",
|
|
202
|
+
max_loops: 1,
|
|
203
|
+
max_tokens: 4096,
|
|
204
|
+
temperature: 0.3,
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
const templateLabel = templateName
|
|
209
|
+
? ` [${templateName}]`
|
|
210
|
+
: "";
|
|
211
|
+
await callback?.({
|
|
212
|
+
text: `Delegating to swarm (${swarmType})${templateLabel} with ${agents.length} agent(s)...\nAgents: ${agents.map((a) => a.agent_name).join(", ")}`,
|
|
213
|
+
});
|
|
214
|
+
try {
|
|
215
|
+
const result = await swarmsService.runSwarm({
|
|
216
|
+
name: `ElizaOS-x402-${Date.now()}`,
|
|
217
|
+
description: `Task delegated from ElizaOS agent`,
|
|
218
|
+
agents,
|
|
219
|
+
task,
|
|
220
|
+
swarm_type: swarmType,
|
|
221
|
+
max_loops: maxLoops,
|
|
222
|
+
});
|
|
223
|
+
// Extract output — can be string, object, or nested
|
|
224
|
+
let output;
|
|
225
|
+
if (typeof result.output === "string") {
|
|
226
|
+
output = result.output;
|
|
227
|
+
}
|
|
228
|
+
else if (result.output != null) {
|
|
229
|
+
output = JSON.stringify(result.output, null, 2);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
output = "(no output)";
|
|
233
|
+
}
|
|
234
|
+
const text = `Swarm completed (${result.swarm_type ?? swarmType})${templateLabel}
|
|
235
|
+
|
|
236
|
+
Agents: ${result.number_of_agents ?? agents.length}
|
|
237
|
+
Execution time: ${result.execution_time != null ? `${result.execution_time.toFixed(1)}s` : "unknown"}
|
|
238
|
+
Job ID: ${result.job_id ?? "unknown"}
|
|
239
|
+
|
|
240
|
+
Result:
|
|
241
|
+
${output.slice(0, 1000)}`;
|
|
242
|
+
await callback?.({
|
|
243
|
+
text,
|
|
244
|
+
content: {
|
|
245
|
+
jobId: result.job_id ?? "",
|
|
246
|
+
swarmType: result.swarm_type ?? swarmType,
|
|
247
|
+
templateName: templateName ?? undefined,
|
|
248
|
+
executionTime: String(result.execution_time ?? 0),
|
|
249
|
+
agentCount: String(result.number_of_agents ?? agents.length),
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
return { success: true, text };
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
256
|
+
await callback?.({
|
|
257
|
+
text: `Swarm delegation failed: ${msg}`,
|
|
258
|
+
error: true,
|
|
259
|
+
});
|
|
260
|
+
return { success: false, error: msg };
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
examples: [
|
|
264
|
+
[
|
|
265
|
+
{
|
|
266
|
+
name: "user",
|
|
267
|
+
content: {
|
|
268
|
+
text: "Use the swarm to analyze top DeFi protocols and summarize risks",
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: "agent",
|
|
273
|
+
content: {
|
|
274
|
+
text: "Swarm completed (SequentialWorkflow)\n\nAgents: 2\nExecution time: 12.3s\n\nResult: [detailed analysis]...",
|
|
275
|
+
actions: ["DELEGATE_TO_SWARM"],
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
[
|
|
280
|
+
{
|
|
281
|
+
name: "user",
|
|
282
|
+
content: {
|
|
283
|
+
text: "Run a concurrent swarm with 3 agents to research Bitcoin, Ethereum, and Solana simultaneously",
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "agent",
|
|
288
|
+
content: {
|
|
289
|
+
text: "Swarm completed (ConcurrentWorkflow)\n\nAgents: 3\nExecution time: 8.1s\n\nResult: [parallel research results]...",
|
|
290
|
+
actions: ["DELEGATE_TO_SWARM"],
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
],
|
|
295
|
+
};
|
|
296
|
+
//# sourceMappingURL=delegateToSwarm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegateToSwarm.js","sourceRoot":"","sources":["../../src/actions/delegateToSwarm.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,yBAAyB,GAC1B,MAAM,uBAAuB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