Centralized wallet usage primitives for Compass agents/services
Project description
compass-wallet-usage
Centralized wallet usage module (Python) for multi-agent Compass systems.
What this module provides
- Per-user, per-IST-day usage recording (
total_tokens, request count, optionalagent_idsplit) - Daily quota enforcement from env (
WALLET_DAILY_TOKEN_LIMIT) - Pluggable storage backends:
InMemoryWalletStorage(dev/tests)FirestoreWalletStorage(prod)
- ADK callback factory (
record_tokens_after_model) for Geminiusage_metadata - Built-in ADK user-id resolver (
resolve_user_id) for common callback context shapes - Optional FastAPI router exposing wallet status + record routes
Install (local repo)
pip install -e .
Quick start
from wallet import WalletService
from storage import InMemoryWalletStorage
wallet = WalletService(InMemoryWalletStorage())
wallet.record("user-123", 210, agent_id="mktg_banner_agent")
print(wallet.status("user-123"))
Quota
Set in host service env:
WALLET_DAILY_TOKEN_LIMIT=9000
Then call before model request:
wallet.enforce_daily_quota_if_configured(user_id)
ADK callback usage
from adk_callbacks import record_tokens_after_model
after_model_callback = record_tokens_after_model(
wallet=wallet,
agent_id="mktg_banner_agent",
)
record_tokens_after_model defaults to resolve_user_id, which checks:
callback_context.state["user_id" | "uid" | "firebase_uid" | "user_email"]- then
callback_context.user_id/callback_context.uid - fallback:
"unknown-user"
Optional FastAPI routes
from fastapi import FastAPI
from api import build_wallet_router
app = FastAPI()
app.include_router(build_wallet_router(wallet))
Routes:
GET /wallet/status?user_id=...POST /wallet/record
Notes
- This module is intentionally standalone and not integrated into other repos yet.
- Firestore backend requires
google-cloud-firestoreand ADC/service credentials.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file compass_wallet_usage-0.1.0.tar.gz.
File metadata
- Download URL: compass_wallet_usage-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6a8c0323e5f6eb9d30929e5f8c488250bd9d55eb0a88b364f3bf57e63c14ef0
|
|
| MD5 |
5db54666448b1113a3fdc1c609a4553a
|
|
| BLAKE2b-256 |
27b49c40a66192af1e3d9004fb3603ece97896efe6033722fba4d8a017b6ec5b
|
File details
Details for the file compass_wallet_usage-0.1.0-py3-none-any.whl.
File metadata
- Download URL: compass_wallet_usage-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d8e0ee04b52fb35593239948a159c6e6489afa65e23a90c85dceda14d5df69f
|
|
| MD5 |
6627013c606f8affd7c37ab183117911
|
|
| BLAKE2b-256 |
0e0cf4c77b7e0b6f0ea11360d9502c6a789ebb1f018cdf49502e26a2d48cc212
|