bnbagent-studio-core 0.0.1__tar.gz

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.
Files changed (42) hide show
  1. bnbagent_studio_core-0.0.1/.gitignore +36 -0
  2. bnbagent_studio_core-0.0.1/DISCLAIMER.md +51 -0
  3. bnbagent_studio_core-0.0.1/PKG-INFO +242 -0
  4. bnbagent_studio_core-0.0.1/README.md +214 -0
  5. bnbagent_studio_core-0.0.1/bnbagent_studio_core/__init__.py +36 -0
  6. bnbagent_studio_core-0.0.1/bnbagent_studio_core/audit/__init__.py +225 -0
  7. bnbagent_studio_core-0.0.1/bnbagent_studio_core/audit/redact.py +90 -0
  8. bnbagent_studio_core-0.0.1/bnbagent_studio_core/audit/schema.py +98 -0
  9. bnbagent_studio_core-0.0.1/bnbagent_studio_core/audit/writer.py +116 -0
  10. bnbagent_studio_core-0.0.1/bnbagent_studio_core/config.py +230 -0
  11. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8004/__init__.py +36 -0
  12. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8004/helpers.py +449 -0
  13. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/__init__.py +66 -0
  14. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/client.py +39 -0
  15. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/errors.py +57 -0
  16. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/negotiate.py +130 -0
  17. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/revert.py +72 -0
  18. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/seller.py +162 -0
  19. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/verify.py +145 -0
  20. bnbagent_studio_core-0.0.1/bnbagent_studio_core/erc8183/workflows.py +520 -0
  21. bnbagent_studio_core-0.0.1/bnbagent_studio_core/llm.py +136 -0
  22. bnbagent_studio_core-0.0.1/bnbagent_studio_core/networks.py +200 -0
  23. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/__init__.py +64 -0
  24. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/client.py +248 -0
  25. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/credit_ensurer.py +430 -0
  26. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/keys.py +299 -0
  27. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/models.py +46 -0
  28. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/policy.py +313 -0
  29. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/siwe.py +165 -0
  30. bnbagent_studio_core-0.0.1/bnbagent_studio_core/pieverse/topup.py +126 -0
  31. bnbagent_studio_core-0.0.1/bnbagent_studio_core/policy.py +65 -0
  32. bnbagent_studio_core-0.0.1/bnbagent_studio_core/storage.py +172 -0
  33. bnbagent_studio_core-0.0.1/bnbagent_studio_core/telemetry.py +19 -0
  34. bnbagent_studio_core-0.0.1/bnbagent_studio_core/tools/__init__.py +12 -0
  35. bnbagent_studio_core-0.0.1/bnbagent_studio_core/tools/chain_readonly.py +622 -0
  36. bnbagent_studio_core-0.0.1/bnbagent_studio_core/wallet.py +257 -0
  37. bnbagent_studio_core-0.0.1/bnbagent_studio_core/x402/__init__.py +64 -0
  38. bnbagent_studio_core-0.0.1/bnbagent_studio_core/x402/buyer.py +472 -0
  39. bnbagent_studio_core-0.0.1/bnbagent_studio_core/x402/errors.py +52 -0
  40. bnbagent_studio_core-0.0.1/bnbagent_studio_core/x402/policy.py +188 -0
  41. bnbagent_studio_core-0.0.1/bnbagent_studio_core/x402/signing.py +58 -0
  42. bnbagent_studio_core-0.0.1/pyproject.toml +59 -0
@@ -0,0 +1,36 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+
8
+ # Virtual envs
9
+ .venv/
10
+ .venv-*/
11
+ venv/
12
+
13
+ # Tooling caches
14
+ .pytest_cache/
15
+ .ruff_cache/
16
+ .mypy_cache/
17
+ .coverage
18
+
19
+ # OS / editor
20
+ .DS_Store
21
+ .vscode/
22
+ .idea/
23
+
24
+ # Local scratch
25
+ scratch/
26
+
27
+ # Project secrets
28
+ .env
29
+ .env.local
30
+
31
+ # Wallet keystores (never commit, even encrypted)
32
+ .studio/wallets/
33
+ *.keystore.json
34
+
35
+ # Audit log (per-project; ADR #37 T37.9)
36
+ .studio/audit-log.jsonl
@@ -0,0 +1,51 @@
1
+ <!-- Synced copy of the repo-root DISCLAIMER.md — edit that one, then re-copy. -->
2
+
3
+ # Disclaimer
4
+
5
+ **bnbagent-studio** is open-source software provided under the
6
+ [Apache-2.0 license](https://github.com/bnb-chain/bnbagent-studio/blob/main/LICENSE)
7
+ **"AS IS", without warranty of any kind** (see Sections 7–8 of the license).
8
+ This file spells out what that means for the parts of the project that touch
9
+ your cloud account and your funds.
10
+
11
+ ## AWS permissions and resources
12
+
13
+ Deploying the two-layer seller provisions resources **in your own AWS
14
+ account**: Bedrock AgentCore and Secrets Manager for the Agent (Layer A),
15
+ and — if you follow the EC2 runbook — an IAM role, security group and EC2
16
+ instance for the Service (Layer B).
17
+
18
+ The IAM policy documents this project publishes —
19
+ [least-privilege-iam.md](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/least-privilege-iam.md)
20
+ and
21
+ [iam-policies.md](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/iam-policies.md)
22
+ — are **reference configurations**, provided AS IS. They are a best effort at
23
+ a least-privilege setup, but **you** apply them, **you** own the credentials,
24
+ and **you** remain solely responsible for:
25
+
26
+ - reviewing and scoping every policy before applying it to your account;
27
+ - the conduct of any identity that holds these permissions;
28
+ - all resulting AWS costs; and
29
+ - the security posture and operation of the deployed resources.
30
+
31
+ Before granting any permission, read the official AWS guidance:
32
+
33
+ - [AWS IAM best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
34
+ - [AWS Well-Architected Framework — security pillar](https://docs.aws.amazon.com/wellarchitected/latest/framework/security.html)
35
+
36
+ ## Wallet keys and on-chain funds
37
+
38
+ The software manages wallet keys and on-chain funds. Private keys live only in
39
+ environments you control — which also means only **you** can protect them.
40
+ Start on testnet, fund mainnet wallets only with amounts you can afford to
41
+ lose, and use the software at your own risk. Nothing in this project is
42
+ financial advice.
43
+
44
+ ## No liability
45
+
46
+ To the maximum extent permitted by law, the authors and contributors accept no
47
+ liability for damages of any kind arising from the use of this software —
48
+ including, without limitation, lost funds, compromised credentials, unexpected
49
+ cloud charges, or security incidents in your AWS account. The
50
+ [Apache-2.0 license](https://github.com/bnb-chain/bnbagent-studio/blob/main/LICENSE)
51
+ is the authoritative statement of the terms.
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: bnbagent-studio-core
3
+ Version: 0.0.1
4
+ Summary: Agent-runtime library for bnbagent-studio: wallet, ERC-8004, ERC-8183, x402 over bnbagent-sdk.
5
+ Project-URL: Homepage, https://github.com/bnb-chain/bnbagent-studio
6
+ Project-URL: Repository, https://github.com/bnb-chain/bnbagent-studio
7
+ Author: BNB Chain Studio
8
+ License-Expression: Apache-2.0
9
+ Keywords: agent,blockchain,bnb,erc-8004,erc-8183,x402
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: bnbagent>=0.3.5
18
+ Requires-Dist: eth-account
19
+ Requires-Dist: httpx
20
+ Requires-Dist: python-dotenv>=1.0
21
+ Requires-Dist: tomli>=2.0; python_version < '3.11'
22
+ Requires-Dist: tomlkit>=0.13
23
+ Requires-Dist: web3
24
+ Provides-Extra: serve
25
+ Requires-Dist: fastapi>=0.110; extra == 'serve'
26
+ Requires-Dist: uvicorn>=0.30; extra == 'serve'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # bnbagent-studio-core
30
+
31
+ The **agent-runtime library** for
32
+ [bnbagent-studio](https://github.com/bnb-chain/bnbagent-studio) — the code a
33
+ deployed BNB Chain seller agent imports and runs. It wraps the `bnbagent`
34
+ protocol SDK with studio's configuration, workflow, and safety layer so an
35
+ agent can sign quotes, run ERC-8183 jobs, pay over x402, and read chain state
36
+ without re-implementing any of it.
37
+
38
+ ## Highlights
39
+
40
+ - **Wraps the `bnbagent` SDK** (wallet / ERC-8004 / ERC-8183 / x402) with
41
+ studio's opinions — `studio.toml` config, multi-step workflows, signing
42
+ policy, and an audit log — while leaving the SDK protocol layer untouched.
43
+ - **Lean runtime deps** — `bnbagent`, `web3`, `eth-account`, `httpx`,
44
+ `tomlkit`, `python-dotenv`. No agent framework, no web server in the base
45
+ install.
46
+ - **Framework- and runtime-agnostic** — does NOT import ADK, LangChain, or
47
+ bedrock-agentcore. Those couplings live in the CLI's emitted recipes, not
48
+ here, so you can drop this into any runtime.
49
+ - **FastAPI is opt-in.** The ERC-8183 seller-hosting helpers are the only code
50
+ that touches FastAPI, and they `import` it lazily — install the `[serve]`
51
+ extra only when you host an 8183 endpoint yourself.
52
+ - **What a deployed agent imports.** This is the library a scaffolded agent
53
+ declares as its runtime dependency; signing, settlement, and chain reads all
54
+ flow through it.
55
+
56
+ > ⚠️ **This project is under active development** and may introduce breaking
57
+ > changes between releases. It manages wallet keys and on-chain funds: start on
58
+ > **testnet**, and use it at your own risk.
59
+
60
+ > ⚠️ **Deploying provisions AWS resources in your own account**, under IAM
61
+ > policies you review and apply yourself. The published policy documents
62
+ > ([least-privilege guide](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/least-privilege-iam.md),
63
+ > [policy JSON](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/iam-policies.md))
64
+ > are **reference configurations provided AS IS** — you remain responsible for
65
+ > scoping, costs, and security. Full terms:
66
+ > [DISCLAIMER.md](https://github.com/bnb-chain/bnbagent-studio/blob/main/DISCLAIMER.md)
67
+ > (also shipped in this package as `bnbagent_studio_core/DISCLAIMER.md`).
68
+
69
+ ## Distribution & import names
70
+
71
+ - **Distribution:** `bnbagent-studio-core`
72
+ - **Import package:** `bnbagent_studio_core`
73
+
74
+ ```python
75
+ from bnbagent_studio_core import get_wallet, get_policy
76
+ from bnbagent_studio_core.erc8183 import submit_workflow, settle_workflow
77
+ ```
78
+
79
+ ## Where it sits
80
+
81
+ You normally **don't install this directly**. It's the library half of a
82
+ two-distribution split:
83
+
84
+ - **`bnbagent-studio-core`** (this package, import `bnbagent_studio_core`) — the
85
+ runtime library.
86
+ - **`bnbagent-studio`** (import `bag`) — the CLI: scaffolding, recipes, and a
87
+ read-only MCP server. It depends on this package.
88
+
89
+ Its three consumers:
90
+
91
+ 1. **A deployed Agent (Layer A, on AWS Bedrock AgentCore)** imports it at
92
+ runtime to sign quotes, submit/settle ERC-8183 jobs, auto-renew LLM credit,
93
+ and read chain state. Emitted agent code does
94
+ `from bnbagent_studio_core import ...`.
95
+ 2. **The `bag` CLI and its read-only MCP server** — shipped as the separate
96
+ `bnbagent-studio` distribution — also import it.
97
+ 3. **Rarely standalone** — only when building or vendoring an agent runtime by
98
+ hand.
99
+
100
+ The keyless Layer-B Service depends on **neither** package — it inlines its own
101
+ ~10-LOC config loader.
102
+
103
+ ## Install
104
+
105
+ ```bash
106
+ # Usual path: install the CLI, which pulls this in automatically
107
+ pip install bnbagent-studio
108
+ ```
109
+
110
+ Install it standalone only when building or vendoring an agent runtime by hand:
111
+
112
+ ```bash
113
+ pip install bnbagent-studio-core
114
+ ```
115
+
116
+ ### The `[serve]` extra
117
+
118
+ FastAPI/uvicorn are an optional `[serve]` extra. Only the seller-hosting path
119
+ (`bnbagent_studio_core.erc8183.seller`, reached via `serve_8183` /
120
+ `build_erc8183_app`) imports them, and it does so lazily — the agent runtime
121
+ never touches FastAPI. Install the extra only to host an ERC-8183 endpoint
122
+ yourself:
123
+
124
+ ```bash
125
+ pip install "bnbagent-studio-core[serve]"
126
+ ```
127
+
128
+ ## What's inside
129
+
130
+ Modules live under `bnbagent_studio_core/`. The convenience surface that
131
+ agent code imports is re-exported from the package root
132
+ (`get_wallet`, `get_policy`, `Policy`, `load_studio_toml`,
133
+ `find_project_root`, `emit`); lower-level surfaces stay reachable via their
134
+ submodules.
135
+
136
+ - **wallet** — keystore-backed signing. `get_wallet()` returns a
137
+ `bnbagent` `WalletProvider` (an `EVMWalletProvider` that enforces a
138
+ `SigningPolicy` on every sign); `ensure_keystore_materialized()` writes the
139
+ injected keystore to disk when the code mount is read-only. Local Keystore V3
140
+ today (KMS / remote signing deferred to v2).
141
+ - **config** — `studio.toml` loading and project discovery:
142
+ `load_studio_toml()`, `find_project_root()`, `find_workspace_root()`,
143
+ `load_env()`.
144
+ - **networks** — BSC testnet/mainnet registry and the **U** stablecoin (United
145
+ Stables, 18 decimals) token info; `get_network()`, plus `to_raw` / `from_raw`
146
+ amount converters.
147
+ - **policy** — `get_policy()` / `Policy` (budget caps: per-call and daily
148
+ spend limits read from `studio.toml`).
149
+ - **erc8004** — identity: `register`, `resolve`, `resolve_service`,
150
+ `update_endpoint`, `update_service_endpoint`, `show` (with `AgentRecord` /
151
+ `ResolvedService` result types).
152
+ - **erc8183** — commerce: a pre-configured client (`get_8183_client`),
153
+ multi-step workflows (`buy_workflow` / `submit_workflow` / `fetch_workflow` /
154
+ `settle_workflow`, plus `get_job_summary`), quote verification
155
+ (`verify_signed_job` / `recover_quote_signer` → `Verdict`), off-chain
156
+ negotiation, and seller-hosting starters (`serve_8183` /
157
+ `build_erc8183_app`). Typed errors (`JobNotFoundError`, `JobStateError`,
158
+ `BudgetCapExceededError`, …) are exported alongside.
159
+ - **x402** — x402 micropayment buyer kernel over the SDK's hardened
160
+ `X402Signer` (`fetch_with_payment`, `quote_url`, `pay_challenge`,
161
+ `FetchResult`) gated by an `X402BuyerPolicy` / `BudgetTracker`.
162
+ - **pieverse** — Pieverse LLM credit layer: `PieverseCreditEnsurer`
163
+ (budget-gated auto-renew), `BudgetPolicy` / `PieversePolicy`, key management
164
+ (`create_key`, `inspect_key`, `allocate`, `get_account_usage`), SIWE login
165
+ (`siwe_login`), and x402 top-up (`topup_x402`).
166
+ - **tools.chain_readonly** — 15 read-only on-chain query functions
167
+ (`wallet_info`, `balance_native`, `balance_u`, `agent_info`, `job_status`,
168
+ `job_list`, `tx_status`, `block_info`, `network_info`, …). Also surfaced as
169
+ the CLI's MCP tools; framework-neutral.
170
+ - **audit** — `.studio/audit-log.jsonl` emission protocol for on-chain money
171
+ ops: redaction (`validate_no_secrets`), schema (`Event`, `SCHEMA_VERSION`),
172
+ and a writer (`record`, `record_chain_op`, `audited_op`, `tail`).
173
+ - **storage** — deliverable storage selection (local file / IPFS) via
174
+ `storage_provider_from_config()`.
175
+ - **llm** — framework-neutral LLM-config resolution
176
+ (`_resolve_provider_config()` → `ProviderConfig`) used by emitted provider
177
+ shells. Studio constructs no model object itself.
178
+
179
+ ## Usage
180
+
181
+ The smallest meaningful snippets — read config and a wallet, verify a signed
182
+ quote. See the
183
+ [reference doc](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/reference.md)
184
+ for the full API.
185
+
186
+ ```python
187
+ from bnbagent_studio_core import get_wallet, get_policy, load_studio_toml
188
+
189
+ cfg = load_studio_toml() # parsed studio.toml (project root auto-discovered)
190
+ wallet = get_wallet() # keystore-backed WalletProvider (policy enforced)
191
+ policy = get_policy() # budget caps from [policy] in studio.toml
192
+ ```
193
+
194
+ ```python
195
+ # Verify a counterparty's signed ERC-8183 quote before acting on it.
196
+ from bnbagent_studio_core.erc8183 import verify_signed_job
197
+
198
+ verdict = verify_signed_job(signed_job)
199
+ if verdict.ok:
200
+ ... # safe to submit / settle
201
+ ```
202
+
203
+ ```python
204
+ # Read-only chain query (no signing, no key needed).
205
+ from bnbagent_studio_core.tools.chain_readonly import balance_u
206
+
207
+ print(balance_u(network="bsc-testnet"))
208
+ ```
209
+
210
+ ## Dependencies & boundaries
211
+
212
+ Runtime dependencies (lean by design):
213
+
214
+ - `bnbagent`, `web3`, `eth-account`, `httpx`, `tomlkit`, `python-dotenv`
215
+ (and `tomli` on Python < 3.11).
216
+
217
+ Boundaries:
218
+
219
+ - **FastAPI/uvicorn are `[serve]`-only.** The agent runtime never imports them;
220
+ the seller-hosting helpers import FastAPI lazily.
221
+ - **Framework- and runtime-agnostic.** This library does NOT import ADK,
222
+ LangChain, or bedrock-agentcore — those couplings live in the CLI's emitted
223
+ recipes, not here.
224
+ - **The SDK protocol layer stays pure.** Studio's opinions wrap `bnbagent`;
225
+ they never pollute it.
226
+
227
+ Python ≥ 3.10.
228
+
229
+ ## Further reading
230
+
231
+ - [Main repository](https://github.com/bnb-chain/bnbagent-studio) — overview,
232
+ guides, and the `bag` CLI.
233
+ - [Architecture](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/design/architecture.md)
234
+ — the layered design and two-layer deploy model.
235
+ - [Reference](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/reference.md)
236
+ — CLI / recipe / MCP-tool / library reference.
237
+ - [User Guide](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/user-guide.md)
238
+ — the install → skills → Claude Code → `bag dev` path (for CLI end-users).
239
+
240
+ ## License
241
+
242
+ Apache-2.0.
@@ -0,0 +1,214 @@
1
+ # bnbagent-studio-core
2
+
3
+ The **agent-runtime library** for
4
+ [bnbagent-studio](https://github.com/bnb-chain/bnbagent-studio) — the code a
5
+ deployed BNB Chain seller agent imports and runs. It wraps the `bnbagent`
6
+ protocol SDK with studio's configuration, workflow, and safety layer so an
7
+ agent can sign quotes, run ERC-8183 jobs, pay over x402, and read chain state
8
+ without re-implementing any of it.
9
+
10
+ ## Highlights
11
+
12
+ - **Wraps the `bnbagent` SDK** (wallet / ERC-8004 / ERC-8183 / x402) with
13
+ studio's opinions — `studio.toml` config, multi-step workflows, signing
14
+ policy, and an audit log — while leaving the SDK protocol layer untouched.
15
+ - **Lean runtime deps** — `bnbagent`, `web3`, `eth-account`, `httpx`,
16
+ `tomlkit`, `python-dotenv`. No agent framework, no web server in the base
17
+ install.
18
+ - **Framework- and runtime-agnostic** — does NOT import ADK, LangChain, or
19
+ bedrock-agentcore. Those couplings live in the CLI's emitted recipes, not
20
+ here, so you can drop this into any runtime.
21
+ - **FastAPI is opt-in.** The ERC-8183 seller-hosting helpers are the only code
22
+ that touches FastAPI, and they `import` it lazily — install the `[serve]`
23
+ extra only when you host an 8183 endpoint yourself.
24
+ - **What a deployed agent imports.** This is the library a scaffolded agent
25
+ declares as its runtime dependency; signing, settlement, and chain reads all
26
+ flow through it.
27
+
28
+ > ⚠️ **This project is under active development** and may introduce breaking
29
+ > changes between releases. It manages wallet keys and on-chain funds: start on
30
+ > **testnet**, and use it at your own risk.
31
+
32
+ > ⚠️ **Deploying provisions AWS resources in your own account**, under IAM
33
+ > policies you review and apply yourself. The published policy documents
34
+ > ([least-privilege guide](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/least-privilege-iam.md),
35
+ > [policy JSON](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/iam-policies.md))
36
+ > are **reference configurations provided AS IS** — you remain responsible for
37
+ > scoping, costs, and security. Full terms:
38
+ > [DISCLAIMER.md](https://github.com/bnb-chain/bnbagent-studio/blob/main/DISCLAIMER.md)
39
+ > (also shipped in this package as `bnbagent_studio_core/DISCLAIMER.md`).
40
+
41
+ ## Distribution & import names
42
+
43
+ - **Distribution:** `bnbagent-studio-core`
44
+ - **Import package:** `bnbagent_studio_core`
45
+
46
+ ```python
47
+ from bnbagent_studio_core import get_wallet, get_policy
48
+ from bnbagent_studio_core.erc8183 import submit_workflow, settle_workflow
49
+ ```
50
+
51
+ ## Where it sits
52
+
53
+ You normally **don't install this directly**. It's the library half of a
54
+ two-distribution split:
55
+
56
+ - **`bnbagent-studio-core`** (this package, import `bnbagent_studio_core`) — the
57
+ runtime library.
58
+ - **`bnbagent-studio`** (import `bag`) — the CLI: scaffolding, recipes, and a
59
+ read-only MCP server. It depends on this package.
60
+
61
+ Its three consumers:
62
+
63
+ 1. **A deployed Agent (Layer A, on AWS Bedrock AgentCore)** imports it at
64
+ runtime to sign quotes, submit/settle ERC-8183 jobs, auto-renew LLM credit,
65
+ and read chain state. Emitted agent code does
66
+ `from bnbagent_studio_core import ...`.
67
+ 2. **The `bag` CLI and its read-only MCP server** — shipped as the separate
68
+ `bnbagent-studio` distribution — also import it.
69
+ 3. **Rarely standalone** — only when building or vendoring an agent runtime by
70
+ hand.
71
+
72
+ The keyless Layer-B Service depends on **neither** package — it inlines its own
73
+ ~10-LOC config loader.
74
+
75
+ ## Install
76
+
77
+ ```bash
78
+ # Usual path: install the CLI, which pulls this in automatically
79
+ pip install bnbagent-studio
80
+ ```
81
+
82
+ Install it standalone only when building or vendoring an agent runtime by hand:
83
+
84
+ ```bash
85
+ pip install bnbagent-studio-core
86
+ ```
87
+
88
+ ### The `[serve]` extra
89
+
90
+ FastAPI/uvicorn are an optional `[serve]` extra. Only the seller-hosting path
91
+ (`bnbagent_studio_core.erc8183.seller`, reached via `serve_8183` /
92
+ `build_erc8183_app`) imports them, and it does so lazily — the agent runtime
93
+ never touches FastAPI. Install the extra only to host an ERC-8183 endpoint
94
+ yourself:
95
+
96
+ ```bash
97
+ pip install "bnbagent-studio-core[serve]"
98
+ ```
99
+
100
+ ## What's inside
101
+
102
+ Modules live under `bnbagent_studio_core/`. The convenience surface that
103
+ agent code imports is re-exported from the package root
104
+ (`get_wallet`, `get_policy`, `Policy`, `load_studio_toml`,
105
+ `find_project_root`, `emit`); lower-level surfaces stay reachable via their
106
+ submodules.
107
+
108
+ - **wallet** — keystore-backed signing. `get_wallet()` returns a
109
+ `bnbagent` `WalletProvider` (an `EVMWalletProvider` that enforces a
110
+ `SigningPolicy` on every sign); `ensure_keystore_materialized()` writes the
111
+ injected keystore to disk when the code mount is read-only. Local Keystore V3
112
+ today (KMS / remote signing deferred to v2).
113
+ - **config** — `studio.toml` loading and project discovery:
114
+ `load_studio_toml()`, `find_project_root()`, `find_workspace_root()`,
115
+ `load_env()`.
116
+ - **networks** — BSC testnet/mainnet registry and the **U** stablecoin (United
117
+ Stables, 18 decimals) token info; `get_network()`, plus `to_raw` / `from_raw`
118
+ amount converters.
119
+ - **policy** — `get_policy()` / `Policy` (budget caps: per-call and daily
120
+ spend limits read from `studio.toml`).
121
+ - **erc8004** — identity: `register`, `resolve`, `resolve_service`,
122
+ `update_endpoint`, `update_service_endpoint`, `show` (with `AgentRecord` /
123
+ `ResolvedService` result types).
124
+ - **erc8183** — commerce: a pre-configured client (`get_8183_client`),
125
+ multi-step workflows (`buy_workflow` / `submit_workflow` / `fetch_workflow` /
126
+ `settle_workflow`, plus `get_job_summary`), quote verification
127
+ (`verify_signed_job` / `recover_quote_signer` → `Verdict`), off-chain
128
+ negotiation, and seller-hosting starters (`serve_8183` /
129
+ `build_erc8183_app`). Typed errors (`JobNotFoundError`, `JobStateError`,
130
+ `BudgetCapExceededError`, …) are exported alongside.
131
+ - **x402** — x402 micropayment buyer kernel over the SDK's hardened
132
+ `X402Signer` (`fetch_with_payment`, `quote_url`, `pay_challenge`,
133
+ `FetchResult`) gated by an `X402BuyerPolicy` / `BudgetTracker`.
134
+ - **pieverse** — Pieverse LLM credit layer: `PieverseCreditEnsurer`
135
+ (budget-gated auto-renew), `BudgetPolicy` / `PieversePolicy`, key management
136
+ (`create_key`, `inspect_key`, `allocate`, `get_account_usage`), SIWE login
137
+ (`siwe_login`), and x402 top-up (`topup_x402`).
138
+ - **tools.chain_readonly** — 15 read-only on-chain query functions
139
+ (`wallet_info`, `balance_native`, `balance_u`, `agent_info`, `job_status`,
140
+ `job_list`, `tx_status`, `block_info`, `network_info`, …). Also surfaced as
141
+ the CLI's MCP tools; framework-neutral.
142
+ - **audit** — `.studio/audit-log.jsonl` emission protocol for on-chain money
143
+ ops: redaction (`validate_no_secrets`), schema (`Event`, `SCHEMA_VERSION`),
144
+ and a writer (`record`, `record_chain_op`, `audited_op`, `tail`).
145
+ - **storage** — deliverable storage selection (local file / IPFS) via
146
+ `storage_provider_from_config()`.
147
+ - **llm** — framework-neutral LLM-config resolution
148
+ (`_resolve_provider_config()` → `ProviderConfig`) used by emitted provider
149
+ shells. Studio constructs no model object itself.
150
+
151
+ ## Usage
152
+
153
+ The smallest meaningful snippets — read config and a wallet, verify a signed
154
+ quote. See the
155
+ [reference doc](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/reference.md)
156
+ for the full API.
157
+
158
+ ```python
159
+ from bnbagent_studio_core import get_wallet, get_policy, load_studio_toml
160
+
161
+ cfg = load_studio_toml() # parsed studio.toml (project root auto-discovered)
162
+ wallet = get_wallet() # keystore-backed WalletProvider (policy enforced)
163
+ policy = get_policy() # budget caps from [policy] in studio.toml
164
+ ```
165
+
166
+ ```python
167
+ # Verify a counterparty's signed ERC-8183 quote before acting on it.
168
+ from bnbagent_studio_core.erc8183 import verify_signed_job
169
+
170
+ verdict = verify_signed_job(signed_job)
171
+ if verdict.ok:
172
+ ... # safe to submit / settle
173
+ ```
174
+
175
+ ```python
176
+ # Read-only chain query (no signing, no key needed).
177
+ from bnbagent_studio_core.tools.chain_readonly import balance_u
178
+
179
+ print(balance_u(network="bsc-testnet"))
180
+ ```
181
+
182
+ ## Dependencies & boundaries
183
+
184
+ Runtime dependencies (lean by design):
185
+
186
+ - `bnbagent`, `web3`, `eth-account`, `httpx`, `tomlkit`, `python-dotenv`
187
+ (and `tomli` on Python < 3.11).
188
+
189
+ Boundaries:
190
+
191
+ - **FastAPI/uvicorn are `[serve]`-only.** The agent runtime never imports them;
192
+ the seller-hosting helpers import FastAPI lazily.
193
+ - **Framework- and runtime-agnostic.** This library does NOT import ADK,
194
+ LangChain, or bedrock-agentcore — those couplings live in the CLI's emitted
195
+ recipes, not here.
196
+ - **The SDK protocol layer stays pure.** Studio's opinions wrap `bnbagent`;
197
+ they never pollute it.
198
+
199
+ Python ≥ 3.10.
200
+
201
+ ## Further reading
202
+
203
+ - [Main repository](https://github.com/bnb-chain/bnbagent-studio) — overview,
204
+ guides, and the `bag` CLI.
205
+ - [Architecture](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/design/architecture.md)
206
+ — the layered design and two-layer deploy model.
207
+ - [Reference](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/reference.md)
208
+ — CLI / recipe / MCP-tool / library reference.
209
+ - [User Guide](https://github.com/bnb-chain/bnbagent-studio/blob/main/docs/guides/user-guide.md)
210
+ — the install → skills → Claude Code → `bag dev` path (for CLI end-users).
211
+
212
+ ## License
213
+
214
+ Apache-2.0.
@@ -0,0 +1,36 @@
1
+ """bnbagent_studio_core — convenience re-exports for agent code.
2
+
3
+ Architecture.md §9.1 specifies this package's `__init__.py` exposes the public
4
+ surface that user-emitted agent code imports:
5
+
6
+ from bnbagent_studio_core import get_wallet, get_policy
7
+
8
+ Lower-level surfaces stay reachable via their submodules:
9
+
10
+ from bnbagent_studio_core.networks import get_network
11
+ from bnbagent_studio_core.erc8183 import buy_workflow, ...
12
+ from bnbagent_studio_core.erc8004 import register, ...
13
+ from bnbagent_studio_core.llm import _resolve_provider_config, ProviderConfig
14
+
15
+ ``load_model`` is not part of this surface — emitted agent projects
16
+ construct their model object from ``agent/managed_model.py`` (scaffolded by
17
+ ``providers/<provider>/code/<framework>/``) which calls
18
+ ``bnbagent_studio_core.llm._resolve_provider_config`` directly. Studio no longer
19
+ imports any agent framework (ADK / etc.) from this package.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ from bnbagent_studio_core.config import find_project_root, load_studio_toml
25
+ from bnbagent_studio_core.policy import Policy, get_policy
26
+ from bnbagent_studio_core.telemetry import emit
27
+ from bnbagent_studio_core.wallet import get_wallet
28
+
29
+ __all__ = [
30
+ "Policy",
31
+ "emit",
32
+ "find_project_root",
33
+ "get_policy",
34
+ "get_wallet",
35
+ "load_studio_toml",
36
+ ]