Standalone local-commerce AI consultation marketplace runtime
pip install shopping-cli==3.2.11 Copy PIP instructions
shopping-cli is a standalone, SQLite-backed AI consultation runtime for local commerce. Merchants publish shop profiles, products, stock, and delivery rules; buyers search nearby supply, open consultations, and receive deterministic merchant-agent replies.
The MVP is not a transaction system. It does not create commitments, reserve stock, process payment, record payment state, custody funds, handle refunds, dispatch couriers, or claim delivery success. Buyer intent is recorded only as quote_request or purchase_intent messages in a conversation.
Pending merchant states are not failures. When a conversation is waiting_merchant, the buyer request has been handed to the merchant agent; when it is human_required, the merchant agent has escalated it to the merchant human. Keep the conversation open and wait for the next merchant-side message.
bash scripts/verify.sh For contributor checks, install the API and development extras, then run the same lint, type, coverage, and Node gates used by CI. Release verification builds both Python artifacts and installs the wheel into an isolated virtual environment before checking all three console entry points.
pip install -e '.[api,dev]' bash scripts/quality.sh bash scripts/verify_release.sh Optional API dependencies are declared in pyproject.toml for the FastAPI marketplace service:
pip install -e '.[api]' Quick Start python3 scripts/shopping.py --db ./shopping-cli.sqlite merchant create \ --id seller-a \ --name "West Lake Tea" \ --city Hangzhou \ --service-area "West Lake" \ --contact "wechat:westlake" \ --hours "09:00-21:00" \ --delivery-fee 12 \ --delivery-eta-minutes 45 \ --tags "tea,gift,longjing" python3 scripts/shopping.py --db ./shopping-cli.sqlite product add \ --merchant seller-a \ --sku tea-a \ --title "Longjing Gift Box" \ --price 88 \ --stock 5 \ --category tea \ --tags "longjing,gift" \ --delivery-attributes "same-city,courier" python3 scripts/shopping.py --db ./shopping-cli.sqlite merchant update --id seller-a --hours "10:00-20:00" python3 scripts/shopping.py --db ./shopping-cli.sqlite merchant list --limit 50 --offset 0 python3 scripts/shopping.py --db ./shopping-cli.sqlite delivery set --merchant seller-a --service-area "West Lake" --fee 12 --eta-minutes 45 python3 scripts/shopping.py --db ./shopping-cli.sqlite product update --merchant seller-a --sku tea-a --stock 4 --price 92 python3 scripts/shopping.py --db ./shopping-cli.sqlite search products --query "longjing" python3 scripts/shopping.py --db ./shopping-cli.sqlite search products --query "longjing" --limit 10 --offset 0 --format json python3 scripts/shopping.py --db ./shopping-cli.sqlite search merchants --query "west lake" --city Hangzhou python3 scripts/shopping.py --db ./shopping-cli.sqlite search merchants --query "west lake" --city Hangzhou --limit 10 --offset 0 --format json python3 scripts/shopping.py --db ./shopping-cli.sqlite buyer ask \ --buyer alice \ --text "longjing gift delivery today" \ --city Hangzhou \ --area "West Lake" python3 scripts/shopping.py --db ./shopping-cli.sqlite buyer ask \ --buyer alice \ --text "longjing gift delivery today" \ --city Hangzhou \ --area "West Lake" \ --format json python3 scripts/shopping.py --db ./shopping-cli.sqlite agent run --merchant seller-a --once --format json python3 scripts/shopping.py --db ./shopping-cli.sqlite buyer summarize --conversation CONV-0001 python3 scripts/shopping.py --db ./shopping-cli.sqlite buyer summarize --conversation CONV-0001 --format json python3 scripts/shopping.py --db ./shopping-cli.sqlite buyer intent --conversation CONV-0001 --intent purchase_intent --text "Buyer wants merchant confirmation." python3 scripts/shopping.py --db ./shopping-cli.sqlite buyer intent --conversation CONV-0001 --intent purchase_intent --text "Buyer wants merchant confirmation." --format json printf 'longjing gift delivery today\n/summary\n/quit\n' | \ python3 scripts/shopping.py --db ./shopping-cli.sqlite buyer chat --buyer alice --city Hangzhou --area "West Lake" --format json Default database path: ~/.local/share/shopping-cli/shopping-cli.sqlite.
For a single-merchant deployment, import commands can read the database and merchant identity from the environment instead of repeating tenant flags:
export SHOPPING_DB_PATH="$HOME/.local/share/shopping-cli/shopping-cli.sqlite" export SHOPPING_MERCHANT_ID="your-merchant-id" shopping-cli import-csv-excel --file products.csv KIWI_MERCHANT_ID is accepted as a compatibility alias for SHOPPING_MERCHANT_ID. Explicit --db and --merchant arguments take precedence over environment variables.
External channel adapters can ingest buyer messages through a stable local entry point before real WhatsApp, Telegram, Slack, or OpenClaw/Hermes gateway bridges are attached:
python3 scripts/shopping.py --db ./shopping-cli.sqlite channel ingest \ --channel whatsapp \ --external-user "+15550001111" \ --text "longjing gift delivery today" \ --city Hangzhou \ --area "West Lake" \ --format json python3 scripts/shopping.py --db ./shopping-cli.sqlite channel ingest \ --channel whatsapp \ --external-user "+15550001111" \ --conversation CONV-0001 \ --text "Any stock left?" \ --format json The buyer id is always derived as : for public channel ingress. Channel names are trimmed and lower-cased before buyer ids, metadata, and idempotency keys are written. Message payloads preserve source_id, channel, external_user_id, and optional external_message_id. When external_message_id is provided, retries with the same normalized (channel, external_user_id, external_message_id) return the original message or original no-match result instead of appending a duplicate or creating a later conversation from an old webhook retry. A stale processing ingress row older than five minutes is treated as abandoned so webhook delivery can recover after an interrupted attempt. The default channel ingest text output summarizes the derived buyer, idempotency state, conversation, message, routing status, and selected product; --format json preserves the full adapter payload.
The raw conversation lifecycle is available without the API server:
Use agent run --once for a single deterministic polling pass. Use the daemon lifecycle commands when a merchant agent should keep polling in the background:
python3 scripts/shopping.py agent start --merchant seller-a --db ./shopping-cli.sqlite --interval 3 --format json python3 scripts/shopping.py agent status --merchant seller-a --db ./shopping-cli.sqlite --format json python3 scripts/shopping.py agent logs --merchant seller-a --tail 20 --format json python3 scripts/shopping.py agent stop --merchant seller-a --db ./shopping-cli.sqlite --format json python3 scripts/shopping.py agent start --merchant seller-a --api-url http://127.0.0.1:8765 --agent-token "$SHOPPING_AGENT_TOKEN" --interval 3 --format json Pid, state, and log files are written under ~/.local/state/shopping-cli/ by default. Set SHOPPING_CLI_STATE_DIR to use a different state directory for tests or demos.
To run through the Marketplace API boundary instead of direct SQLite access:
External channel adapters can use POST /channels/messages with channel, external_user_id, text, and optional conversation_id, city, area, and external_message_id. API channel ingress requires SHOPPING_CHANNEL_TOKENS such as telegram:secret,whatsapp:secret2, or a global SHOPPING_CHANNEL_TOKEN; pass the matching token as channel_token or as a Bearer token. The optional external_message_id is an idempotency key for webhook retry safety, channel is normalized the same way as the CLI ingress path, and stale in-flight ingress claims are recoverable after five minutes.
POST /merchants requires SHOPPING_ADMIN_TOKEN as admin_token in the JSON body or as a Bearer token, then returns a local merchant_token once. Use Idempotency-Key for safe bootstrap retries; use POST /merchants/{merchant_id}/token/rotate with a current merchant token or the admin token if the credential must be replaced, and use the admin-only /token/revoke endpoint to revoke all merchant credentials. GET /merchants/{merchant_id}/private-config exposes automation_boundaries only to that merchant or its scoped agent. POST /buyer/ask and POST /conversations require SHOPPING_BUYER_BOOTSTRAP_TOKEN as buyer_bootstrap_token in the JSON body or as a Bearer token before creating durable buyer conversation state; each successful call still opens a fresh conversation and returns a buyer token scoped to that conversation. Merchant and buyer credentials have default TTLs, and closing a conversation revokes its buyer token. Product writes, merchant profile updates, merchant human replies, merchant/operator closes, and human-review resolution require that merchant token in the JSON body as merchant_token or as a Bearer token. Agent heartbeats, agent message processing, merchant-agent replies, merchant-agent closes, merchant-agent human-review flags, and tool-call audit writes may use either the merchant token or a scoped agent token. New merchant, buyer, and agent tokens are opaque and do not embed merchant or buyer ids. Raw tokens are stored only as SHA-256 digests with prefix/suffix hints for listing; stored token hashes are not accepted as bearer credentials. Agent status reads also require an owner token: /agents is scoped to the caller's merchant, and agent detail or merchant-agent list reads require the matching merchant/agent token. Scoped agent tokens can be revoked and can optionally expire through ttl_seconds. Conversation reads, buyer message appends, buyer closes, and human-review queue/detail reads require an owner token: buyer tokens can read or write only their issued conversation, while merchant and agent tokens can read conversations and review queues for their merchant. Buyer message appends cannot override conversation status, and generic message appends cannot close conversations; closes and human-review routing must use their explicit endpoints. Unresolved human review blocks normal close paths until resolution. Every close path records a conversation_closed audit event, including human-review close resolutions. Merchant or agent message appends that set human_required create a matching human-review flag so the queue and conversation state stay aligned. Closed conversations reject later message, close, and human-review mutations until an explicit audited reopen flow exists. Remote Marketplace API URLs require HTTPS unless SHOPPING_ALLOW_INSECURE_HTTP=true is explicitly set for a trusted internal network; long-running Agent credentials must be supplied through environment/secret injection rather than argv.
Serve the FastAPI app after installing API dependencies:
See references/negotiation-api.md for the full endpoint contract, policy-gate order, Kiwi integration flow, and known limitations.
Apache License 2.0 — 协议契约与参考实现同许可(与 Kiwi、kiwi-catalog 一致)。
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR U...
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




