@bnbagent/studio-cli 0.0.6-alpha.1
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 +48 -0
- package/LICENSE +201 -0
- package/dist/_agentcoreName-DZDWEYD3.js +7 -0
- package/dist/_twak-5XQMOFUC.js +25 -0
- package/dist/bag.js +19358 -0
- package/dist/chunk-7RAKL4AS.js +172 -0
- package/dist/chunk-M3ODFCA7.js +1053 -0
- package/dist/chunk-U7IDQ3K5.js +14 -0
- package/dist/deployCli-N6TPN6XA.js +40 -0
- package/package.json +64 -0
- package/recipes/agent/code/{{PKG}}/signing.ts.tmpl +287 -0
- package/recipes/agent/recipe.toml +35 -0
- package/recipes/providers/pieverse-llm/recipe.toml +16 -0
- package/recipes/providers/pieverse-llm/skills/funding-pieverse-llm.md +203 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/.dockerignore.tmpl +8 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/Dockerfile.tmpl +50 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/agentCard.ts.tmpl +135 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/dualMain.ts.tmpl +402 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/executor.ts.tmpl +147 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/main.ts.tmpl +344 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/mcpMain.ts.tmpl +677 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/model.ts.tmpl +117 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/sellerCore.ts.tmpl +503 -0
- package/recipes/runtimes/agentcore/code/{{PKG}}/tools.ts.tmpl +157 -0
- package/recipes/runtimes/agentcore/recipe.toml +97 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/.dockerignore.tmpl +8 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/Dockerfile.tmpl +47 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/agentCard.ts.tmpl +131 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/executor.ts.tmpl +504 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/foundryMain.ts.tmpl +300 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/main.ts.tmpl +196 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/mcpMain.ts.tmpl +562 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/model.ts.tmpl +117 -0
- package/recipes/runtimes/azure-foundry/code/{{PKG}}/tools.ts.tmpl +157 -0
- package/recipes/runtimes/azure-foundry/recipe.toml +88 -0
- package/recipes/tools-chain/code/{{PKG}}/chainTools.ts.tmpl +166 -0
- package/recipes/tools-chain/recipe.toml +11 -0
- package/recipes/wallet/recipe.toml +20 -0
- package/recipes/x402-buyer/code/{{PKG}}/x402Buyer.ts.tmpl +175 -0
- package/recipes/x402-buyer/recipe.toml +15 -0
- package/skills/bnbagent-studio.md +107 -0
- package/skills/references/bnbagent-studio-adding-to-project.md +241 -0
- package/skills/references/bnbagent-studio-buying-from-bazaar.md +169 -0
- package/skills/references/bnbagent-studio-buying-via-8183.md +222 -0
- package/skills/references/bnbagent-studio-extending-signing.md +227 -0
- package/skills/references/bnbagent-studio-operating.md +211 -0
- package/skills/references/bnbagent-studio-scaffolding-agent.md +536 -0
- package/skills/references/bnbagent-studio-selling-via-8183.md +271 -0
- package/skills/references/bnbagent-studio-selling-via-b402.md +194 -0
- package/skills/references/bnbagent-studio-use-aws-agentcore.md +208 -0
- package/skills/references/bnbagent-studio-use-azure-foundry.md +164 -0
- package/skills/references/bnbagent-studio-use-bnb-trial.md +92 -0
- package/skills/references/bnbagent-studio-using-altana-wallet.md +68 -0
- package/skills/references/bnbagent-studio-using-twak-wallet.md +260 -0
- package/skills/references/bnbagent-studio-wiring-llm-tools.md +338 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bnbagent-studio
|
|
3
|
+
description: The single entry point for bnbagent-studio — a TypeScript CLI (`bag`) for building a blockchain SELLER agent that earns $U on BNB Chain via ERC-8004 + ERC-8183 + x402 (Pieverse LLM inside). Load this skill whenever the user works in a bnbagent-studio / `bag` project, or wants to create/scaffold, deploy, run, debug, operate, or monetize such a seller agent (composable A2A, MCP, and X402 faces; BNB Chain trial, AWS AgentCore, or Azure Foundry). All detailed playbooks ship as references/ files inside this skill — route via the decision tree in the body. When invoked with arguments, treat them as the user's intent and route the same way.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# bnbagent-studio (the single entry point)
|
|
7
|
+
|
|
8
|
+
`bnbagent-studio` (CLI: `bag`) wires the `@bnbagent/sdk` protocol layer (wallet /
|
|
9
|
+
ERC-8004 / ERC-8183 / Pieverse LLM) into a TypeScript agent project, then deploys it
|
|
10
|
+
as a **single blockchain seller runtime**. A2A, MCP, and X402 are composable
|
|
11
|
+
public faces selected with `--protocols`; A2A is the default. `bag deploy` uses
|
|
12
|
+
**scheme C**: every new deploy
|
|
13
|
+
or redeploy explicitly selects BNB, AWS, or Azure; a recorded deployment is
|
|
14
|
+
used only to offer an explicit update action, never as a silent default. BNB is
|
|
15
|
+
a 48h testnet trial and is disabled after expiry. AWS and Azure deploy into the
|
|
16
|
+
user's own account. All cloud lifecycle calls go through the pinned
|
|
17
|
+
`@bnbagent/deploy-cli`; never require `aws`, `az`, or `azd` CLIs.
|
|
18
|
+
BNB/AWS share the agentcore scaffold; Azure requires the azure-foundry
|
|
19
|
+
container scaffold and currently deploys A2A projects only (Foundry's
|
|
20
|
+
Invocations contract is not the native MCP transport). Treat an incompatible provider row as unavailable—do not
|
|
21
|
+
force through it or mutate the scaffold during deploy.
|
|
22
|
+
|
|
23
|
+
Invoked as `/bnbagent-studio <ask>`? Treat `<ask>` as the user's intent and
|
|
24
|
+
route it through the decision tree below, exactly like a natural-language ask.
|
|
25
|
+
|
|
26
|
+
## The single seller runtime model (the invariants)
|
|
27
|
+
|
|
28
|
+
One deployed runtime, one signer: a single valuable Agent serves the selected
|
|
29
|
+
faces (A2A `src/main.ts` on `:9000`, MCP `src/mcpMain.ts` on `:8000/mcp`, or
|
|
30
|
+
A2A-native `src/dualMain.ts` on `:9000` with tunneled `/mcp`),
|
|
31
|
+
holds the key, and signs in-process. The ERC-8183 rail exposes exactly two
|
|
32
|
+
bounded operations — **`negotiate`** (rule-based price clamp + EIP-191 sign;
|
|
33
|
+
**no LLM touches money**) and **`notify_funded`** (verify the funded job →
|
|
34
|
+
produce the deliverable → submit on-chain; A2A acks then delivers in the
|
|
35
|
+
background, MCP delivers synchronously in the tool call). The optional x402
|
|
36
|
+
rail adds an anonymous paid HTTP request at `/x402`; it settles through B402
|
|
37
|
+
before running work and does not expose a general signing tool. Read-only chain
|
|
38
|
+
tools remain available. ALL signing is fixed entrypoint code in
|
|
39
|
+
`app/agent/src/signing.ts` or the runtime's bounded x402 payment handler, never
|
|
40
|
+
an LLM-callable tool. The encrypted keystore lives at the workspace root
|
|
41
|
+
`.studio/wallets/`, outside the deploy codeLocation, and is injected only via
|
|
42
|
+
the selected provider's delegated secret channel. `settle` is manual
|
|
43
|
+
(`bag erc8183 settle`). Full layout and lifecycle details live in the
|
|
44
|
+
references below — read them before acting.
|
|
45
|
+
|
|
46
|
+
## Decision tree — which reference to read next
|
|
47
|
+
|
|
48
|
+
**References are plain markdown files installed in THIS skill's directory** at
|
|
49
|
+
`references/<name>.md`. When a row matches, READ THAT FILE before acting — do
|
|
50
|
+
not answer from memory.
|
|
51
|
+
|
|
52
|
+
| User intent | Read / do |
|
|
53
|
+
|---|---|
|
|
54
|
+
| Create a brand new single seller project from zero | `references/bnbagent-studio-scaffolding-agent.md` |
|
|
55
|
+
| Add wallet / the single seller runtime to an existing TypeScript agent | `references/bnbagent-studio-adding-to-project.md` |
|
|
56
|
+
| Run / debug / dev / doctor / RPC / balance / incident triage | `references/bnbagent-studio-operating.md` |
|
|
57
|
+
| Implement what the Agent sells, tune pricing, publish over A2A and/or MCP, defend disputes (seller flow) | `references/bnbagent-studio-selling-via-8183.md` |
|
|
58
|
+
| Sell one paid HTTP request through the B402-backed x402 rail (merchant application, RSA key, credentials, IP allowlist, activation) | `references/bnbagent-studio-selling-via-b402.md` |
|
|
59
|
+
| Deploy / redeploy / status / logs / destroy | Run `bag deploy` and explicitly choose a provider. Non-interactive deploy requires `--provider bnb\|aws\|azure --yes` (and `--allow-multiple` when keeping another provider active). Read `references/bnbagent-studio-use-bnb-trial.md`, `references/bnbagent-studio-use-aws-agentcore.md`, or `references/bnbagent-studio-use-azure-foundry.md` for the selected provider. `bag deploy status` lists every recorded provider; multi-deployment logs/verify/destroy require `--provider`. |
|
|
60
|
+
| Wire chain-read tools into the Agent's LLM (AI SDK `tool()` wrappers, or any TS agent framework) | `references/bnbagent-studio-wiring-llm-tools.md` |
|
|
61
|
+
| Buy a service from another ERC-8183 seller via CLI — incl. testing your own seller from the buyer side (v2/internal — NOT the v1 seller product flow) | `references/bnbagent-studio-buying-via-8183.md` |
|
|
62
|
+
| Give the agent a PAID x402 capability — CMC market data / Binance Bazaar (B402) merchants / any pay-per-call API (`bag x402 trust`, x402-buyer recipe, 402 buyer errors) | `references/bnbagent-studio-buying-from-bazaar.md` |
|
|
63
|
+
| Extend the EIP-712 signing allowlist (custom contract / new x402 service / diagnose `PolicyViolation` / `X402PolicyError`) | `references/bnbagent-studio-extending-signing.md` |
|
|
64
|
+
| Project uses `[wallet].kind = "twak"` (create / fund / SIWE-bind / container deploy / known limitations) | `references/bnbagent-studio-using-twak-wallet.md` |
|
|
65
|
+
| Project uses `[wallet].kind = "altana"` (admin keystore / bounded session / quote checker / x402 allowance / local dev) | `references/bnbagent-studio-using-altana-wallet.md` |
|
|
66
|
+
| (Pieverse projects only) Fund the LLM, switch to a paid model, hit insufficient credits (`PieverseBudgetExhaustedError` / `PieverseAccountBalanceExhaustedError`) | skill `funding-pieverse-llm` (project-scope; emitted at `bag init --llm-provider pieverse-llm`) |
|
|
67
|
+
|
|
68
|
+
If two or more match, read both — they're designed to be orthogonal.
|
|
69
|
+
|
|
70
|
+
### Where the references live
|
|
71
|
+
|
|
72
|
+
Next to this file: this skill installs as a directory with a `references/`
|
|
73
|
+
subdirectory (Claude Code: `~/.claude/skills/bnbagent-studio/references/` or the
|
|
74
|
+
project-scope `<project>/.claude/skills/bnbagent-studio/references/`; Cursor:
|
|
75
|
+
`bnbagent-studio/references/` under the rules directory, beside the `.mdc`
|
|
76
|
+
rules). If a reference file is missing, `bag skills install` (re)installs it.
|
|
77
|
+
|
|
78
|
+
<!-- Maintainers: this skill's DESCRIPTION only carries ENTRY intents (identity
|
|
79
|
+
+ create/deploy/run/debug/operate/monetize). Mid-journey topics (twak, EIP-712,
|
|
80
|
+
disputes, buyer flow, tool wiring, ...) are routed by the decision tree above and
|
|
81
|
+
must NOT be added to the description — see docs/design/decisions.md §14. -->
|
|
82
|
+
|
|
83
|
+
## 5 core commitments (always honor)
|
|
84
|
+
|
|
85
|
+
1. **Agent project code is user-owned** — recipe-emitted files are theirs to edit; studio doesn't auto-rewrite them.
|
|
86
|
+
2. **Private keys live in a user-controlled environment, never transmitted to studio or third parties** — the encrypted keystore lives at the workspace root, outside the deploy codeLocation (no packaging path can bundle it). Altana keeps its admin keystore there and gives local runtime only a bounded session; deployment is blocked. Other supported deploy paths inject only their required wallet material into the selected runtime secret channel. (Scoped, consented exception: provider `bnb`, the 48h testnet trial — testnet-forced, throwaway wallet recommended.)
|
|
87
|
+
3. **Signing is fixed handler code, never an LLM-callable tool** — the ERC-8183 rail exposes bounded `negotiate` / `notify_funded` flows and the x402 rail exposes a bounded paid-request handler; raw/arbitrary signing is never exposed. Read-only chain queries remain read-only tools.
|
|
88
|
+
4. **SDK protocol layer stays pure** — studio's opinions don't pollute `bnbagent-sdk`.
|
|
89
|
+
5. **The user can jump ship at any point** — emitted code is theirs to edit / fork / migrate; studio depends on no closed SaaS. Emitted code imports from `@bnbagent/studio-runtime` and depends on that runtime lib (not the CLI), so uninstalling the `@bnbagent/studio-cli` package never breaks a deployed agent.
|
|
90
|
+
|
|
91
|
+
## CLI groups at a glance
|
|
92
|
+
|
|
93
|
+
`init`, `scan`, `recipe`, `skills`, `wallet`, `erc8004`, `erc8183`, `x402`, `agents`, `config`, `env`, `dev`, `doctor`, `audit`, `deploy`, `platform`, `llm`, `bundle`, `budget` — see `bag --help` for details. `bag deploy [--provider bnb\|aws\|azure]` is the primary deploy command; `prepare`, `verify`, `status`, `info`, `destroy`, `logs`, `fix-gitignore`, and `provision-cognito` remain lifecycle subcommands (`deploy agent` is a deprecated compatibility alias). Provider deploy/status/logs/destroy and deploy-time credential validation are delegated to pinned `@bnbagent/deploy-cli@0.4.14`.
|
|
94
|
+
|
|
95
|
+
## Tool surface
|
|
96
|
+
|
|
97
|
+
- **CLI** — write-side (wallet ops, on-chain register, x402 buy, deploy)
|
|
98
|
+
- **MCP** — an external seller face (`bag init --protocols MCP`), composable
|
|
99
|
+
with A2A; dual mode is A2A-native so `HEALTHY_BUSY` preserves background work
|
|
100
|
+
- **`@bnbagent/studio-runtime/tools`** — 15 pure read-only functions, wrapped into LLM tools by the chain-tools recipe (read `references/bnbagent-studio-wiring-llm-tools.md`)
|
|
101
|
+
|
|
102
|
+
## Where docs live
|
|
103
|
+
|
|
104
|
+
- `docs/design/architecture.md` — layered architecture
|
|
105
|
+
- `docs/design/decisions.md` — decision records (Pieverse default, signing policy, chain tools, zero-deposit, skill reorg, **single seller runtime + protocol faces**)
|
|
106
|
+
- `docs/guides/pieverse-integration.md` — Pieverse LLM full lifecycle
|
|
107
|
+
- `docs/guides/user-guide.md` — end-user procedures
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bnbagent-studio-adding-to-project
|
|
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
|
+
---
|
|
5
|
+
|
|
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
|
+
|
|
8
|
+
# bnbagent-studio-adding-to-project
|
|
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.
|
|
13
|
+
|
|
14
|
+
## The single seller runtime model (v1 workspace)
|
|
15
|
+
|
|
16
|
+
studio turns the user's existing valuable agent into a paid blockchain seller as
|
|
17
|
+
a **thin workspace root with one sub-project** under it:
|
|
18
|
+
|
|
19
|
+
- **Agent (`app/agent/` sub-project, → AWS Bedrock AgentCore).** The user's
|
|
20
|
+
agent value (LLM / memory / tools / KB) AND the **sole key-holder/signer**.
|
|
21
|
+
AgentCore runs the container with the selected protocol (A2A:
|
|
22
|
+
`0.0.0.0:9000`; MCP: `0.0.0.0:8000/mcp`), so the Agent **serves directly** —
|
|
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.
|
|
43
|
+
|
|
44
|
+
v1 is **seller-only**; chat / buyer roles are deferred to v2.
|
|
45
|
+
|
|
46
|
+
## Preconditions
|
|
47
|
+
|
|
48
|
+
- The repo is a TypeScript/Node project (has a `package.json`).
|
|
49
|
+
- 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
|
+
- Network access to BSC testnet RPC (default: `https://data-seed-prebsc-1-s1.binance.org:8545`).
|
|
51
|
+
|
|
52
|
+
## Step 1 — Bootstrap studio config
|
|
53
|
+
|
|
54
|
+
Check for the v1 workspace layout — `app/agent/studio.toml` (not a root-level
|
|
55
|
+
`studio.toml`):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
ls app/agent/studio.toml 2>/dev/null || echo MISSING
|
|
59
|
+
```
|
|
60
|
+
|
|
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):
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
bag init my-agent && cd my-agent # creates ./my-agent/ with the single app/agent/ sub-project
|
|
68
|
+
```
|
|
69
|
+
|
|
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.
|
|
76
|
+
|
|
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.
|
|
83
|
+
|
|
84
|
+
## Step 2 — Detect framework (best-effort)
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
bag scan
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**v1 note**: `scan` is a stub — it just reports detected files. Don't rely on
|
|
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.
|
|
93
|
+
|
|
94
|
+
## Step 3 — Emit the agent
|
|
95
|
+
|
|
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:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
bag recipe code agent > /dev/null # inspect; bag init writes app/agent/src/signing.ts for you
|
|
106
|
+
bag recipe code runtimes/agentcore > /dev/null # inspect; bag init writes the A2A serving files for you
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
In practice `bag init` already scaffolds `app/agent/`. Use `bag recipe code agent`
|
|
110
|
+
/ `bag recipe code runtimes/agentcore` to inspect or re-emit (emits under
|
|
111
|
+
`{{PKG}}` = the agent's `src/` dir, or pass `--pkg <name>` explicitly).
|
|
112
|
+
|
|
113
|
+
Gotcha: token is **U** (USD-pegged stablecoin on BSC), not BNB. All ERC-8183
|
|
114
|
+
amounts are denominated in U.
|
|
115
|
+
|
|
116
|
+
## Step 4 — Wire your existing agent's value into the Agent
|
|
117
|
+
|
|
118
|
+
The Agent sub-project (`app/agent/`) is where your existing valuable agent
|
|
119
|
+
lives. Move your LLM construction / tools / memory / KB wiring into it, and
|
|
120
|
+
implement the `runWork` developer hook (in `app/agent/src/sellerCore.ts` for
|
|
121
|
+
A2A, `app/agent/src/mcpMain.ts` for MCP; called from `notify_funded`'s
|
|
122
|
+
delivery) to produce the deliverable. Read-only chain tools go in
|
|
123
|
+
`app/agent/src/tools.ts` (see `bnbagent-studio-wiring-llm-tools`). ALL signing
|
|
124
|
+
stays in `app/agent/src/signing.ts` — never expose a signing call as an LLM
|
|
125
|
+
tool.
|
|
126
|
+
|
|
127
|
+
Tune the price in `app/agent/studio.toml` (`[payments.erc8183]` `min_price`/
|
|
128
|
+
`max_price`): the `negotiate` path is **rule-based, no LLM** — fixed code takes
|
|
129
|
+
the configured list price, clamps it to `[min_price, max_price]`, then
|
|
130
|
+
`signing.ts` EIP-191-signs the offer. For per-task pricing, compute the price
|
|
131
|
+
from the request *before* clamping — the LLM still never sets the price. The
|
|
132
|
+
buyer anchors the signed envelope on-chain via `createJob` + `fund`.
|
|
133
|
+
|
|
134
|
+
## Step 4c — LLM credit continuity (automatic, NOT an LLM tool)
|
|
135
|
+
|
|
136
|
+
For Pieverse projects, the Agent's `buildModel()` factory in the emitted
|
|
137
|
+
`app/agent/src/model.ts` returns an AI SDK model wrapped with credit-ensure
|
|
138
|
+
middleware. Its **automatic, budget-gated auto-renew hook** (the stack-neutral
|
|
139
|
+
logic lives in `@bnbagent/studio-runtime/pieverse` `PieverseCreditEnsurer`;
|
|
140
|
+
the AI-SDK shell is the emitted file) tops up the active Pieverse key from the
|
|
141
|
+
wallet (when
|
|
142
|
+
`[budget].enabled = true`) before an LLM call whose cached balance is below
|
|
143
|
+
`[llm.auto_renew].min_balance_usd`. The Agent keeps delivering jobs even if it
|
|
144
|
+
runs low mid-shift — the resilience is transparent.
|
|
145
|
+
|
|
146
|
+
Crucially this is **not** an LLM tool. It rides on the hardened x402 buyer
|
|
147
|
+
kernel (`@bnbagent/studio-runtime/x402`, the payment signer) — but the Agent
|
|
148
|
+
(the sole key-holder) drives it transparently inside the model wrapper; the LLM
|
|
149
|
+
never decides to spend. The LLM-credit self-top-up you get for free is the
|
|
150
|
+
managed-model auto-renew hook described above.
|
|
151
|
+
|
|
152
|
+
If the budget gate is off / exhausted, the hook raises
|
|
153
|
+
`PieverseAccountBalanceExhaustedError` — let it surface so the buyer can dispute;
|
|
154
|
+
refill with `bag llm topup` or enable the budget with `bag budget enable`.
|
|
155
|
+
|
|
156
|
+
## Step 5 — Deploy the agent
|
|
157
|
+
|
|
158
|
+
`bag deploy` always asks the operator to choose BNB, AWS, or Azure; it never
|
|
159
|
+
silently reuses `[deploy].destination` or the last provider.
|
|
160
|
+
|
|
161
|
+
**Platform scaffold** (the bare-init default while the campaign runs) — one
|
|
162
|
+
command; first run does a GitHub device-flow login, the wallet key goes to the
|
|
163
|
+
operator's Secrets Manager (testnet-forced, use a throwaway wallet):
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
bag platform login # prints GitHub device URL + code; does not open a browser
|
|
167
|
+
bag deploy --provider bnb # ship to the managed platform (48h testnet trial)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Self-deploy scaffold** (`--destination self`) — the Agent serves the selected
|
|
171
|
+
protocol directly behind a mandatory Cognito authorizer; register
|
|
172
|
+
ERC-8004/8183 **last** with the deployed AgentCore endpoint:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
bag deploy prepare # readiness sweep
|
|
176
|
+
bag deploy provision-cognito # emits the Cognito CDK app you run (cdk deploy); wires discoveryUrl/clientId
|
|
177
|
+
bag deploy --provider aws # ship the Agent to AgentCore
|
|
178
|
+
bag deploy verify --provider aws # delegated status + reconcile ERC-8004 identity
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Gotcha: to serve external buyers, configure the Cognito authorizer
|
|
182
|
+
(`provision-cognito` → `cdk deploy --outputs-file` → `provision-cognito --wire`);
|
|
183
|
+
`bag deploy prepare` warns (W9) if unset but does NOT block. With no authorizer
|
|
184
|
+
the runtime is IAM/SigV4 owner-only (never anonymous) — external buyers without
|
|
185
|
+
AWS creds just can't reach it.
|
|
186
|
+
|
|
187
|
+
Gotcha: `dispute_window` is read from the on-chain policy contract (24h on
|
|
188
|
+
testnet). Buyers can dispute within that window after submit — the Agent can't
|
|
189
|
+
claim funds until the window closes.
|
|
190
|
+
|
|
191
|
+
## Step 6 — Verify
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
bag doctor # run from workspace root; scans the agent sub-project
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Should show green for: `app/agent/studio.toml` present, wallet decryptable (needs
|
|
198
|
+
`WALLET_PASSWORD` set in `.studio/.env.local`), RPC reachable, 8004 identity
|
|
199
|
+
registered (if applicable), LLM key present (if `[llm]` configured in
|
|
200
|
+
`app/agent/studio.toml`).
|
|
201
|
+
|
|
202
|
+
If anything is red, fix and re-run `bag doctor` before deploying.
|
|
203
|
+
|
|
204
|
+
## Step 7 — Smoke test the Agent locally
|
|
205
|
+
|
|
206
|
+
`bag dev` from the workspace root launches the Agent with the selected protocol.
|
|
207
|
+
Locally it runs without Cognito env, so the A2A card / MCP metadata is reachable
|
|
208
|
+
without a token:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
bag dev # A2A on :9000, or MCP on :8000/mcp
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
For A2A projects, in another shell, fetch the card and send a `negotiate` message
|
|
215
|
+
(`message/send` JSON-RPC with a single `DataPart`):
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
curl -s http://localhost:9000/.well-known/agent-card.json # 2 skills: negotiate / notify_funded
|
|
219
|
+
|
|
220
|
+
curl -X POST http://localhost:9000/ \
|
|
221
|
+
-H 'Content-Type: application/json' \
|
|
222
|
+
-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"}}]}}}'
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The reply data part is the SDK `NegotiationResult` envelope, signed by the agent:
|
|
226
|
+
the quoted `price`, `currency`, and the signature fields (`negotiation_hash`,
|
|
227
|
+
`provider_sig`). The buyer anchors it on-chain via `createJob` + `fund`, then
|
|
228
|
+
sends a `notify_funded` message; the agent acks `accepted` at once and delivers in
|
|
229
|
+
the background, and the buyer reads the result from the chain (SUBMITTED →
|
|
230
|
+
`deliverable_url`). For MCP projects, connect an MCP client to
|
|
231
|
+
`http://localhost:8000/mcp`; `notify_funded` verifies, runs the work, and submits
|
|
232
|
+
synchronously inside the tool call (see `bnbagent-studio-selling-via-8183.md` (same directory) and
|
|
233
|
+
`docs/design/erc8183-buyer-push.md`).
|
|
234
|
+
|
|
235
|
+
## Reference
|
|
236
|
+
|
|
237
|
+
- `docs/design/single-seller-agent.md` (the A2A deploy model and history).
|
|
238
|
+
- `docs/design/erc8183-buyer-push.md` (how a buyer drives a sale: negotiate → fund → notify_funded).
|
|
239
|
+
- `docs/design/decisions.md` (single seller runtime + protocol-choice decision records).
|
|
240
|
+
- `docs/design/architecture.md` (recipes, selected-protocol runtime, project layout — §2.5 / §9.2).
|
|
241
|
+
- `bnbagent-studio-selling-via-8183.md` (same directory) — the runtime seller flow (negotiate/notify_funded/settle, disputes).
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bnbagent-studio-buying-from-bazaar
|
|
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
|
+
---
|
|
5
|
+
|
|
6
|
+
> **Reference file** of the `bnbagent-studio` router skill — installed at
|
|
7
|
+
> `bnbagent-studio/references/` and loaded on demand (not a standalone skill).
|
|
8
|
+
> Route here via the router's decision tree.
|
|
9
|
+
|
|
10
|
+
# bnbagent-studio-buying-from-bazaar
|
|
11
|
+
|
|
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.
|
|
17
|
+
|
|
18
|
+
**The three roles, kept separate** (do not conflate):
|
|
19
|
+
|
|
20
|
+
- **Bazaar** (`https://www.binance.com/bapi/ramp/v1/public/ramp/b402/bazaar/…`)
|
|
21
|
+
— a public, auth-free **catalog** of x402 merchants. It is never in the data
|
|
22
|
+
path and never in the payment path.
|
|
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.
|
|
27
|
+
|
|
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.
|
|
33
|
+
|
|
34
|
+
## Step 0 — know what's on offer
|
|
35
|
+
|
|
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`):
|
|
38
|
+
|
|
39
|
+
| Endpoint | Path | Good for |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Quotes Latest | `/x402/v3/cryptocurrency/quotes/latest?id=1` | prices, holdings briefs, price alerts |
|
|
42
|
+
| Listings Latest | `/x402/v3/cryptocurrency/listings/latest?start=1&limit=10` | top-N market overviews, rotation signals |
|
|
43
|
+
| DEX Search | `/x402/v1/dex/search?q=bnb` | new-token discovery, name checks |
|
|
44
|
+
| DEX Pairs Quotes | `/x402/v4/dex/pairs/quotes/latest?pair_address=0x…` | pool liquidity/volume, LP monitoring |
|
|
45
|
+
|
|
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.
|
|
52
|
+
|
|
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.
|
|
57
|
+
|
|
58
|
+
## Step 1 — trust the merchant (writes config, never pays)
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
bag x402 trust cmc # studio-reviewed: pinned payTo byte-compared vs live 402
|
|
62
|
+
bag x402 trust https://api.example.com/thing --cap 0.05 # any other x402 service (unreviewed)
|
|
63
|
+
```
|
|
64
|
+
|
|
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:
|
|
67
|
+
|
|
68
|
+
```toml
|
|
69
|
+
[payments.x402.merchants.cmc]
|
|
70
|
+
domain = "pro-api.coinmarketcap.com"
|
|
71
|
+
pay_to = "0x3C5f3a6cE224BB89D72f5EB4232ecC27F67B3eeA" # pinned; byte-compared on every payment
|
|
72
|
+
per_call_cap_usd = 0.02 # clamps every call, LLM cannot widen
|
|
73
|
+
verified = true # studio-reviewed shelf
|
|
74
|
+
```
|
|
75
|
+
|
|
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.
|
|
79
|
+
|
|
80
|
+
## Step 2 — wire the buyer tools into the agent
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
bag recipe code x402-buyer # emits src/x402Buyer.ts (next to src/tools.ts)
|
|
84
|
+
```
|
|
85
|
+
|
|
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:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { X402_BUYER_TOOLS } from "./x402Buyer.js";
|
|
92
|
+
// ...
|
|
93
|
+
tools: { ...LLM_READ_TOOLS, ...X402_BUYER_TOOLS },
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
This is the whole point of the feature: the DEPLOYED agent buys the data
|
|
97
|
+
itself at work time (e.g. inside `notify_funded` while producing a
|
|
98
|
+
deliverable) — the CLI commands below are only the operator's test rig.
|
|
99
|
+
The LLM gets two tools:
|
|
100
|
+
|
|
101
|
+
- `buy_with_x402(url, max_usd, method="GET")` — pay + fetch. The LLM chooses
|
|
102
|
+
**which** allowed URL to call and with what query params; it can NEVER
|
|
103
|
+
choose who gets paid (pinned `pay_to`) or widen the caps (per-call cap,
|
|
104
|
+
`[budget].max_per_day_usd`, `[payments.x402].max_per_request_usd`).
|
|
105
|
+
- `quote_x402(url, method="GET")` — free 402 inspection.
|
|
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
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
bag x402 quote "https://pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/latest?id=1" # free
|
|
125
|
+
bag x402 buy "https://pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/latest?id=1" --max-usd 0.02
|
|
126
|
+
bag dev # then ask the agent something that needs the paid data
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`buy` needs `WALLET_PASSWORD` set and the wallet funded with mainnet $U (see
|
|
130
|
+
money section below). A successful `buy` prints `✓ Paid: 0.01 USD` plus the
|
|
131
|
+
response body — that is the whole x402 loop proven.
|
|
132
|
+
|
|
133
|
+
## The money — read before funding
|
|
134
|
+
|
|
135
|
+
- **Mainnet, real $U.** CMC (and current Bazaar merchants) settle **only** on
|
|
136
|
+
BSC mainnet (`eip155:56`); there is no testnet channel. This is independent
|
|
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).
|
|
152
|
+
|
|
153
|
+
## Troubleshooting
|
|
154
|
+
|
|
155
|
+
| Symptom | Meaning / fix |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `X402HostNotAllowedError` | Merchant not trusted yet → `bag x402 trust <merchant\|url>` |
|
|
158
|
+
| `X402RecipientRequiredError` | No pinned recipient for that host → same fix |
|
|
159
|
+
| `X402RecipientMismatchError` | Live payTo drifted from the pin — do NOT override casually; re-verify the merchant |
|
|
160
|
+
| `X402BudgetExhaustedError` | Per-call cap or daily budget hit — raise `per_call_cap_usd` / `[budget].max_per_day_usd` deliberately |
|
|
161
|
+
| `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 |
|
|
162
|
+
| `X402PolicyError` / `PolicyViolation` | Signing allowlist — see `bnbagent-studio-extending-signing.md` |
|
|
163
|
+
|
|
164
|
+
**Different from**:
|
|
165
|
+
- `bnbagent-studio-buying-via-8183.md` (same directory) — buying from an
|
|
166
|
+
**ERC-8183 seller agent** (jobs, disputes, settle windows). This file is
|
|
167
|
+
about flat pay-per-call x402 APIs; no job lifecycle.
|
|
168
|
+
- `bnbagent-studio-extending-signing.md` — the signing-policy allowlist
|
|
169
|
+
mechanics that back all of this.
|