cornerstone-autonomous-agent 2.0.0 → 2.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/.env.example +3 -8
- package/LICENSE.md +384 -384
- package/README.md +27 -27
- package/adapters/local/README.md +2 -2
- package/adapters/openai/openapi.yaml +3 -3
- package/adapters/openclaw/SKILL.md +40 -29
- package/package.json +4 -4
- package/skills/README.md +1 -1
- package/skills/autonomous-agent/SKILL.md +41 -30
- package/src/agent/agent.js +77 -53
- package/src/agent/tools/localTools.js +260 -259
- package/src/agent/tools/mcpTools.js +150 -150
- package/src/cli.js +1 -1
- package/src/lib/aptos/signPayment.js +1 -1
- package/src/lib/evm/signPayment.js +1 -1
- package/src/lib/mcp/client.js +35 -17
- package/src/run-agent.js +2 -2
- package/src/show-agent-addresses.js +33 -33
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CornerStone MCP x402 Skill – Tools for Agents
|
|
2
2
|
|
|
3
3
|
**Published as [cornerstone-autonomous-agent](https://www.npmjs.com/package/cornerstone-autonomous-agent)** on npm; **source: [FinTechTonic/autonomous-agent](https://github.com/FinTechTonic/autonomous-agent)**.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A **skill** that gives agents a set of **x402-paid MCP tools**: predict tickers, backtest strategies, link bank accounts, and query agent/borrower scores. Agents using this skill pay with **Aptos** or **EVM** via the x402 facilitator. Designed for marketplaces where agents can autonomously download and use the skill; also usable from Cursor, OpenClaw/Moltbot, and headless runners.
|
|
6
6
|
|
|
7
7
|
## Why?
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Agents need tools, not a full backend. This skill provides **run_prediction**, **run_backtest**, **link_bank_account**, and **score tools** (get_agent_reputation_score, get_borrower_score, by-email variants). Agents using it talk to an **x402 MCP server**, pay with their own Aptos and EVM wallets (verify → settle), and get results after minimal setup—whitelist the agent’s addresses, fund wallets, then the agent can call the tools. The server offers both Aptos and EVM payment options; the skill handles 402 → pay → retry so the agent just calls the tool.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ Most agent demos need a full backend and separate API keys. This agent talks to
|
|
|
16
16
|
npm install cornerstone-autonomous-agent
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Copy the package’s `.env.example` into your project and set `
|
|
19
|
+
Copy the package’s `.env.example` into your project and set `X402_FACILITATOR_URL`, `HUGGINGFACE_API_KEY`, `LLM_MODEL`, and wallet paths. See [Config](#config).
|
|
20
20
|
|
|
21
21
|
### From source
|
|
22
22
|
|
|
@@ -25,8 +25,7 @@ git clone https://github.com/FinTechTonic/autonomous-agent.git && cd autonomous-
|
|
|
25
25
|
npm install
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
**OpenClaw / Moltbot:** See [adapters/openclaw/SKILL.md](adapters/openclaw/SKILL.md) or use your platform’s skill install (e.g. ClawHub).
|
|
29
|
-
|
|
28
|
+
**OpenClaw / Moltbot:** See [adapters/openclaw/SKILL.md](adapters/openclaw/SKILL.md) or use your platform’s skill install (e.g. ClawHub).
|
|
30
29
|
## Quick Start
|
|
31
30
|
|
|
32
31
|
**Important:** Another npm package is named [autonomous](https://www.npmjs.com/package/autonomous). To run **this** package without installing, always use the full name: **`npx cornerstone-autonomous-agent`**. After you `npm install cornerstone-autonomous-agent`, the short binary `autonomous` in that project runs this CLI.
|
|
@@ -62,7 +61,6 @@ Copy `.env.example` to `.env` and set:
|
|
|
62
61
|
|
|
63
62
|
| Variable | Description |
|
|
64
63
|
|----------|-------------|
|
|
65
|
-
| `MCP_SERVER_URL` | x402 MCP server base URL (e.g. http://localhost:4023 or https://3001-borrower.replit.app) |
|
|
66
64
|
| `X402_FACILITATOR_URL` | Facilitator base URL (Aptos + EVM verify/settle). Use public (e.g. https://x402-navy.vercel.app/facilitator) for full demo. |
|
|
67
65
|
| `X402_EVM_FACILITATOR_URL` | Optional. EVM facilitator; defaults to X402_FACILITATOR_URL. |
|
|
68
66
|
| `PREFERRED_PAYMENT_ORDER` | Optional. Comma-separated `network|asset` (e.g. `aptos:2|usdc,eip155:84532|usdc`) to choose payment option when server returns multiple. |
|
|
@@ -71,7 +69,7 @@ Copy `.env.example` to `.env` and set:
|
|
|
71
69
|
| `LLM_MODEL` | Model ID (e.g. meta-llama/Llama-3.2-3B-Instruct) |
|
|
72
70
|
| `APTOS_WALLET_PATH` | Aptos wallet JSON path. Multi-wallet: ~/.aptos-agent-wallets.json. |
|
|
73
71
|
| `EVM_WALLET_PATH` | EVM wallet path. Multi-wallet: ~/.evm-wallets.json. Or set EVM_PRIVATE_KEY. |
|
|
74
|
-
| `BASE_SEPOLIA_RPC` | Optional; Base Sepolia RPC.
|
|
72
|
+
| `BASE_SEPOLIA_RPC` | Optional; Base Sepolia RPC. Skill supports all EVM chains in lib/chains.js (Base, Ethereum, Polygon, etc.). |
|
|
75
73
|
|
|
76
74
|
## Commands
|
|
77
75
|
|
|
@@ -82,16 +80,16 @@ Use **`npx cornerstone-autonomous-agent <command>`** (or, in a project that has
|
|
|
82
80
|
| `autonomous setup` | Generate EVM wallet (single; for multi use agent tool create_evm_wallet) |
|
|
83
81
|
| `autonomous setup:aptos` | Generate Aptos wallet (single; for multi use create_aptos_wallet) |
|
|
84
82
|
| `autonomous setup:evm:multichain` | Generate EVM multi-chain wallet |
|
|
85
|
-
| `autonomous addresses` | Print all Aptos and EVM addresses for whitelisting at flow.html |
|
|
83
|
+
| `autonomous addresses` | Print all Aptos and EVM addresses for whitelisting at https://arnstein.ch/flow.html |
|
|
86
84
|
| `autonomous attest:aptos` | Sign attestation for Aptos wallet (set `APTOS_PRIVATE_KEY` or `APTOS_TESTNET_*`); submit to POST /attest/aptos |
|
|
87
85
|
| `autonomous attest:evm` | Sign attestation for EVM wallet; submit to POST /attest/evm |
|
|
88
86
|
| `autonomous balance [chain]` | EVM balance |
|
|
89
87
|
| `autonomous transfer` | Transfer (see script for args) |
|
|
90
88
|
| `autonomous contract` | Contract interaction helper |
|
|
91
89
|
| `autonomous swap` | Swap helper |
|
|
92
|
-
| `autonomous` or `autonomous agent` or `autonomous start [message]` | Run
|
|
93
|
-
| `npm run credit:aptos` | Credit Aptos
|
|
94
|
-
| `npx cornerstone-agent [message]` | Run
|
|
90
|
+
| `autonomous` or `autonomous agent` or `autonomous start [message]` | Run skill demo (default: balance + prediction) |
|
|
91
|
+
| `npm run credit:aptos` | Credit Aptos wallet (devnet: programmatic; testnet: instructions) |
|
|
92
|
+
| `npx cornerstone-agent [message]` | Run skill demo (legacy bin name) |
|
|
95
93
|
|
|
96
94
|
**Crediting Aptos:** Testnet has no programmatic faucet—use [Aptos testnet faucet](https://aptos.dev/network/faucet). Devnet: `APTOS_FAUCET_NETWORK=devnet npm run credit:aptos`. See [Canteen – Aptos x402](https://canteenapp-aptos-x402.notion.site/).
|
|
97
95
|
|
|
@@ -102,11 +100,13 @@ Use **`npx cornerstone-autonomous-agent <command>`** (or, in a project that has
|
|
|
102
100
|
| `run_prediction` | Stock prediction (symbol, horizon) | x402: Aptos or EVM |
|
|
103
101
|
| `run_backtest` | Backtest trading strategy | x402: Aptos or EVM |
|
|
104
102
|
| `link_bank_account` | CornerStone bank link (Plaid) | x402: Aptos or EVM |
|
|
105
|
-
| `get_agent_reputation_score` |
|
|
106
|
-
| `get_borrower_score` | Borrower score
|
|
103
|
+
| `get_agent_reputation_score` | Reputation Score: measures the agent's ability to transact using x402 | x402 or lender credits |
|
|
104
|
+
| `get_borrower_score` | Borrower score: measures real borrower behavior | x402 or lender credits |
|
|
107
105
|
| `get_agent_reputation_score_by_email` | Reputation score by email (resolves to agent) | x402 or lender credits |
|
|
108
106
|
| `get_borrower_score_by_email` | Borrower score by email | x402 or lender credits |
|
|
109
107
|
|
|
108
|
+
**Score definitions:** Reputation Score measures an agent’s ability to transact using x402. Borrower score measures real borrower behavior.
|
|
109
|
+
|
|
110
110
|
All paid tools accept **both Aptos and EVM**; the server returns 402 with multiple options. Use `PREFERRED_PAYMENT_ORDER` to prefer one chain/asset.
|
|
111
111
|
|
|
112
112
|
## Supported Networks
|
|
@@ -119,11 +119,11 @@ All paid tools accept **both Aptos and EVM**; the server returns 402 with multip
|
|
|
119
119
|
## x402 Flow
|
|
120
120
|
|
|
121
121
|
```
|
|
122
|
-
Agent calls MCP tool
|
|
122
|
+
Agent (using this skill) calls MCP tool
|
|
123
123
|
→ Server returns 402 + payment requirements (single or array of options: USDC, APT, native ETH)
|
|
124
|
-
→
|
|
125
|
-
→
|
|
126
|
-
→
|
|
124
|
+
→ Skill picks one option (by preferredPaymentOrder or first), builds payload (Aptos or EVM)
|
|
125
|
+
→ Skill calls facilitator /verify then /settle
|
|
126
|
+
→ Skill retries request with payment_payload
|
|
127
127
|
→ Server returns result + payment_receipt
|
|
128
128
|
```
|
|
129
129
|
|
|
@@ -141,7 +141,7 @@ autonomous/
|
|
|
141
141
|
│ │ ├── evm/ # EVM wallet, signPayment (Base)
|
|
142
142
|
│ │ └── x402/ # Payment types, verify/settle flow
|
|
143
143
|
│ ├── cli.js # CLI router (autonomous / cornerstone-autonomous-agent)
|
|
144
|
-
│ ├── run-agent.js #
|
|
144
|
+
│ ├── run-agent.js # Skill demo entrypoint (agent + tools)
|
|
145
145
|
│ ├── setup.js # EVM wallet generation
|
|
146
146
|
│ ├── setup-aptos.js # Aptos wallet generation
|
|
147
147
|
│ ├── attest-aptos-wallet.js / attest-evm-wallet.js
|
|
@@ -151,26 +151,26 @@ autonomous/
|
|
|
151
151
|
└── package.json
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
**Core pieces:** `lib/mcp` — MCP client and 402 retry; `lib/aptos` / `lib/evm` — wallets and payment signing; `lib/x402` — verify/settle; `agent/` — LangChain.js ReAct
|
|
154
|
+
**Core pieces:** `lib/mcp` — MCP client and 402 retry; `lib/aptos` / `lib/evm` — wallets and payment signing; `lib/x402` — verify/settle; `agent/` — LangChain.js ReAct runner and tools (for agents using the skill).
|
|
155
155
|
|
|
156
156
|
## Tech Stack
|
|
157
157
|
|
|
158
158
|
- **Runtime:** Node.js 18+
|
|
159
|
-
- **
|
|
159
|
+
- **Runner:** LangChain.js (ReAct), OpenAI-compatible LLM (e.g. Hugging Face) for the demo; agents use the tools via their own runtime
|
|
160
160
|
- **MCP:** [Model Context Protocol](https://modelcontextprotocol.io) + x402 payment flow
|
|
161
161
|
- **Chains:** Aptos (viem-style + @aptos-labs/ts-sdk), EVM (viem) for Base Sepolia/Base
|
|
162
162
|
- **Payments:** x402 facilitator (verify/settle), local wallet storage
|
|
163
163
|
|
|
164
164
|
## Security
|
|
165
165
|
|
|
166
|
-
- **Wallets:** Stored locally (e.g. `~/.aptos-agent-wallets.json`, `~/.evm-wallets.json`); private keys not logged or sent except as signed payloads to the facilitator.
|
|
166
|
+
- **Wallets:** Stored locally (e.g. `~/.aptos-agent-wallets.json`, `~/.evm-wallets.json`) for the agent using the skill; private keys not logged or sent except as signed payloads to the facilitator.
|
|
167
167
|
- **Payments:** Only verify/settle go to the facilitator; no custody of funds by the MCP server.
|
|
168
|
-
- **Whitelist:**
|
|
168
|
+
- **Whitelist:** Addresses used by the agent must be allowlisted at the onboarding flow before paid tools succeed.
|
|
169
169
|
|
|
170
170
|
## Capability + adapters
|
|
171
171
|
|
|
172
|
-
- **Capability:** Core (`src/`) — MCP client, x402 flow,
|
|
173
|
-
- **Adapters:** `adapters/` — how each platform
|
|
172
|
+
- **Capability:** Core (`src/`) — MCP client, x402 flow, tools for agents. No OpenAI/Claw/Anthropic logic in code.
|
|
173
|
+
- **Adapters:** `adapters/` — how each platform or marketplace loads the skill:
|
|
174
174
|
- [adapters/openclaw/SKILL.md](adapters/openclaw/SKILL.md) — OpenClaw / Moltbot
|
|
175
175
|
- [adapters/openai/openapi.yaml](adapters/openai/openapi.yaml) — Custom GPTs / Assistants
|
|
176
176
|
- [adapters/anthropic/tools.json](adapters/anthropic/tools.json) — Claude tools
|
|
@@ -179,8 +179,8 @@ autonomous/
|
|
|
179
179
|
## Deployment order
|
|
180
180
|
|
|
181
181
|
1. **x402 facilitator** — Use public (e.g. https://x402-navy.vercel.app/facilitator) for full demo; or run local and set X402_EVM_FACILITATOR_URL to public for link_bank_account.
|
|
182
|
-
2. **MCP server** — x402-enabled
|
|
183
|
-
3. **
|
|
182
|
+
2. **MCP server** — x402-enabled.
|
|
183
|
+
3. **Skill runner (demo)** — `node src/run-agent.js` or PM2 (`pm2 start ecosystem.config.cjs --only agent-autonomous` from repo root).
|
|
184
184
|
|
|
185
185
|
## References
|
|
186
186
|
|
package/adapters/local/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Local / OSS agents
|
|
2
2
|
|
|
3
|
-
Use the
|
|
3
|
+
Use the CornerStone MCP x402 capability from local or OSS agents (e.g. LM Studio, AutoGen, CrewAI).
|
|
4
4
|
|
|
5
5
|
1. **Source:** [FinTechTonic/autonomous-agent](https://github.com/FinTechTonic/autonomous-agent).
|
|
6
6
|
2. **Install:** `npm install` in `autonomous/`.
|
|
7
|
-
3. **Config:** Set
|
|
7
|
+
3. **Config:** Set x402 facilitator URL and LLM/env as needed.
|
|
8
8
|
4. **Run:** `node src/run-agent.js "your message"` or wire MCP client to your agent framework.
|
|
9
9
|
5. **x402:** On 402 responses, call facilitator verify → settle, then retry the request with `PAYMENT-SIGNATURE` header.
|
|
10
10
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
openapi: 3.0.3
|
|
2
2
|
info:
|
|
3
|
-
title:
|
|
3
|
+
title: CornerStone MCP x402 Tools
|
|
4
4
|
description: Payment-protected tools (run_prediction, run_backtest, open_bank_account, scores). Use x402 flow (402 → pay → retry with PAYMENT-SIGNATURE).
|
|
5
5
|
version: 1.0.0
|
|
6
6
|
servers:
|
|
7
|
-
- url:
|
|
8
|
-
description: MCP server
|
|
7
|
+
- url: https://arnstein.ch/mcp
|
|
8
|
+
description: MCP server
|
|
9
9
|
paths:
|
|
10
10
|
/mcp/prediction/{symbol}:
|
|
11
11
|
get:
|
|
@@ -1,62 +1,73 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: autonomous-agent
|
|
3
|
-
description:
|
|
3
|
+
description: CornerStone MCP x402 skill for agents. Tools for stock predictions, backtests, bank linking, and agent/borrower scores. Payment-protected MCP tools with x402 flow (Aptos + Base). Skill handles 402 → pay → retry. Wallet attestation for onboarding. For marketplaces where agents download and use skills autonomously.
|
|
4
4
|
metadata: {"openclaw":{"emoji":"📈","homepage":"https://github.com/FinTechTonic/autonomous-agent","requires":{"bins":["node","npm"]},"primaryEnv":"MCP_SERVER_URL","skillKey":"autonomous-agent"},"clawdbot":{"emoji":"📈","homepage":"https://github.com/FinTechTonic/autonomous-agent","requires":{"bins":["node","npm"]}}}
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# CornerStone MCP x402 Skill (for Agents)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Skill that gives **agents** tools to call x402-protected MCP endpoints: stock prediction, backtest, bank linking, and agent/borrower scores. **Payment is automatic** — the skill handles 402 → sign → verify → settle → retry transparently. Supports **wallet attestation** (signing) for onboarding (POST /attest/aptos, /attest/evm).
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
Clone or copy the repo. When loaded from OpenClaw/MoltBook, the skill folder is `{baseDir}`; run commands from the **repo root** (parent of `adapters/openclaw` or of `skills/autonomous-agent`).
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
# From repository root
|
|
17
16
|
git clone https://github.com/FinTechTonic/autonomous-agent.git && cd autonomous-agent
|
|
18
17
|
npm install
|
|
19
18
|
```
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
Copy `.env.example` to `.env` and set:
|
|
22
21
|
|
|
23
|
-
- `MCP_SERVER_URL` – MCP server base URL (MCP protocol at `/mcp`)
|
|
24
22
|
- `X402_FACILITATOR_URL` – x402 facilitator (verify/settle)
|
|
25
23
|
- `LLM_BASE_URL`, `HUGGINGFACE_API_KEY` or `HF_TOKEN`, `LLM_MODEL` – for inference
|
|
26
24
|
- `APTOS_WALLET_PATH`, `EVM_WALLET_PATH` (or `EVM_PRIVATE_KEY`) – for payments
|
|
27
25
|
|
|
28
|
-
##
|
|
26
|
+
## Quick-start workflow
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
1. `get_wallet_addresses()` – check what wallets exist.
|
|
29
|
+
2. If empty: `create_aptos_wallet()` + `create_evm_wallet()`.
|
|
30
|
+
3. Fund: `credit_aptos_wallet()` + `fund_evm_wallet()`.
|
|
31
|
+
4. Whitelist addresses at https://arnstein.ch/flow.html.
|
|
32
|
+
5. Check balances: `balance_aptos()`, `balance_evm({ chain: "baseSepolia" })`.
|
|
33
|
+
6. Call paid tools: `run_prediction`, `run_backtest`, `link_bank_account`, or score tools.
|
|
34
|
+
|
|
35
|
+
## Run the skill (demo)
|
|
31
36
|
|
|
32
37
|
```bash
|
|
33
38
|
npx cornerstone-agent "Run a 30-day prediction for AAPL"
|
|
34
|
-
# Or interactive
|
|
35
39
|
npx cornerstone-agent
|
|
36
|
-
|
|
40
|
+
npm run agent -- "..."
|
|
41
|
+
node src/run-agent.js "..."
|
|
37
42
|
```
|
|
38
43
|
|
|
39
|
-
**x402 flow:** Agent calls tool without `payment_payload` → server returns 402 + `paymentRequirements` → agent signs, facilitator verify/settle → agent retries with `payment_payload` → receives result + `paymentReceipt`.
|
|
40
|
-
|
|
41
44
|
## Wallet attestation (signing)
|
|
42
45
|
|
|
43
|
-
To prove wallet ownership during onboarding, run from repo root:
|
|
44
|
-
|
|
45
46
|
- Aptos: `npm run attest:aptos` or `npx cornerstone-agent-attest-aptos` — output to POST /attest/aptos
|
|
46
47
|
- EVM: `npm run attest:evm` or `npx cornerstone-agent-attest-evm` — output to POST /attest/evm
|
|
47
48
|
|
|
48
|
-
##
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
## Tool reference
|
|
50
|
+
|
|
51
|
+
### Wallet tools (local)
|
|
52
|
+
| Tool | Args | Returns |
|
|
53
|
+
|------|------|---------|
|
|
54
|
+
| `get_wallet_addresses` | none | `{ aptos: [{ address, network }], evm: [...] }` |
|
|
55
|
+
| `create_aptos_wallet` | `{ force?, network? }` | `{ success, address, network }` |
|
|
56
|
+
| `create_evm_wallet` | `{ force?, network? }` | `{ success, address, network }` |
|
|
57
|
+
| `credit_aptos_wallet` | `{ amount_octas? }` | devnet: funds directly; testnet: `{ faucet_url, address }` |
|
|
58
|
+
| `fund_evm_wallet` | none | `{ faucet_url, address, message }` |
|
|
59
|
+
| `balance_aptos` | none | `{ address, balances: { usdc, apt } }` |
|
|
60
|
+
| `balance_evm` | `{ chain? }` | `{ address, chain, balance, symbol }` |
|
|
61
|
+
|
|
62
|
+
### Paid MCP tools (x402 — payment automatic)
|
|
63
|
+
| Tool | Args | Returns | Cost |
|
|
64
|
+
|------|------|---------|------|
|
|
65
|
+
| `run_prediction` | `{ symbol, horizon? }` | Forecast data | ~6¢ |
|
|
66
|
+
| `run_backtest` | `{ symbol, startDate?, endDate?, strategy? }` | Performance metrics | ~6¢ |
|
|
67
|
+
| `link_bank_account` | none | `{ link_token }` | ~5¢ |
|
|
68
|
+
| `get_agent_reputation_score` | `{ agent_address?, payer_wallet? }` | `{ reputation_score }` | ~6¢ or credits |
|
|
69
|
+
| `get_borrower_score` | `{ agent_address?, payer_wallet? }` | `{ score }` | ~6¢ or credits |
|
|
70
|
+
| `get_agent_reputation_score_by_email` | `{ email, payer_wallet? }` | `{ reputation_score }` | higher |
|
|
71
|
+
| `get_borrower_score_by_email` | `{ email, payer_wallet? }` | `{ score }` | higher |
|
|
72
|
+
|
|
73
|
+
Whitelist the addresses the agent uses at https://arnstein.ch/flow.html so the server allows those wallets.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornerstone-autonomous-agent",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "CornerStone
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "CornerStone MCP x402 skill for agents: tools to predict tickers, backtest strategies, link bank accounts, and query agent/borrower scores. Agents pay via Aptos/EVM (x402). Handles 402 → pay → retry. Publishable in marketplaces for autonomous download and use. Includes LangChain.js demo runner (Hugging Face / OpenAI-compatible).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/run-agent.js",
|
|
7
7
|
"bin": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@aptos-labs/ts-sdk": "^1.0.0"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|
|
54
|
-
"
|
|
54
|
+
"cornerstone-mcp",
|
|
55
55
|
"demo",
|
|
56
56
|
"autonomous-agent",
|
|
57
57
|
"x402",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"evm",
|
|
68
68
|
"crypto"
|
|
69
69
|
],
|
|
70
|
-
"author": "
|
|
70
|
+
"author": "CornerStone MCP",
|
|
71
71
|
"license": "GPL-2.0-only",
|
|
72
72
|
"repository": {
|
|
73
73
|
"type": "git",
|
package/skills/README.md
CHANGED
|
@@ -4,6 +4,6 @@ This folder follows the **AgentSkills** layout expected by MoltBook and OpenClaw
|
|
|
4
4
|
|
|
5
5
|
| Skill | Description |
|
|
6
6
|
|-------|-------------|
|
|
7
|
-
| [autonomous-agent](autonomous-agent/SKILL.md) | x402 MCP
|
|
7
|
+
| [autonomous-agent](autonomous-agent/SKILL.md) | x402 MCP skill for agents: stock prediction, backtest, link_bank_account, agent/borrower scores (Aptos + Base). Wallet attestation for onboarding. |
|
|
8
8
|
|
|
9
9
|
**Loading:** Add this repo path to `skills.load.extraDirs` in `~/.openclaw/openclaw.json` (MoltBook/OpenClaw will load `autonomous-agent` from `skills/autonomous-agent/`), or copy `autonomous-agent` into `~/.openclaw/skills/`, or use the repo as your OpenClaw workspace. See the main [README](../README.md#moltbook--openclaw).
|
|
@@ -1,62 +1,73 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: autonomous-agent
|
|
3
|
-
description:
|
|
3
|
+
description: CornerStone MCP x402 skill for agents. Tools for stock predictions, backtests, bank linking, and agent/borrower scores. Payment-protected MCP tools with x402 flow (Aptos + Base). Skill handles 402 → pay → retry. Wallet attestation for onboarding. For marketplaces where agents download and use skills autonomously.
|
|
4
4
|
metadata: {"openclaw":{"emoji":"📈","homepage":"https://github.com/FinTechTonic/autonomous-agent","requires":{"bins":["node","npm"]},"primaryEnv":"MCP_SERVER_URL","skillKey":"autonomous-agent"},"clawdbot":{"emoji":"📈","homepage":"https://github.com/FinTechTonic/autonomous-agent","requires":{"bins":["node","npm"]}}}
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# CornerStone MCP x402 Skill (for Agents)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Skill that gives **agents** tools to call x402-protected MCP endpoints: stock prediction, backtest, bank linking, and agent/borrower scores. **Payment is automatic** — the skill handles 402 → sign → verify → settle → retry transparently. Supports **wallet attestation** (signing) for onboarding (POST /attest/aptos, /attest/evm).
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
When this skill is loaded from the **autonomous-agent** repo, the repo root is the parent of the skill folder `{baseDir}`. Clone and install from the repo root:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
# From repository root (parent of {baseDir} when using this repo)
|
|
17
16
|
git clone https://github.com/FinTechTonic/autonomous-agent.git && cd autonomous-agent
|
|
18
17
|
npm install
|
|
19
18
|
```
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
Copy `.env.example` to `.env` and set:
|
|
22
21
|
|
|
23
|
-
- `
|
|
24
|
-
- `X402_FACILITATOR_URL` – x402 facilitator (verify/settle)
|
|
22
|
+
- set `X402_FACILITATOR_URL` too
|
|
25
23
|
- `LLM_BASE_URL`, `HUGGINGFACE_API_KEY` or `HF_TOKEN`, `LLM_MODEL` – for inference
|
|
26
24
|
- `APTOS_WALLET_PATH`, `EVM_WALLET_PATH` (or `EVM_PRIVATE_KEY`) – for payments
|
|
27
25
|
|
|
28
|
-
##
|
|
26
|
+
## Quick-start workflow
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
1. `get_wallet_addresses()` – check what wallets exist.
|
|
29
|
+
2. If empty: `create_aptos_wallet()` + `create_evm_wallet()`.
|
|
30
|
+
3. Fund: `credit_aptos_wallet()` + `fund_evm_wallet()`.
|
|
31
|
+
4. Whitelist addresses at https://arnstein.ch/sse/flow.html.
|
|
32
|
+
5. Check balances: `balance_aptos()`, `balance_evm({ chain: "baseSepolia" })`.
|
|
33
|
+
6. Call paid tools: `run_prediction`, `run_backtest`, `link_bank_account`, or score tools.
|
|
34
|
+
|
|
35
|
+
## Run the skill (demo)
|
|
31
36
|
|
|
32
37
|
```bash
|
|
33
38
|
npx cornerstone-agent "Run a 30-day prediction for AAPL"
|
|
34
|
-
# Or interactive
|
|
35
39
|
npx cornerstone-agent
|
|
36
|
-
|
|
40
|
+
npm run agent -- "..."
|
|
41
|
+
node src/run-agent.js "..."
|
|
37
42
|
```
|
|
38
43
|
|
|
39
|
-
**x402 flow:** Agent calls tool without `payment_payload` → server returns 402 + `paymentRequirements` → agent signs, facilitator verify/settle → agent retries with `payment_payload` → receives result + `paymentReceipt`.
|
|
40
|
-
|
|
41
44
|
## Wallet attestation (signing)
|
|
42
45
|
|
|
43
|
-
To prove wallet ownership during onboarding, run from repo root:
|
|
44
|
-
|
|
45
46
|
- Aptos: `npm run attest:aptos` or `npx cornerstone-agent-attest-aptos` — output to POST /attest/aptos
|
|
46
47
|
- EVM: `npm run attest:evm` or `npx cornerstone-agent-attest-evm` — output to POST /attest/evm
|
|
47
48
|
|
|
48
|
-
##
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
## Tool reference
|
|
50
|
+
|
|
51
|
+
### Wallet tools (local)
|
|
52
|
+
| Tool | Args | Returns |
|
|
53
|
+
|------|------|---------|
|
|
54
|
+
| `get_wallet_addresses` | none | `{ aptos: [{ address, network }], evm: [...] }` |
|
|
55
|
+
| `create_aptos_wallet` | `{ force?, network? }` | `{ success, address, network }` |
|
|
56
|
+
| `create_evm_wallet` | `{ force?, network? }` | `{ success, address, network }` |
|
|
57
|
+
| `credit_aptos_wallet` | `{ amount_octas? }` | devnet: funds directly; testnet: `{ faucet_url, address }` |
|
|
58
|
+
| `fund_evm_wallet` | none | `{ faucet_url, address, message }` |
|
|
59
|
+
| `balance_aptos` | none | `{ address, balances: { usdc, apt } }` |
|
|
60
|
+
| `balance_evm` | `{ chain? }` | `{ address, chain, balance, symbol }` |
|
|
61
|
+
|
|
62
|
+
### Paid MCP tools (x402 — payment automatic)
|
|
63
|
+
| Tool | Args | Returns | Cost |
|
|
64
|
+
|------|------|---------|------|
|
|
65
|
+
| `run_prediction` | `{ symbol, horizon? }` | Forecast data | ~6¢ |
|
|
66
|
+
| `run_backtest` | `{ symbol, startDate?, endDate?, strategy? }` | Performance metrics | ~6¢ |
|
|
67
|
+
| `link_bank_account` | none | `{ link_token }` | ~5¢ |
|
|
68
|
+
| `get_agent_reputation_score` | `{ agent_address?, payer_wallet? }` | `{ reputation_score }` | ~6¢ or credits |
|
|
69
|
+
| `get_borrower_score` | `{ agent_address?, payer_wallet? }` | `{ score }` | ~6¢ or credits |
|
|
70
|
+
| `get_agent_reputation_score_by_email` | `{ email, payer_wallet? }` | `{ reputation_score }` | higher |
|
|
71
|
+
| `get_borrower_score_by_email` | `{ email, payer_wallet? }` | `{ score }` | higher |
|
|
72
|
+
|
|
73
|
+
Whitelist the addresses the agent uses at https://arnstein.ch/sse/flow.html so the server allows those wallets.
|
package/src/agent/agent.js
CHANGED
|
@@ -1,53 +1,77 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LangChain.js ReAct
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
6
|
-
import { createLLM } from './llm.js';
|
|
7
|
-
import { createMcpTools } from './tools/mcpTools.js';
|
|
8
|
-
import { createLocalTools } from './tools/localTools.js';
|
|
9
|
-
|
|
10
|
-
const SYSTEM_MESSAGE = `You are an
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LangChain.js ReAct runner for the skill: MCP tools + local tools, Hugging Face LLM.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
6
|
+
import { createLLM } from './llm.js';
|
|
7
|
+
import { createMcpTools } from './tools/mcpTools.js';
|
|
8
|
+
import { createLocalTools } from './tools/localTools.js';
|
|
9
|
+
|
|
10
|
+
const SYSTEM_MESSAGE = `You are an agent with a skill that provides tools for wallet management and x402-paid MCP tools (predictions, backtests, bank linking, scores). Payment is automatic — just call the tool.
|
|
11
|
+
|
|
12
|
+
## ALWAYS DO FIRST
|
|
13
|
+
Before any paid or wallet action, call get_wallet_addresses (no args). It returns:
|
|
14
|
+
{ aptos: [{ address, network }], evm: [{ address, network }] }
|
|
15
|
+
- If aptos is empty and you need Aptos tools: create_aptos_wallet -> credit_aptos_wallet -> tell user to whitelist at https://arnstein.ch/flow.html
|
|
16
|
+
- If evm is empty and you need EVM tools: create_evm_wallet -> fund_evm_wallet -> tell user to whitelist at https://arnstein.ch/flow.html
|
|
17
|
+
- If wallets exist: check balance before paid calls. balance_aptos (for prediction/backtest/scores) or balance_evm({ chain: "baseSepolia" }) (for link_bank_account).
|
|
18
|
+
|
|
19
|
+
## TOOLS
|
|
20
|
+
|
|
21
|
+
Wallet tools:
|
|
22
|
+
- get_wallet_addresses() -> { aptos: [...], evm: [...] }
|
|
23
|
+
- create_aptos_wallet({ force?, network? }) -> { success, address, network }
|
|
24
|
+
- create_evm_wallet({ force?, network? }) -> { success, address, network }
|
|
25
|
+
- credit_aptos_wallet({ amount_octas? }) -> devnet: funds directly; testnet: returns faucet_url + instructions
|
|
26
|
+
- fund_evm_wallet() -> returns faucet_url + address (manual funding)
|
|
27
|
+
- balance_aptos() -> { address, balances: { usdc, apt } }
|
|
28
|
+
- balance_evm({ chain? }) -> { address, chain, balance, symbol }. Chains: base, baseSepolia, ethereum, polygon, arbitrum, optimism
|
|
29
|
+
|
|
30
|
+
Paid MCP tools (payment handled for you — just call them):
|
|
31
|
+
- run_prediction({ symbol, horizon? }) — stock prediction, ~6c USDC. Example: run_prediction({ symbol: "AAPL", horizon: 30 })
|
|
32
|
+
- run_backtest({ symbol, startDate?, endDate?, strategy? }) — backtest, ~6c. Dates "YYYY-MM-DD", strategy default "chronos"
|
|
33
|
+
- link_bank_account() — Plaid bank link, ~5c on Base. Needs funded EVM wallet (baseSepolia for testnet)
|
|
34
|
+
- get_agent_reputation_score({ agent_address?, payer_wallet? }) — reputation score
|
|
35
|
+
- get_borrower_score({ agent_address?, payer_wallet? }) — borrower score
|
|
36
|
+
- get_agent_reputation_score_by_email({ email, payer_wallet? }) — by email (needs SCORE_BY_EMAIL_ENABLED)
|
|
37
|
+
- get_borrower_score_by_email({ email, payer_wallet? }) — by email
|
|
38
|
+
|
|
39
|
+
## ERROR RECOVERY
|
|
40
|
+
- "No Aptos/EVM wallet" -> create the missing wallet
|
|
41
|
+
- "already exist" -> use existing wallet, or pass force: true to add another
|
|
42
|
+
- "Payment verification failed" -> insufficient funds; check balance, tell user to fund
|
|
43
|
+
- "403" / "not allowlisted" -> tell user to whitelist at https://arnstein.ch/flow.html
|
|
44
|
+
- Timeout -> retry once`;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create agent graph: llm + tools (MCP + local).
|
|
48
|
+
* @param {{ llm?: import('@langchain/core/language_models/chat_models').BaseChatModel; tools?: import('@langchain/core/tools').StructuredToolInterface[] }} options - llm and tools (if omitted, created from env and mcpClient)
|
|
49
|
+
* @param {{ callTool: (name: string, args: Object) => Promise<Object> }} [options.mcpClient] - required if tools not provided
|
|
50
|
+
* @returns {Promise<{ agent: import('@langchain/langgraph').CompiledStateGraph; runAgent: (message: string) => Promise<Object> }>}
|
|
51
|
+
*/
|
|
52
|
+
export async function createAgent(options = {}) {
|
|
53
|
+
const llm = options.llm || createLLM();
|
|
54
|
+
let tools = options.tools;
|
|
55
|
+
if (!tools && options.mcpClient) {
|
|
56
|
+
tools = [...createMcpTools(options.mcpClient), ...createLocalTools()];
|
|
57
|
+
}
|
|
58
|
+
if (!tools) {
|
|
59
|
+
throw new Error('Provide options.tools or options.mcpClient to createAgent.');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const agent = createReactAgent({
|
|
63
|
+
llm,
|
|
64
|
+
tools,
|
|
65
|
+
stateModifier: (state) => [{ role: 'system', content: SYSTEM_MESSAGE }, ...(state.messages || [])],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
async function runAgent(userMessage) {
|
|
69
|
+
const result = await agent.invoke(
|
|
70
|
+
{ messages: [{ role: 'user', content: userMessage }] },
|
|
71
|
+
{ recursionLimit: 50 }
|
|
72
|
+
);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { agent, runAgent };
|
|
77
|
+
}
|