Freehold Agent
Layer 2: Local AI agent for Personal Context Infrastructure.
Overview
The Freehold Agent provides:
- Local AI Processing - Run language models on your device
- Context Retrieval - Query encrypted context store
- Policy Enforcement - Validate requests against S-PAL policies
- Decision Support - AI-powered assistance without data leakage
Installation
# Clone and install
git clone https://github.com/freehold-earth/freehold.git
cd freehold/agent
uv sync
# With LLM support (llama-cpp-python)
uv sync --extra llm
Quick Start
from freehold_agent import Agent, AgentConfig
# Initialize agent
agent = Agent(
AgentConfig(
model_path="models/phi-3-mini-q4.gguf",
)
)
# Process a request with policy enforcement
response = await agent.process(
query="What are my upcoming appointments?",
policy_id="calendar-access",
)
print(response.content)
Architecture
flowchart TB
subgraph Agent["Freehold Agent"]
QH["Query Handler"]
QH --> PC["Policy Checker"]
QH --> CR["Context Retriever"]
QH --> LLM["LLM Inference"]
end
PC --> SPAL["S-PAL Policy"]
CR --> CS["Context Store"]
Supported Models
The agent works with GGUF-format models:
| Model | Parameters | RAM Required | Quality |
|---|---|---|---|
| Phi-3 Mini | 3.8B | 4GB | Good |
| Llama 3.2 | 3B | 3GB | Good |
| Mistral | 7B | 8GB | Better |
| Llama 3.1 | 8B | 10GB | Best |
Local Inference
Two backends are supported behind a single protocol:
- Ollama (recommended) — talks HTTP to a local
ollama servedaemon (defaulthttp://127.0.0.1:11434). Cross-platform, transparent MLX on Apple Silicon, and supports JSON-schema constrained output via Ollama'sformatparameter — used by the S-PAL flow to synthesise validatedRequestContextproposals. - llama-cpp-python (in-process, "no daemon") — kept as a fallback for
single-executable demos. Requires the optional
llmextra:uv sync --extra llm.
Named model tiers (Ollama backend):
| Tier | Model tag | Notes |
|---|---|---|
default |
qwen3.6:27b |
Primary tier for laptop / dev boxes with 16+ GB. |
small |
phi4-mini:3.8b |
Emergency fallback for <=8 GB RAM boxes. |
freehold-agent targets desktop and server runtimes; the mobile / on-device story lives in a separate native client (see ADR-006 in pci-docs). This release does not expose an on-device tier — Bonsai-27B and similar Q1_0 models depend on llama.cpp backend support that isn't yet wired into every Ollama build (see ollama/ollama#15359 for tracking).
Basic usage:
from freehold_agent import Agent, AgentConfig, LLMConfig
agent = Agent(AgentConfig(llm=LLMConfig(backend="ollama", ollama_tier="default")))
await agent.initialize()
try:
# S-PAL wiring: synthesise a RequestContext for the policy checker
request_ctx = await agent.propose_request_context(
"Business wants age >= 18 verification for alcohol purchase."
)
finally:
await agent.close()
Integration smoke tests against a live Ollama daemon:
ollama pull phi4-mini:3.8b
PCI_OLLAMA_MODEL=phi4-mini:3.8b uv run pytest -m ollama
Environment Variables
| Variable | Default | Description |
|---|---|---|
HOST |
127.0.0.1 |
Bind address; loopback by default. The container sets 0.0.0.0 to accept external traffic |
PORT |
8082 |
HTTP server port |
ZKP_SERVICE_URL |
http://localhost:8084 |
ZKP service endpoint |
PCI_APPROVAL_MODE |
manual |
Autonomous approval mode: manual, auto_with_notification, or fully_autonomous |
CARDANO_API_URL |
http://localhost:8080 |
Cardano devnet API endpoint |
PCI_LLM_BACKEND |
llamacpp |
ollama or llamacpp |
PCI_LLM_TIER |
default |
default (Qwen3.6-27B) or small (Phi-4-mini) |
PCI_OLLAMA_URL |
http://127.0.0.1:11434 |
Ollama daemon base URL |
PCI_OLLAMA_MODEL |
(from tier) | Explicit Ollama model tag override |
PCI_OLLAMA_TIMEOUT |
120.0 |
Per-request HTTP timeout (seconds) |
PCI_LLM_MODEL_PATH |
(unset) | GGUF path for the llama-cpp backend |
Development
# Install with dev dependencies
uv sync --group dev
# Run tests
uv run pytest
# Type check
uv run mypy src/
# Lint
uv run ruff check src/
# Run the agent
uv run python -m freehold_agent
Related Packages
- pci-spec - S-PAL schema and protocols
- pci-context-store - Layer 1: Context Store
- pci-contracts - Layer 3: Smart Contracts
- pci-zkp - Layer 4: Zero-Knowledge Proofs
- pci-identity - Layer 5: DID Management
License
Apache 2.0
Metadata
Release files for freehold-agent 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| freehold_agent-0.2.0.tar.gz | 61.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| freehold_agent-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 112.6 kB
Release files / freehold_agent-0.2.0.tar.gz
| Download URL | freehold_agent-0.2.0.tar.gz |
|---|---|
| Size | 61.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11aa65fdfe31ed1c338e0244734ff97b561a094d0c5406c9c0c7cb12290e7551
|
|
BLAKE2b-256 checksum How to use checksums |
0a12933ef3f22abb3120a13d569490fe03ed1f8f4f925f2b67a4e5e72fbeb8a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.
Transparency logRelease files / freehold_agent-0.2.0-py3-none-any.whl
| Download URL | freehold_agent-0.2.0-py3-none-any.whl |
|---|---|
| Size | 50.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ded5427aa97e5444f6fd064637e74bc4d3eb20b8a466b717525aa255822edbb5
|
|
BLAKE2b-256 checksum How to use checksums |
b0f87148d956716de15824dfcc1b44f66e56c604b2937417d61dc3d57a0104e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.
Transparency log