Skip to main content

koa-fhe

Confidential coprocessor client — compute on encrypted data via Koa's FHE service.

The server never sees plaintext. Your data is encrypted locally, evaluated under Fully Homomorphic Encryption, and decrypted locally. Every query costs $0.001–$0.10 USDC via x402.

Install

pip install koa-fhe            # core (compare, add, multiply, schedule analysis)
pip install koa-fhe[ml]        # + encrypted ML inference (XGBoost workload scoring)

CLI (Agent-to-Agent)

No install needed — run ephemeral via uvx:

uvx koa-fhe health                                    # service status
uvx koa-fhe compare 85 80                             # {"greater": true, ...}
uvx koa-fhe add 500 300                               # {"value": 800, ...}
uvx koa-fhe multiply 7 13                             # {"value": 91, ...}
uvx koa-fhe verify --circuit add --queries 5          # integrity check
uvx koa-fhe --server http://remote:3410 compare 85 80 # remote server

Every command outputs JSON to stdout. Exit code 1 if integrity verification fails. Agents can call this as a subprocess — no venv, no imports, no state management.

Also works with pipx run koa-fhe or python -m koa_fhe.

Python API

import koa_fhe

client = koa_fhe.Client()  # default: localhost:3410

# Encrypted comparison — server never sees 85 or 80
result = client.compare(85, 80)
print(result.greater)  # True

# Encrypted addition
result = client.add(500, 300)
print(result.value)  # 800

# Encrypted multiplication
result = client.multiply(7, 13)
print(result.value)  # 91

API Reference

Client(server, *, payment_proof)

Method Returns Latency Price
compare(a, b) CompareResult(greater, stats) ~625ms $0.002
add(a, b) ArithmeticResult(value, stats) ~260ms $0.001
multiply(a, b) ArithmeticResult(value, stats) ~685ms $0.002
measure_rigidity(old, new) RigidityResult(hamming_distance, rigidity_score, severity, stats) ~3.5s $0.05
analyze_schedule(old, new, *, constraints, alpha, beta) ScheduleAnalysis(objective, ...) ~5s $0.10
predict_workload(features) WorkloadPrediction(predictions, stats) ~7s $0.01
verify_integrity(circuit, n_queries, *, seed) IntegrityResult(passed, queries, proofs) varies same as circuit
health() ServiceHealth(status, circuits, ...) instant free
circuits() dict — circuit catalog with hashes, pricing instant free

Warm-up & Readiness

Key generation is the slowest step (~2-30s per circuit). Use warm_up() to pre-generate keys in background threads:

client = koa_fhe.Client()
client.warm_up(["add", "threshold"])  # keygen in background

# ... do other work ...

print(client.ready)  # {"add": True, "threshold": True}
result = client.add(1, 2)  # instant — keys already ready

Key Deduplication

Evaluation keys are content-addressed (SHA-256). If you create multiple Client instances with the same circuits, the SDK detects duplicate keys on the server via HEAD /keys/{circuit}?hash=... and reuses them — no redundant uploads.

How it works

  1. On first call, the SDK downloads circuit specs from the server
  2. Keys are generated locally — the server never sees your secret key
  3. Key hash is checked against server — if a matching key exists, it's reused
  4. Otherwise, keys are uploaded (with integrity verification via X-Content-Hash)
  5. Inputs are encrypted locally, sent as ciphertext
  6. Server evaluates the FHE circuit on ciphertext
  7. Encrypted result returns, SDK decrypts locally

Key setup is cached per circuit. Subsequent calls skip steps 1-4. Server-side key management enforces TTL (24h default) and per-circuit caps (10 keys max).

LangChain Integration

pip install koa-fhe[langchain]
from koa_fhe.langchain import koa_tools
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI

agent = initialize_agent(
    tools=koa_tools("http://your-koa-server:3410"),
    llm=ChatOpenAI(),
    agent=AgentType.OPENAI_FUNCTIONS,
)

agent.run("Is 85 greater than 80? Use encrypted comparison.")

Tools: koa_encrypted_compare, koa_encrypted_add, koa_encrypted_multiply, koa_encrypted_rigidity, koa_encrypted_schedule_analysis, koa_fhe_health.

Integrity Verification

Agents can verify that the FHE service computes correctly by interleaving trap queries — test vectors with known plaintext answers. Because FHE hides the inputs, the server cannot distinguish trap queries from real ones.

result = client.verify_integrity("add", n_queries=5, seed=42)
print(result.passed)   # True — all trap queries returned correct results
print(len(result.queries))  # 5

# If the server ever returns a wrong result:
if not result.passed:
    for proof in result.proofs:
        print(proof.circuit, proof.inputs, proof.expected, proof.actual)
        # → Submit proof to KoaIntegrity smart contract for on-chain slashing

Supported circuits: add, multiply, threshold. See contracts/KoaIntegrity.sol for the on-chain slashing mechanism.

Discovery

The FHE service exposes machine-readable metadata for agent-to-agent integration:

  • OpenAPI spec: GET /openapi.yaml
  • Service manifest: GET /.well-known/x402 — x402 payment info, service catalog, ERC-8004 identity
  • Agent aliases: /v1/confidential/{predicate,aggregate,arithmetic,rigidity,analysis,predict}

On-chain identity: ERC-8004 Agent #21648 on Base mainnet.

Dependencies

Core (pip install koa-fhe): concrete-python + numpy. Handles compare, add, multiply, rigidity, and schedule analysis.

ML (pip install koa-fhe[ml]): adds concrete-ml for encrypted XGBoost inference. This pulls in PyTorch, scikit-learn, etc. — only install if you need predict_workload().

License

MIT

Metadata

Release files for koa-fhe 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for koa-fhe 0.2.0
File Size Uploaded Provenance
koa_fhe-0.2.0.tar.gz 18.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for koa-fhe 0.2.0
File Interpreter ABI Platform
koa_fhe-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.9 kB

Release files / koa_fhe-0.2.0.tar.gz

Download URL koa_fhe-0.2.0.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b03eb94499a12ed3f2597a5d09a31ad7090d7f92a8cf14f8acdfecfbb9ad91dc
BLAKE2b-256 checksum
How to use checksums
e0565208116627ec054cfb56d873845bcf1867d3b073a5836d598781f884cb99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / koa_fhe-0.2.0-py3-none-any.whl

Download URL koa_fhe-0.2.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac1155e36ea4f7a4135b6615d1323121dce126949f837ae7da5285a7fed28062
BLAKE2b-256 checksum
How to use checksums
36ec8b623a7db44c91fb12177961a4592d8bd84eccad875877178a8f89513c8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for koa-fhe 0.2.0

Provenance

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page