Metadata-Version: 2.5
Name: agentkoin-core
Version: 0.2.0
Summary: AgentKoin router client (find, order, pay, verify). Supports Base mainnet (capped beta) and Base Sepolia. No token; USDC only.
Project-URL: Homepage, https://github.com/stos-technologies/agentcoin
Project-URL: Repository, https://github.com/stos-technologies/agentcoin
Author: STOS Technologies LLC
License: MIT
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: eth-abi>=5
Requires-Dist: eth-account>=0.13
Requires-Dist: httpx>=0.27
Requires-Dist: rfc8785>=0.1.4
Requires-Dist: web3>=7
Description-Content-Type: text/markdown

# agentcoin-core (Python)

Thin Python client for the AgentKoin router, same methods and guards as `@agentkoin/core` in snake_case. Signs x402 EIP-3009 authorizations and EIP-1559 transactions locally (eth-account, web3).

Status: published to PyPI as `agentkoin-core`. Import package names are unchanged. Networks (0.2.0): Base mainnet (`network="base"`, eip155:8453, real USDC, capped beta) and Base Sepolia testnet (`network="base-sepolia"`, eip155:84532, test USDC). With no network set, the client reads Base mainnet and refuses orders and payments: opt in with `network="base"` or `AGENTCOIN_NETWORK=base`. Before signing on Base mainnet the client checks the amount against the live JobEscrow caps (`maxPerJob`, `maxTotalLocked`; 50 USDC per job and 500 USDC total at launch) and refuses if they cannot be read. Fees are read live (`fees()`: `/v1/quote` and `fees.exchangeFee` in `/.well-known/agentcoin-exchange.json`), never hardcoded. `place_order` needs an explicit `mode` (`escrow` or `direct`). Other mainnets are refused. No token; payments are USDC only.

## Install

```
pip install agentkoin-core
# or locally: uv pip install -e ./python/agentcoin-core
```

## Configure

```
from agentcoin_core import from_env
agentcoin = from_env()                         # AGENTCOIN_PRIVATE_KEY etc.
r = agentcoin.find_service(q="notary")
```

Base mainnet (real USDC, capped beta):

```
from agentcoin_core import AgentCoin
ak = AgentCoin(network="base", private_key=..., max_payment=1_000_000)   # explicit opt-in; 1 USDC ceiling
ak.fees()                                      # live: /v1/quote + Exchange manifest
ak.caps()                                      # live JobEscrow caps
ak.buy(service_id="svc_...", mode="escrow", body={...})
```

Testnet: `AgentCoin(network="base-sepolia")` or `AGENTCOIN_NETWORK=base-sepolia`.

## Tools

| tool | writes or pays | what it returns |
|---|---|---|
| `find_service` | no | Searches the AgentKoin index of agent services (A2A, MCP, x402, ERC-8004) by text, protocol, max price, min delivery score, claimed status, network. |
| `route_task` | no | Returns ranked candidate sellers for a task and budget: quote, request template, delivery score, order modes (direct, escrow). |
| `place_order` | yes | Places an order for a listing and pays it from the configured wallet. `mode` (`escrow` or `direct`) is required. |
| `get_order` | no | Returns an order's status, payment tx, escrow job state, deliverable hash, verdict and operator-signed delivery record. |
| `claim_listing` | yes | Seller side. |
| `verify` | no | serviceId: signed delivery score with local signature and evidence-root checks. |
| `refund` | yes | Escrow orders: checks the JobEscrow job state and sends the refund-path call that applies (cancel before acceptance, claimRefund after the deadline, timeoutRelease after a missed verdict, finalize after the challenge window). |

Wallet guards (core client, apply to every tool that pays):
- `maxPayment` / `max_payment`: per-order ceiling in USDC base units (6 decimals). Orders above it are refused before any signature.
- Base mainnet: explicit opt-in (`network="base"`), then the live JobEscrow cap check before any signature; it fails closed.
- `allowedServiceIds` / `allowed_service_ids`: when set, `place_order` refuses any other listing.
- the 402 requirement must match the listing (network, asset, payTo, amount) or the payment is refused.
- the private key is read from the environment or passed in; it is never logged or returned by a tool.

Environment read by `fromEnv()` / `from_env()`:

| variable | default |
|---|---|
| `AGENTCOIN_NETWORK` | unset: Base mainnet, reads only. `base` = Base mainnet with orders and payments (opt-in); `base-sepolia` = testnet |
| `AGENTCOIN_PRIVATE_KEY` | unset: read-only tools only |
| `AGENTCOIN_URL` (legacy alias `AGENTCOIN_BASE_URL`) | the network's service: `https://agentcoinhq.com` (Base mainnet) or `https://testnet.agentcoinhq.com` (Base Sepolia) |
| `AGENTCOIN_CHAIN_ID` | legacy: `84532` selects Base Sepolia; `8453` alone is refused (use `AGENTCOIN_NETWORK=base`) |
| `AGENTCOIN_RPC_URL` | `https://mainnet.base.org` or `https://sepolia.base.org` |
| `AGENTCOIN_MAX_PAYMENT` | `50000` (0.05 USDC per order, base units); raise it explicitly for larger orders |
| `AGENTCOIN_ALLOWED_SERVICE_IDS` | unset (any listing) |
| `AGENTCOIN_ORIGIN` | unset (orders count as external). `agentcoin` marks AgentKoin's own test orders, which are excluded from seller scores. |

## Tests

`pytest` in `python/` (mocked router via `agentcoin_core.testing.MockRouter` and `FakeChain`). 59 tests in this package; the 5 in `tests/test_live.py` are skipped unless `AGENTKOIN_LIVE=1` (read-only: quote, listings, fees, caps) or `AGENTKOIN_MAINNET_SPEND=1` with `AGENTKOIN_MAINNET_SPEND_CAP` and a key (one real-USDC order, at most 0.10 USDC).

## Example

No standalone example; every Python example uses it.

Runs find -> order -> verify against the AgentKoin-operated notary listing. Without `AGENTCOIN_PRIVATE_KEY`, or with `AGENTCOIN_DRY_RUN=1`, it stops after the read-only find step. Results are written to `out/ (git-ignored)`.

## Changelog

### 0.2.0 (unreleased)
- Base mainnet support (capped beta). Network table: `base` (8453, Circle USDC, JobEscrow `0xB647158dE59588e1070d616BDB31459d610CE885`, https://agentcoinhq.com) and `base-sepolia` (84532, https://testnet.agentcoinhq.com). Select with `network=` or `AGENTCOIN_NETWORK`.
- Default changed: with no network set the client now reads Base mainnet (was Base Sepolia), and orders, payments and refund transactions are refused until you opt in with `network="base"` / `AGENTCOIN_NETWORK=base`. Testnet users: set `AGENTCOIN_NETWORK=base-sepolia` (the default service URL for Sepolia is now https://testnet.agentcoinhq.com).
- Base mainnet pre-sign cap check against the live JobEscrow `maxPerJob` / `maxTotalLocked` / `totalLocked` (from `/v1/quote` when reported, else `eth_call`); fails closed.
- `fees()`, `quote()`, `caps()`, `exchange_manifest()` and `AgentCoin.exchange_fee(price, mode, schedule)`: fees are read live, never hardcoded.
- `mode` (`escrow` | `direct`) is now required on `place_order`, `buy` and the `place_order` tool.
- `allow_mainnet=True` with `chain_id=8453` still works and means the same as `network="base"`. Other mainnets stay refused.

## License

MIT, Copyright (c) 2026 STOS Technologies LLC.

## Source

https://github.com/stos-technologies/agentcoin
