@bnbagent/studio-cli 0.0.6-alpha.7 → 0.0.6-alpha.8
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/DISCLAIMER.md +6 -27
- package/README.md +6 -13
- package/dist/bag.js +920 -723
- package/dist/{chunk-VEOOFDSF.js → chunk-JZAW6HMV.js} +74 -5
- package/dist/{deployCli-EEK75T67.js → deployCli-AJ25A4VK.js} +1 -1
- package/package.json +2 -2
- package/recipes/providers/pieverse-llm/skills/funding-pieverse-llm.md +32 -64
- package/skills/bnbagent-studio.md +29 -74
- package/skills/references/bnbagent-studio-adding-to-project.md +58 -169
- package/skills/references/bnbagent-studio-buying-from-bazaar.md +43 -104
- package/skills/references/bnbagent-studio-buying-via-8183.md +38 -112
- package/skills/references/bnbagent-studio-extending-signing.md +47 -50
- package/skills/references/bnbagent-studio-operating.md +58 -110
- package/skills/references/bnbagent-studio-scaffolding-agent.md +134 -400
- package/skills/references/bnbagent-studio-selling-via-8183.md +87 -171
- package/skills/references/bnbagent-studio-selling-via-b402.md +39 -131
- package/skills/references/bnbagent-studio-use-aws-agentcore.md +42 -141
- package/skills/references/bnbagent-studio-use-azure-foundry.md +34 -95
- package/skills/references/bnbagent-studio-use-bnb-trial.md +12 -36
- package/skills/references/bnbagent-studio-using-altana-wallet.md +11 -28
- package/skills/references/bnbagent-studio-using-twak-wallet.md +102 -210
- package/skills/references/bnbagent-studio-wiring-llm-tools.md +71 -150
|
@@ -3,189 +3,99 @@ name: bnbagent-studio-adding-to-project
|
|
|
3
3
|
description: When the user wants to add bnbagent-studio's single ERC-8183 seller runtime (one valuable Agent on AWS Bedrock AgentCore that serves A2A by default or MCP optionally, holds the key, and signs in-process) to an existing TypeScript agent project.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
> **Reference file** of the `bnbagent-studio` router skill
|
|
6
|
+
> **Reference file** of the `bnbagent-studio` router skill - installed at `bnbagent-studio/references/` and loaded on demand (not a standalone skill). Route here via the router's decision tree.
|
|
7
7
|
|
|
8
8
|
# bnbagent-studio-adding-to-project
|
|
9
9
|
|
|
10
|
-
Procedure for adding `bnbagent-studio`'s **single selected-protocol seller** to an
|
|
11
|
-
**existing** TypeScript/Node repo. Audience: Claude Code (or another agent)
|
|
12
|
-
running with shell + edit access in the user's repo.
|
|
10
|
+
Procedure for adding `bnbagent-studio`'s **single selected-protocol seller** to an **existing** TypeScript/Node repo. Audience: Claude Code (or another agent) running with shell + edit access in the user's repo.
|
|
13
11
|
|
|
14
12
|
## The single seller runtime model (v1 workspace)
|
|
15
13
|
|
|
16
|
-
studio turns the user's existing valuable agent into a paid blockchain seller as
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
it is its own public HTTPS surface, gated by a mandatory Cognito OAuth2
|
|
24
|
-
authorizer. Owns its own `app/agent/package.json`, `app/agent/studio.toml`,
|
|
25
|
-
and `.studio/.env.local`; the keystore lives at the WORKSPACE root
|
|
26
|
-
`.studio/wallets/` (outside the AgentCore codeLocation, so no deploy packaging
|
|
27
|
-
path can bundle it — at deploy it is injected via AWS Secrets Manager as
|
|
28
|
-
`WALLET_KEYSTORE_JSON`). The outward surface is A2A's `SellerAgentExecutor`
|
|
29
|
-
(`negotiate` / `notify_funded` skills) or the MCP server's tools with the same
|
|
30
|
-
bounded operations; ALL signing is fixed `app/agent/src/signing.ts` code,
|
|
31
|
-
never an LLM tool.
|
|
32
|
-
|
|
33
|
-
There is **no** second service: the Agent signs in-process and answers buyers
|
|
34
|
-
directly over its selected protocol. (The earlier two-layer split — an
|
|
35
|
-
invoke-only Agent plus a public keyless EC2 service relaying to it — was removed
|
|
36
|
-
once AgentCore could serve the protocol surface on a public endpoint; see
|
|
37
|
-
`docs/design/single-seller-agent.md` for the A2A decision history.)
|
|
38
|
-
|
|
39
|
-
"Adding to an existing project" in v1 means **scaffolding a fresh workspace and
|
|
40
|
-
migrating your value into it** — `bag init` always creates a *new* workspace
|
|
41
|
-
directory (there is no in-place adoption); you then move your existing agent's
|
|
42
|
-
LLM / tools / memory code into the generated `app/agent/` sub-project.
|
|
14
|
+
studio turns the user's existing valuable agent into a paid blockchain seller as a **thin workspace root with one sub-project** under it:
|
|
15
|
+
|
|
16
|
+
- **Agent (`app/agent/` sub-project, → AWS Bedrock AgentCore).** The user's agent value (LLM / memory / tools / KB) AND the **sole key-holder/signer**. AgentCore runs the container with the selected protocol (A2A: `0.0.0.0:9000`; MCP: `0.0.0.0:8000/mcp`), so the Agent **serves directly** - it is its own public HTTPS surface, gated by a mandatory Cognito OAuth2 authorizer. Owns its own `app/agent/package.json`, `app/agent/studio.toml`, and `.studio/.env.local`; the keystore lives at the WORKSPACE root `.studio/wallets/` (outside the AgentCore codeLocation, so no deploy packaging path can bundle it - at deploy it is injected via AWS Secrets Manager as `WALLET_KEYSTORE_JSON`). The outward surface is A2A's `SellerAgentExecutor` (`negotiate` / `notify_funded` skills) or the MCP server's tools with the same bounded operations; ALL signing is fixed `app/agent/src/signing.ts` code, never an LLM tool.
|
|
17
|
+
|
|
18
|
+
There is **no** second service: the Agent signs in-process and answers buyers directly over its selected protocol. (The earlier two-layer split - an invoke-only Agent plus a public keyless EC2 service relaying to it - was removed once AgentCore could serve the protocol surface on a public endpoint; see `docs/design/single-seller-agent.md` for the A2A decision history.)
|
|
19
|
+
|
|
20
|
+
"Adding to an existing project" in v1 means **scaffolding a fresh workspace and migrating your value into it** - `bag init` always creates a _new_ workspace directory (there is no in-place adoption); you then move your existing agent's LLM / tools / memory code into the generated `app/agent/` sub-project.
|
|
43
21
|
|
|
44
22
|
v1 is **seller-only**; chat / buyer roles are deferred to v2.
|
|
45
23
|
|
|
46
24
|
## Preconditions
|
|
47
25
|
|
|
48
26
|
- The repo is a TypeScript/Node project (has a `package.json`).
|
|
49
|
-
- The user has Node.js ≥22 and can install the CLI
|
|
27
|
+
- The user has Node.js ≥22 and can install the CLI - `npm install -g @bnbagent/studio-cli` (auto-pulls the `@bnbagent/studio-runtime` lib); for local dev use a monorepo clone (`pnpm install` at the workspace root).
|
|
50
28
|
- Network access to BSC testnet RPC (default: `https://data-seed-prebsc-1-s1.binance.org:8545`).
|
|
51
29
|
|
|
52
|
-
## Step 1
|
|
30
|
+
## Step 1 - Bootstrap studio config
|
|
53
31
|
|
|
54
|
-
Check for the v1 workspace layout
|
|
55
|
-
`studio.toml`):
|
|
32
|
+
Check for the v1 workspace layout - `app/agent/studio.toml` (not a root-level `studio.toml`):
|
|
56
33
|
|
|
57
34
|
```bash
|
|
58
35
|
ls app/agent/studio.toml 2>/dev/null || echo MISSING
|
|
59
36
|
```
|
|
60
37
|
|
|
61
|
-
If missing, scaffold a new workspace. `bag init <name>` **always creates a new
|
|
62
|
-
directory `<name>/` under the current working directory** — it does not adopt the
|
|
63
|
-
current repo in place. Pick a workspace name, then migrate your existing agent's
|
|
64
|
-
value into the generated `app/agent/` sub-project (Step 4):
|
|
38
|
+
If missing, scaffold a new workspace. `bag init <name>` **always creates a new directory `<name>/` under the current working directory** - it does not adopt the current repo in place. Pick a workspace name, then migrate your existing agent's value into the generated `app/agent/` sub-project (Step 4):
|
|
65
39
|
|
|
66
40
|
```bash
|
|
67
|
-
bag init
|
|
41
|
+
bag init myagent && cd myagent # creates ./myagent/ with the single app/agent/ sub-project
|
|
68
42
|
```
|
|
69
43
|
|
|
70
|
-
**Scaffold note:** while the trial campaign runs, bare `bag init` defaults to
|
|
71
|
-
`--destination platform` (the 48h managed-platform testnet trial — no AWS
|
|
72
|
-
account needed). Pass `--destination self` to make AWS the scaffold intent.
|
|
73
|
-
Both AgentCore variants include a Studio-rendered local deploy descriptor so a
|
|
74
|
-
later explicit AWS deployment does not require re-scaffolding. Deploy provider
|
|
75
|
-
selection remains explicit in Step 5.
|
|
44
|
+
**Scaffold note:** while the trial campaign runs, bare `bag init` defaults to `--destination platform` (the 48h managed-platform testnet trial - no AWS account needed). Pass `--destination self` to make AWS the scaffold intent. Both AgentCore variants include a Studio-rendered local deploy descriptor so a later explicit AWS deployment does not require re-scaffolding. Deploy provider selection remains explicit in Step 5.
|
|
76
45
|
|
|
77
|
-
Verify the workspace tree: `app/agent/studio.toml`, `.studio/.env.local`,
|
|
78
|
-
`.studio/wallets/` at the root, and `.gitignore` at root + sub-project. A
|
|
79
|
-
runtime=`agentcore` scaffolds (including platform-destined ones) also have
|
|
80
|
-
`agentcore/agentcore.json` + `agentcore/aws-targets.json`. The managed BNB
|
|
81
|
-
platform does not consume those local AWS files; they exist only to permit a
|
|
82
|
-
later explicit `bag deploy --provider aws` choice.
|
|
46
|
+
Verify the workspace tree: `app/agent/studio.toml`, `.studio/.env.local`, `.studio/wallets/` at the root, and `.gitignore` at root + sub-project. A runtime=`agentcore` scaffolds (including platform-destined ones) also have `agentcore/agentcore.json` + `agentcore/aws-targets.json`. The managed BNB platform does not consume those local AWS files; they exist only to permit a later explicit `bag deploy --provider aws` choice.
|
|
83
47
|
|
|
84
|
-
## Step 2
|
|
48
|
+
## Step 2 - Detect framework (best-effort)
|
|
85
49
|
|
|
86
50
|
```bash
|
|
87
51
|
bag scan
|
|
88
52
|
```
|
|
89
53
|
|
|
90
|
-
**v1 note**: `scan` is a stub
|
|
91
|
-
its decisions; ask the user what their existing agent is built with (AI SDK /
|
|
92
|
-
LangChain.js / a custom express service) before emitting recipes.
|
|
54
|
+
**v1 note**: `scan` is a stub - it just reports detected files. Don't rely on its decisions; ask the user what their existing agent is built with (AI SDK / LangChain.js / a custom express service) before emitting recipes.
|
|
93
55
|
|
|
94
|
-
## Step 3
|
|
56
|
+
## Step 3 - Emit the agent
|
|
95
57
|
|
|
96
|
-
A seller is the single Agent serving the selected protocol. `bag init` already
|
|
97
|
-
composes it from recipes — `agent` (the fixed-code `src/signing.ts`) and
|
|
98
|
-
`runtimes/agentcore` (A2A: `src/main.ts` (the express + A2A entrypoint) +
|
|
99
|
-
`src/sellerCore.ts` (the protocol-neutral core; executor inherits it) +
|
|
100
|
-
`src/executor.ts` + `src/agentCard.ts`; MCP: `src/mcpMain.ts`; shared
|
|
101
|
-
`src/tools.ts` + `src/model.ts` + `Dockerfile`).
|
|
102
|
-
Use `bag recipe code` to inspect or re-emit a piece:
|
|
58
|
+
A seller is the single Agent serving the selected protocol. `bag init` already composes it from recipes - `agent` (the fixed-code `src/signing.ts`) and `runtimes/agentcore` (A2A: `src/main.ts` (the express + A2A entrypoint) + `src/sellerCore.ts` (the protocol-neutral core; executor inherits it) + `src/executor.ts` + `src/agentCard.ts`; MCP: `src/mcpMain.ts`; shared `src/tools.ts` + `src/model.ts`; a `Dockerfile` is added only for a container deployment path such as TWAK). Use `bag recipe code` to inspect or re-emit a piece:
|
|
103
59
|
|
|
104
60
|
```bash
|
|
105
61
|
bag recipe code agent > /dev/null # inspect; bag init writes app/agent/src/signing.ts for you
|
|
106
62
|
bag recipe code runtimes/agentcore > /dev/null # inspect; bag init writes the A2A serving files for you
|
|
107
63
|
```
|
|
108
64
|
|
|
109
|
-
In practice `bag init` already scaffolds `app/agent/`. Use `bag recipe code agent`
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
the
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
FREE in `bag doctor`. Zero funding also requires commerce, router, and policy
|
|
137
|
-
from one compatible stack: set all three `ERC8183_*_ADDRESS` overrides, then
|
|
138
|
-
require `bag doctor` and `bag deploy prepare` to pass. The buyer still runs
|
|
139
|
-
`setBudget(0)` and `fund(0)`, but no ERC-20 approval or token escrow occurs.
|
|
140
|
-
|
|
141
|
-
For an X402 face, choose its request price independently. Use
|
|
142
|
-
`bag config set payments.x402_seller.price_usd 0` only when the existing agent
|
|
143
|
-
is intentionally becoming an unrestricted anonymous FREE API. This path
|
|
144
|
-
bypasses B402 verify/settle, payment, and settlement audit; it needs no merchant
|
|
145
|
-
credentials and Studio will not synchronize any configured B402 secrets.
|
|
146
|
-
Positive prices retain the paid B402 onboarding and settle-before-work flow.
|
|
147
|
-
Verify the choice with `bag x402 sell status`, `bag doctor`, and
|
|
148
|
-
`bag deploy prepare`.
|
|
149
|
-
|
|
150
|
-
## Step 4c — LLM credit continuity (automatic, NOT an LLM tool)
|
|
151
|
-
|
|
152
|
-
For Pieverse projects, the Agent's `buildModel()` factory in the emitted
|
|
153
|
-
`app/agent/src/model.ts` returns an AI SDK model wrapped with credit-ensure
|
|
154
|
-
middleware. Its **automatic, budget-gated auto-renew hook** (the stack-neutral
|
|
155
|
-
logic lives in `@bnbagent/studio-runtime/pieverse` `PieverseCreditEnsurer`;
|
|
156
|
-
the AI-SDK shell is the emitted file) tops up the active Pieverse key from the
|
|
157
|
-
wallet (when
|
|
158
|
-
`[budget].enabled = true`) before an LLM call whose cached balance is below
|
|
159
|
-
`[llm.auto_renew].min_balance_usd`. The Agent keeps delivering jobs even if it
|
|
160
|
-
runs low mid-shift — the resilience is transparent.
|
|
161
|
-
|
|
162
|
-
Crucially this is **not** an LLM tool. It rides on the hardened x402 buyer
|
|
163
|
-
kernel (`@bnbagent/studio-runtime/x402`, the payment signer) — but the Agent
|
|
164
|
-
(the sole key-holder) drives it transparently inside the model wrapper; the LLM
|
|
165
|
-
never decides to spend. The LLM-credit self-top-up you get for free is the
|
|
166
|
-
managed-model auto-renew hook described above.
|
|
167
|
-
|
|
168
|
-
If the budget gate is off / exhausted, the hook raises
|
|
169
|
-
`PieverseAccountBalanceExhaustedError` — let it surface so the buyer can dispute;
|
|
170
|
-
refill with `bag llm topup` or enable the budget with `bag budget enable`.
|
|
171
|
-
|
|
172
|
-
## Step 5 — Deploy the agent
|
|
173
|
-
|
|
174
|
-
`bag deploy` always asks the operator to choose BNB or AWS; it never
|
|
175
|
-
silently reuses `[deploy].destination` or the last provider.
|
|
176
|
-
|
|
177
|
-
**Platform scaffold** (the bare-init default while the campaign runs) — one
|
|
178
|
-
command; first run does a GitHub device-flow login, the wallet key goes to the
|
|
179
|
-
operator's Secrets Manager (testnet-forced, use a throwaway wallet):
|
|
65
|
+
In practice `bag init` already scaffolds `app/agent/`. Use `bag recipe code agent` / `bag recipe code runtimes/agentcore` to inspect or re-emit (emits under `{{PKG}}` = the agent's `src/` dir, or pass `--pkg <name>` explicitly).
|
|
66
|
+
|
|
67
|
+
Gotcha: token is **U** (USD-pegged stablecoin on BSC), not BNB. All ERC-8183 amounts are denominated in U.
|
|
68
|
+
|
|
69
|
+
## Step 4 - Wire your existing agent's value into the Agent
|
|
70
|
+
|
|
71
|
+
The Agent sub-project (`app/agent/`) is where your existing valuable agent lives. Move your LLM construction / tools / memory / KB wiring into it, and implement the `runWork` developer hook (in `app/agent/src/sellerCore.ts` for A2A, `app/agent/src/mcpMain.ts` for MCP; called from `notify_funded`'s delivery) to produce the deliverable. Read-only chain tools go in `app/agent/src/tools.ts` (see `bnbagent-studio-wiring-llm-tools`). ALL signing stays in `app/agent/src/signing.ts` - never expose a signing call as an LLM tool.
|
|
72
|
+
|
|
73
|
+
Tune the price in `app/agent/studio.toml` (`[payments.erc8183]` `min_price`/ `max_price`): the `negotiate` path is **rule-based, no LLM** - fixed code takes the configured list price, clamps it to `[min_price, max_price]`, then `signing.ts` EIP-191-signs the offer. For per-task pricing, compute the price from the request _before_ clamping - the LLM still never sets the price. The buyer anchors the signed envelope on-chain via `createJob` + `fund`.
|
|
74
|
+
|
|
75
|
+
Use `bag config set payments.erc8183.price 0` only for an explicit FREE product decision. Studio stores ERC-8183 amounts as decimal strings and reports FREE in `bag doctor`. Zero funding also requires commerce, router, and policy from one compatible stack: set all three `ERC8183_*_ADDRESS` overrides, then require `bag doctor` and `bag deploy prepare` to pass. The buyer still runs `setBudget(0)` and `fund(0)`, but no ERC-20 approval or token escrow occurs.
|
|
76
|
+
|
|
77
|
+
For an X402 face, choose its request price independently. Use `bag config set payments.x402_seller.price_usd 0` only when the existing agent is intentionally becoming an unrestricted anonymous FREE API. This path bypasses B402 verify/settle, payment, and settlement audit; it needs no merchant credentials and Studio will not synchronize any configured B402 secrets. Positive prices retain the paid B402 onboarding and settle-before-work flow. Verify the choice with `bag x402 sell status`, `bag doctor`, and `bag deploy prepare`.
|
|
78
|
+
|
|
79
|
+
## Step 4c - LLM credit continuity (automatic, NOT an LLM tool)
|
|
80
|
+
|
|
81
|
+
For Pieverse projects, the Agent's `buildModel()` factory in the emitted `app/agent/src/model.ts` returns an AI SDK model wrapped with credit-ensure middleware. Its **automatic, budget-gated auto-renew hook** (the stack-neutral logic lives in `@bnbagent/studio-runtime/pieverse` `PieverseCreditEnsurer`; the AI-SDK shell is the emitted file) tops up the active Pieverse key from the wallet (when `[budget].enabled = true`) before an LLM call whose cached balance is below `[llm.auto_renew].min_balance_usd`. The Agent keeps delivering jobs even if it runs low mid-shift - the resilience is transparent.
|
|
82
|
+
|
|
83
|
+
Crucially this is **not** an LLM tool. It rides on the hardened x402 buyer kernel (`@bnbagent/studio-runtime/x402`, the payment signer) - but the Agent (the sole key-holder) drives it transparently inside the model wrapper; the LLM never decides to spend. The LLM-credit self-top-up you get for free is the managed-model auto-renew hook described above.
|
|
84
|
+
|
|
85
|
+
If the budget gate is off / exhausted, the hook raises `PieverseAccountBalanceExhaustedError` - let it surface so the buyer can dispute; refill with `bag llm topup` or enable the budget with `bag budget enable`.
|
|
86
|
+
|
|
87
|
+
## Step 5 - Deploy the agent
|
|
88
|
+
|
|
89
|
+
`bag deploy` always asks the operator to choose BNB or AWS; it never silently reuses `[deploy].destination` or the last provider.
|
|
90
|
+
|
|
91
|
+
**Platform scaffold** (the bare-init default while the campaign runs) - one command; first run does a GitHub device-flow login, the wallet key goes to the operator's Secrets Manager (testnet-forced, use a throwaway wallet):
|
|
180
92
|
|
|
181
93
|
```bash
|
|
182
94
|
bag platform login # prints GitHub device URL + code; does not open a browser
|
|
183
95
|
bag deploy --provider bnb # ship to the managed platform (48h testnet trial)
|
|
184
96
|
```
|
|
185
97
|
|
|
186
|
-
**Self-deploy scaffold** (`--destination self`)
|
|
187
|
-
protocol directly behind a mandatory Cognito authorizer; register
|
|
188
|
-
ERC-8004/8183 **last** with the deployed AgentCore endpoint:
|
|
98
|
+
**Self-deploy scaffold** (`--destination self`) - the Agent serves the selected protocol directly behind a mandatory Cognito authorizer; register ERC-8004/8183 **last** with the deployed AgentCore endpoint:
|
|
189
99
|
|
|
190
100
|
```bash
|
|
191
101
|
bag deploy prepare # readiness sweep
|
|
@@ -193,42 +103,29 @@ bag deploy --provider aws # ship the Agent to AgentCore
|
|
|
193
103
|
bag deploy verify --provider aws # delegated status + reconcile ERC-8004 identity
|
|
194
104
|
```
|
|
195
105
|
|
|
196
|
-
Gotcha: `bag deploy --provider aws` provisions the Cognito user pool and the
|
|
197
|
-
buyer M2M client itself and prints the token URL, client id, and scope — hand
|
|
198
|
-
those to each buyer (Cognito has no public M2M self-registration; retrieve the
|
|
199
|
-
client secret read-only from the AWS Console). Do not run
|
|
200
|
-
`bag deploy provision-cognito`: it is deprecated and its CDK pool is never used
|
|
201
|
-
by a deploy.
|
|
106
|
+
Gotcha: `bag deploy --provider aws` provisions the Cognito user pool and the buyer M2M client itself and prints the token URL, client id, and scope - hand those to each buyer (Cognito has no public M2M self-registration; retrieve the client secret read-only from the AWS Console). Do not run `bag deploy provision-cognito`: it is deprecated and its CDK pool is never used by a deploy.
|
|
202
107
|
|
|
203
|
-
Gotcha: `dispute_window` is read from the on-chain policy contract (24h on
|
|
204
|
-
testnet). Buyers can dispute within that window after submit — the Agent can't
|
|
205
|
-
claim funds until the window closes.
|
|
108
|
+
Gotcha: `dispute_window` is read from the on-chain policy contract (24h on testnet). Buyers can dispute within that window after submit - the Agent can't claim funds until the window closes.
|
|
206
109
|
|
|
207
|
-
## Step 6
|
|
110
|
+
## Step 6 - Verify
|
|
208
111
|
|
|
209
112
|
```bash
|
|
210
113
|
bag doctor # run from workspace root; scans the agent sub-project
|
|
211
114
|
```
|
|
212
115
|
|
|
213
|
-
Should show green for: `app/agent/studio.toml` present, wallet decryptable (needs
|
|
214
|
-
`WALLET_PASSWORD` set in `.studio/.env.local`), RPC reachable, 8004 identity
|
|
215
|
-
registered (if applicable), LLM key present (if `[llm]` configured in
|
|
216
|
-
`app/agent/studio.toml`).
|
|
116
|
+
Should show green for: `app/agent/studio.toml` present, wallet decryptable (needs `WALLET_PASSWORD` set in `.studio/.env.local`), RPC reachable, 8004 identity registered (if applicable), LLM key present (if `[llm]` configured in `app/agent/studio.toml`).
|
|
217
117
|
|
|
218
118
|
If anything is red, fix and re-run `bag doctor` before deploying.
|
|
219
119
|
|
|
220
|
-
## Step 7
|
|
120
|
+
## Step 7 - Smoke test the Agent locally
|
|
221
121
|
|
|
222
|
-
`bag dev` from the workspace root launches the Agent with the selected protocol.
|
|
223
|
-
Locally it runs without Cognito env, so the A2A card / MCP metadata is reachable
|
|
224
|
-
without a token:
|
|
122
|
+
`bag dev` from the workspace root launches the Agent with the selected protocol. Locally it runs without Cognito env, so the A2A card / MCP metadata is reachable without a token:
|
|
225
123
|
|
|
226
124
|
```bash
|
|
227
125
|
bag dev # A2A on :9000, or MCP on :8000/mcp
|
|
228
126
|
```
|
|
229
127
|
|
|
230
|
-
For A2A projects, in another shell, fetch the card and send a `negotiate` message
|
|
231
|
-
(`message/send` JSON-RPC with a single `DataPart`):
|
|
128
|
+
For A2A projects, in another shell, fetch the card and send a `negotiate` message (`message/send` JSON-RPC with a single `DataPart`):
|
|
232
129
|
|
|
233
130
|
```bash
|
|
234
131
|
curl -s http://localhost:9000/.well-known/agent-card.json # 2 skills: negotiate / notify_funded
|
|
@@ -238,20 +135,12 @@ curl -X POST http://localhost:9000/ \
|
|
|
238
135
|
-d '{"jsonrpc":"2.0","id":1,"method":"message/send","params":{"message":{"role":"user","messageId":"nego-1","parts":[{"kind":"data","data":{"skill":"negotiate","task_description":"summarize a webpage"}}]}}}'
|
|
239
136
|
```
|
|
240
137
|
|
|
241
|
-
The reply data part is the SDK `NegotiationResult` envelope, signed by the agent:
|
|
242
|
-
the quoted `price`, `currency`, and the signature fields (`negotiation_hash`,
|
|
243
|
-
`provider_sig`). The buyer anchors it on-chain via `createJob` + `fund`, then
|
|
244
|
-
sends a `notify_funded` message; the agent acks `accepted` at once and delivers in
|
|
245
|
-
the background, and the buyer reads the result from the chain (SUBMITTED →
|
|
246
|
-
`deliverable_url`). For MCP projects, connect an MCP client to
|
|
247
|
-
`http://localhost:8000/mcp`; `notify_funded` verifies, runs the work, and submits
|
|
248
|
-
synchronously inside the tool call (see `bnbagent-studio-selling-via-8183.md` (same directory) and
|
|
249
|
-
`docs/design/erc8183-buyer-push.md`).
|
|
138
|
+
The reply data part is the SDK `NegotiationResult` envelope, signed by the agent: the quoted `price`, `currency`, and the signature fields (`negotiation_hash`, `provider_sig`). The buyer anchors it on-chain via `createJob` + `fund`, then sends a `notify_funded` message; the agent acks `accepted` at once and delivers in the background, and the buyer reads the result from the chain (SUBMITTED → `deliverable_url`). For MCP projects, connect an MCP client to `http://localhost:8000/mcp`; `notify_funded` verifies, runs the work, and submits synchronously inside the tool call (see `bnbagent-studio-selling-via-8183.md` (same directory) and `docs/design/erc8183-buyer-push.md`).
|
|
250
139
|
|
|
251
140
|
## Reference
|
|
252
141
|
|
|
253
142
|
- `docs/design/single-seller-agent.md` (the A2A deploy model and history).
|
|
254
143
|
- `docs/design/erc8183-buyer-push.md` (how a buyer drives a sale: negotiate → fund → notify_funded).
|
|
255
144
|
- `docs/design/decisions.md` (single seller runtime + protocol-choice decision records).
|
|
256
|
-
- `docs/design/architecture.md` (recipes, selected-protocol runtime, project layout
|
|
257
|
-
- `bnbagent-studio-selling-via-8183.md` (same directory)
|
|
145
|
+
- `docs/design/architecture.md` (recipes, selected-protocol runtime, project layout - §2.5 / §9.2).
|
|
146
|
+
- `bnbagent-studio-selling-via-8183.md` (same directory) - the runtime seller flow (negotiate, notify_funded, submit, and dispute defense); buyer settlement lives in the buying reference.
|
|
@@ -1,69 +1,45 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: bnbagent-studio-buying-from-bazaar
|
|
3
|
-
description: When the user wants their agent to buy a paid x402 capability
|
|
3
|
+
description: When the user wants their agent to buy a paid x402 capability - market data, inference, any pay-per-call API - from the Binance Bazaar (B402) or any other x402 service. Owns discovery (browse the Bazaar / studio recommendations), trusting a merchant (`bag x402 trust`), wiring the buyer @tools (x402-buyer recipe), verifying with a paid test call, and the mainnet-money caveats.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
> **Reference file** of the `bnbagent-studio` router skill
|
|
7
|
-
> `bnbagent-studio/references/` and loaded on demand (not a standalone skill).
|
|
8
|
-
> Route here via the router's decision tree.
|
|
6
|
+
> **Reference file** of the `bnbagent-studio` router skill - installed at `bnbagent-studio/references/` and loaded on demand (not a standalone skill). Route here via the router's decision tree.
|
|
9
7
|
|
|
10
8
|
# bnbagent-studio-buying-from-bazaar
|
|
11
9
|
|
|
12
|
-
Procedure to give an agent a **paid capability**: the agent calls an
|
|
13
|
-
x402-protected API (e.g. CoinMarketCap market data), receives a `402 Payment
|
|
14
|
-
Required`, signs a $U payment locally, retries, and gets the data — all
|
|
15
|
-
automatic at runtime. This is the buyer counterpart of what the seller side
|
|
16
|
-
already does over x402.
|
|
10
|
+
Procedure to give an agent a **paid capability**: the agent calls an x402-protected API (e.g. CoinMarketCap market data), receives a `402 Payment Required`, signs a $U payment locally, retries, and gets the data - all automatic at runtime. This is the buyer counterpart of what the seller side already does over x402.
|
|
17
11
|
|
|
18
12
|
**The three roles, kept separate** (do not conflate):
|
|
19
13
|
|
|
20
|
-
- **Bazaar** (`https://www.binance.com/bapi/ramp/v1/public/ramp/b402/bazaar/…`)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- **The merchant** (e.g. CMC) — the agent talks to it **directly**: request →
|
|
24
|
-
402 → signed retry → data.
|
|
25
|
-
- **B402 facilitator** (verify/settle, gas fronted) — the **merchant's**
|
|
26
|
-
payment plumbing. The agent never calls it.
|
|
14
|
+
- **Bazaar** (`https://www.binance.com/bapi/ramp/v1/public/ramp/b402/bazaar/…`) - a public, auth-free **catalog** of x402 merchants. It is never in the data path and never in the payment path.
|
|
15
|
+
- **The merchant** (e.g. CMC) - the agent talks to it **directly**: request → 402 → signed retry → data.
|
|
16
|
+
- **B402 facilitator** (verify/settle, gas fronted) - the **merchant's** payment plumbing. The agent never calls it.
|
|
27
17
|
|
|
28
|
-
**Recommendation, not admission**: studio ships a reviewed shelf
|
|
29
|
-
(the CLI's built-in recommended-merchants table — today: CMC's 4 market-data
|
|
30
|
-
endpoints), but
|
|
31
|
-
any x402 service can be trusted by URL. Studio recommends; it never
|
|
32
|
-
gate-keeps the user's own spending choices.
|
|
18
|
+
**Recommendation, not admission**: studio ships a reviewed shelf (the CLI's built-in recommended-merchants table - today: CMC's 4 market-data endpoints), but any x402 service can be trusted by URL. Studio recommends; it never gate-keeps the user's own spending choices.
|
|
33
19
|
|
|
34
|
-
## Step 0
|
|
20
|
+
## Step 0 - know what's on offer
|
|
35
21
|
|
|
36
|
-
Studio-reviewed (the fast path): run `bag x402 trust cmc` and skip to Step 1.
|
|
37
|
-
CMC's 4 endpoints (all `$0.01/call`, base `https://pro-api.coinmarketcap.com`):
|
|
22
|
+
Studio-reviewed (the fast path): run `bag x402 trust cmc` and skip to Step 1. CMC's 4 endpoints (all `$0.01/call`, base `https://pro-api.coinmarketcap.com`):
|
|
38
23
|
|
|
39
24
|
| Endpoint | Path | Good for |
|
|
40
|
-
|
|
25
|
+
| --- | --- | --- |
|
|
41
26
|
| Quotes Latest | `/x402/v3/cryptocurrency/quotes/latest?id=1` | prices, holdings briefs, price alerts |
|
|
42
27
|
| Listings Latest | `/x402/v3/cryptocurrency/listings/latest?start=1&limit=10` | top-N market overviews, rotation signals |
|
|
43
28
|
| DEX Search | `/x402/v1/dex/search?q=bnb` | new-token discovery, name checks |
|
|
44
29
|
| DEX Pairs Quotes | `/x402/v4/dex/pairs/quotes/latest?pair_address=0x…` | pool liquidity/volume, LP monitoring |
|
|
45
30
|
|
|
46
|
-
Browsing the wider Bazaar (optional): the discovery API is public JSON
|
|
47
|
-
`GET …/bazaar/search?query=<keyword>&limit=10`, `…/bazaar/resources`,
|
|
48
|
-
`…/bazaar/merchant?payTo=0x…`. Each resource carries `accepts[]` (who gets
|
|
49
|
-
paid, in what asset, on which chain) and 30-day quality signals
|
|
50
|
-
(`l30DaysTotalCalls`, `l30DaysUniquePayers`). Merchants found there are
|
|
51
|
-
**unreviewed** — trust them by URL only after checking the payTo out-of-band.
|
|
31
|
+
Browsing the wider Bazaar (optional): the discovery API is public JSON - `GET …/bazaar/search?query=<keyword>&limit=10`, `…/bazaar/resources`, `…/bazaar/merchant?payTo=0x…`. Each resource carries `accepts[]` (who gets paid, in what asset, on which chain) and 30-day quality signals (`l30DaysTotalCalls`, `l30DaysUniquePayers`). Merchants found there are **unreviewed** - trust them by URL only after checking the payTo out-of-band.
|
|
52
32
|
|
|
53
|
-
> Doc lag warning: a merchant's human docs may lag its live 402 (CMC's page
|
|
54
|
-
> documents only Base/USDC; the live challenge also accepts BSC $U via
|
|
55
|
-
> EIP-3009). Machine decisions always come from the live `accepts[]` — which
|
|
56
|
-
> is exactly what `bag x402 trust` and `bag x402 quote` read.
|
|
33
|
+
> Doc lag warning: a merchant's human docs may lag its live 402 (CMC's page documents only Base/USDC; the live challenge also accepts BSC $U via EIP-3009). Machine decisions always come from the live `accepts[]` - which is exactly what `bag x402 trust` and `bag x402 quote` read.
|
|
57
34
|
|
|
58
|
-
## Step 1
|
|
35
|
+
## Step 1 - trust the merchant (writes config, never pays)
|
|
59
36
|
|
|
60
37
|
```bash
|
|
61
38
|
bag x402 trust cmc # studio-reviewed: pinned payTo byte-compared vs live 402
|
|
62
39
|
bag x402 trust https://api.example.com/thing --cap 0.05 # any other x402 service (unreviewed)
|
|
63
40
|
```
|
|
64
41
|
|
|
65
|
-
What it does: probes the live 402 (free), shows **who gets paid and how much
|
|
66
|
-
per call**, then — after your explicit confirmation — writes:
|
|
42
|
+
What it does: probes the live 402 (free), shows **who gets paid and how much per call**, then - after your explicit confirmation - writes:
|
|
67
43
|
|
|
68
44
|
```toml
|
|
69
45
|
[payments.x402.merchants.cmc]
|
|
@@ -73,19 +49,15 @@ per_call_cap_usd = 0.02 # clamps every call, LLM
|
|
|
73
49
|
verified = true # studio-reviewed shelf
|
|
74
50
|
```
|
|
75
51
|
|
|
76
|
-
Hard-stop cases: a reviewed merchant whose live payTo drifts from the studio
|
|
77
|
-
pin (address rotation or tampering — upgrade studio or verify out-of-band and
|
|
78
|
-
pass `--pay-to`), and `--cap` below the live per-call price.
|
|
52
|
+
Hard-stop cases: a reviewed merchant whose live payTo drifts from the studio pin (address rotation or tampering - upgrade studio or verify out-of-band and pass `--pay-to`), and `--cap` below the live per-call price.
|
|
79
53
|
|
|
80
|
-
## Step 2
|
|
54
|
+
## Step 2 - wire the buyer tools into the agent
|
|
81
55
|
|
|
82
56
|
```bash
|
|
83
57
|
bag recipe code x402-buyer # emits src/x402Buyer.ts (next to src/tools.ts)
|
|
84
58
|
```
|
|
85
59
|
|
|
86
|
-
Then wire the set into the agent's LLM in `src/main.ts` (A2A) or
|
|
87
|
-
`src/mcpMain.ts` (MCP) — the scaffold's `tools:` line carries this exact hint
|
|
88
|
-
in a comment:
|
|
60
|
+
Then wire the set into the agent's LLM in `src/main.ts` (A2A) or `src/mcpMain.ts` (MCP) - the scaffold's `tools:` line carries this exact hint in a comment:
|
|
89
61
|
|
|
90
62
|
```ts
|
|
91
63
|
import { X402_BUYER_TOOLS } from "./x402Buyer.js";
|
|
@@ -93,32 +65,16 @@ import { X402_BUYER_TOOLS } from "./x402Buyer.js";
|
|
|
93
65
|
tools: { ...LLM_READ_TOOLS, ...X402_BUYER_TOOLS },
|
|
94
66
|
```
|
|
95
67
|
|
|
96
|
-
This is the whole point of the feature: the DEPLOYED agent buys the data
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
This is commitment #3 intact: signing stays fixed handler code; the merchant
|
|
108
|
-
table is user-confirmed config, not an LLM-writable surface.
|
|
109
|
-
|
|
110
|
-
> **For the agent's LLM — the one invariant it keeps getting wrong:** x402
|
|
111
|
-
> merchants need **NO API key**. CMC's x402 endpoints (and every Bazaar
|
|
112
|
-
> merchant) authenticate the caller by the on-chain EIP-3009 payment the
|
|
113
|
-
> agent's wallet signs — there is no `Authorization` / `X-API-KEY` header
|
|
114
|
-
> anywhere. So when a funded task asks for CMC/paid data and `buy_with_x402`
|
|
115
|
-
> is in the toolset, the LLM MUST call it — it must never fall back to "I need
|
|
116
|
-
> an API key / I can't do this without a key." Payment is already fenced by
|
|
117
|
-
> `per_call_cap_usd` + `[budget].max_per_day_usd`, so the call is always safe
|
|
118
|
-
> to make. The recipe bakes this into the tool description and the scaffold's
|
|
119
|
-
> `system` prompt; keep it there if you edit them.
|
|
120
|
-
|
|
121
|
-
## Step 3 — verify end to end
|
|
68
|
+
This is the whole point of the feature: the DEPLOYED agent buys the data itself at work time (e.g. inside `notify_funded` while producing a deliverable) - the CLI commands below are only the operator's test rig. The LLM gets two tools:
|
|
69
|
+
|
|
70
|
+
- `buy_with_x402(url, max_usd, method="GET")` - pay + fetch. The LLM chooses **which** allowed URL to call and with what query params; it can NEVER choose who gets paid (pinned `pay_to`) or widen the caps (per-call cap, `[budget].max_per_day_usd`, `[payments.x402].max_per_request_usd`).
|
|
71
|
+
- `quote_x402(url, method="GET")` - free 402 inspection.
|
|
72
|
+
|
|
73
|
+
This is commitment #3 intact: signing stays fixed handler code; the merchant table is user-confirmed config, not an LLM-writable surface.
|
|
74
|
+
|
|
75
|
+
> **For the agent's LLM - the one invariant it keeps getting wrong:** x402 merchants need **NO API key**. CMC's x402 endpoints (and every Bazaar merchant) authenticate the caller by the on-chain EIP-3009 payment the agent's wallet signs - there is no `Authorization` / `X-API-KEY` header anywhere. So when a funded task asks for CMC/paid data and `buy_with_x402` is in the toolset, the LLM MUST call it - it must never fall back to "I need an API key / I can't do this without a key." Payment is already fenced by `per_call_cap_usd` + `[budget].max_per_day_usd`, so the call is always safe to make. The recipe bakes this into the tool description and the scaffold's `system` prompt; keep it there if you edit them.
|
|
76
|
+
|
|
77
|
+
## Step 3 - verify end to end
|
|
122
78
|
|
|
123
79
|
```bash
|
|
124
80
|
bag x402 quote "https://pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/latest?id=1" # free
|
|
@@ -126,44 +82,27 @@ bag x402 buy "https://pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/
|
|
|
126
82
|
bag dev # then ask the agent something that needs the paid data
|
|
127
83
|
```
|
|
128
84
|
|
|
129
|
-
`buy` needs `WALLET_PASSWORD` set and the wallet funded with mainnet $U (see
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- **
|
|
136
|
-
|
|
137
|
-
of your project's `[network].default` — a testnet seller can still buy
|
|
138
|
-
mainnet data.
|
|
139
|
-
- **Exposure is fenced** three ways: per-call `per_call_cap_usd`, per-request
|
|
140
|
-
`max_per_request_usd`, and the daily `[budget].max_per_day_usd` (shared
|
|
141
|
-
ledger at `.studio/spend-ledger.json`).
|
|
142
|
-
- **Platform trials:** `bag deploy` warns (never blocks) when
|
|
143
|
-
`[deploy].destination = "platform"` meets a merchants table — the trial
|
|
144
|
-
ships the wallet key to the operator's Secrets Manager under
|
|
145
|
-
testnet-scoped consent. For paid-capability agents prefer self-deploy, or
|
|
146
|
-
keep a throwaway wallet holding only pocket money.
|
|
147
|
-
- **Funding**: buy $U on PancakeSwap
|
|
148
|
-
(`?outputCurrency=0xcE24439F2D9C6a2289F741120FE202248B666666`) to the agent
|
|
149
|
-
wallet address (`bag wallet status`). A few dollars covers hundreds of CMC
|
|
150
|
-
calls; x402 payments themselves are gasless for the buyer (the facilitator
|
|
151
|
-
fronts gas).
|
|
85
|
+
`buy` needs `WALLET_PASSWORD` set and the wallet funded with mainnet $U (see money section below). A successful `buy` prints `✓ Paid: 0.01 USD` plus the response body - that is the whole x402 loop proven.
|
|
86
|
+
|
|
87
|
+
## The money - read before funding
|
|
88
|
+
|
|
89
|
+
- **Mainnet, real $U.** CMC (and current Bazaar merchants) settle **only** on BSC mainnet (`eip155:56`); there is no testnet channel. This is independent of your project's `[network].default` - a testnet seller can still buy mainnet data.
|
|
90
|
+
- **Exposure is fenced** three ways: per-call `per_call_cap_usd`, per-request `max_per_request_usd`, and the daily `[budget].max_per_day_usd` (shared ledger at `.studio/spend-ledger.json`).
|
|
91
|
+
- **Platform trials:** `bag deploy` warns (never blocks) when `[deploy].destination = "platform"` meets a merchants table - the trial ships the wallet key to the operator's Secrets Manager under testnet-scoped consent. For paid-capability agents prefer self-deploy, or keep a throwaway wallet holding only pocket money.
|
|
92
|
+
- **Funding**: buy $U on PancakeSwap (`?outputCurrency=0xcE24439F2D9C6a2289F741120FE202248B666666`) to the agent wallet address (`bag wallet status`). A few dollars covers hundreds of CMC calls; x402 payments themselves are gasless for the buyer (the facilitator fronts gas).
|
|
152
93
|
|
|
153
94
|
## Troubleshooting
|
|
154
95
|
|
|
155
96
|
| Symptom | Meaning / fix |
|
|
156
|
-
|
|
97
|
+
| --- | --- |
|
|
157
98
|
| `X402HostNotAllowedError` | Merchant not trusted yet → `bag x402 trust <merchant\|url>` |
|
|
158
99
|
| `X402RecipientRequiredError` | No pinned recipient for that host → same fix |
|
|
159
|
-
| `X402RecipientMismatchError` | Live payTo drifted from the pin
|
|
160
|
-
| `X402BudgetExhaustedError` | Per-call cap or daily budget hit
|
|
161
|
-
| `x402 402 has no EIP-3009-payable option` | Merchant offers only permit2/other methods for $U on this network
|
|
162
|
-
| `X402PolicyError` / `PolicyViolation` | Signing allowlist
|
|
100
|
+
| `X402RecipientMismatchError` | Live payTo drifted from the pin - do NOT override casually; re-verify the merchant |
|
|
101
|
+
| `X402BudgetExhaustedError` | Per-call cap or daily budget hit - raise `per_call_cap_usd` / `[budget].max_per_day_usd` deliberately |
|
|
102
|
+
| `x402 402 has no EIP-3009-payable option` | Merchant offers only permit2/other methods for $U on this network - not payable by this buyer today |
|
|
103
|
+
| `X402PolicyError` / `PolicyViolation` | Signing allowlist - see `bnbagent-studio-extending-signing.md` |
|
|
163
104
|
|
|
164
105
|
**Different from**:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
- `bnbagent-studio-extending-signing.md` — the signing-policy allowlist
|
|
169
|
-
mechanics that back all of this.
|
|
106
|
+
|
|
107
|
+
- `bnbagent-studio-buying-via-8183.md` (same directory) - buying from an **ERC-8183 seller agent** (jobs, disputes, settle windows). This file is about flat pay-per-call x402 APIs; no job lifecycle.
|
|
108
|
+
- `bnbagent-studio-extending-signing.md` - the signing-policy allowlist mechanics that back all of this.
|