Skip to main content

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 serve daemon (default http://127.0.0.1:11434). Cross-platform, transparent MLX on Apple Silicon, and supports JSON-schema constrained output via Ollama's format parameter — used by the S-PAL flow to synthesise validated RequestContext proposals.
  • llama-cpp-python (in-process, "no daemon") — kept as a fallback for single-executable demos. Requires the optional llm extra: 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 docs/decisions). 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
FREEHOLD_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
FREEHOLD_APPROVAL_MODE manual Autonomous approval mode: manual, auto_with_notification, or fully_autonomous
CARDANO_API_URL http://localhost:8080 Cardano devnet API endpoint
FREEHOLD_LLM_BACKEND llamacpp ollama or llamacpp
FREEHOLD_LLM_TIER default default (Qwen3.6-27B) or small (Phi-4-mini)
FREEHOLD_OLLAMA_URL http://127.0.0.1:11434 Ollama daemon base URL
FREEHOLD_OLLAMA_MODEL (from tier) Explicit Ollama model tag override
FREEHOLD_OLLAMA_TIMEOUT 120.0 Per-request HTTP timeout (seconds)
FREEHOLD_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

License

Apache 2.0

Metadata

Release files for freehold-agent 0.3.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 freehold-agent 0.3.0
File Size Uploaded Provenance Actions
freehold_agent-0.3.0.tar.gz 62.2 kB With provenance Details for freehold_agent-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for freehold-agent 0.3.0
File Interpreter ABI Platform Actions
freehold_agent-0.3.0-py3-none-any.whl Python 3 none any Details for freehold_agent-0.3.0-py3-none-any.whl

Total release size: 113.5 kB

Release files / freehold_agent-0.3.0.tar.gz

Download URL freehold_agent-0.3.0.tar.gz
Size 62.2 kB
Tags Source
SHA-256 checksum
How to use checksums
744db7be74c0cfc4e0d62f7a5608310a90f2c05f48967b123672b3e0db3104ce
BLAKE2b-256 checksum
How to use checksums
606f08151671911e8e260a6921f6cc04d9736c8587fba06c99768240b0b9ec1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 3, 2026.

Transparency log

Release files / freehold_agent-0.3.0-py3-none-any.whl

Download URL freehold_agent-0.3.0-py3-none-any.whl
Size 51.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75f9c3159bbf388fe707ead1aec96199a70a272eb5433461df2521e80c9176be
BLAKE2b-256 checksum
How to use checksums
e6e0850f52f36da10c2a3c609028e3d9574eaef87db02d697b6c8f7df0943f56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 3, 2026.

Transparency log

Security for freehold-agent 0.3.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for freehold_agent-0.3.0.tar.gz

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 Nov 3, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

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