Skip to main content

FastAPI service and toolkit for managing AI agent contexts, prompts, and memories.

Project description

Context Control

Context Control is a FastAPI-powered service and Python package for storing and serving AI agent context, prompt telemetry, and long-term memories. It gives teams a single place to manage reusable personas, model configuration, retrieval manifests, and per-user memories.

Why Context Control?

  • Agent-ready storage – Persist system prompts, model configs, and retrieval manifests per agent + label.
  • Prompt audit trail – Capture prompts and (optional) completions for analytics, training, or debugging.
  • User memories – Store both general agent memories and user-scoped memories with arbitrary metadata.
  • Built-in dashboard – A lightweight local UI (/dashboard) to inspect stored data while developing.
  • Local-first utilities – Seed demo data, smoke-test the API, or push curated contexts to remote deployments.

Installation

Install the package (and its CLI utilities) from source:

python -m venv .venv
source .venv/bin/activate
pip install -e .

The editable install keeps the package in sync with your working tree while you iterate.

Quick Start

  1. Run the API

    context-control-api --reload
    

    The first launch creates context_control.db (SQLite) alongside the code.

  2. Visit the dashboard

    Open http://127.0.0.1:8000/dashboard to view contexts, prompts, and memories in real time.

  3. Seed sample data (optional)

    python scripts/seed_local_db.py
    
  4. Smoke test the API

    python scripts/test_local_api.py
    

    The script upserts a context, records a prompt, creates a memory, and verifies the results end-to-end.

Library Usage

Use the ContextControlClient to interact with the store either locally (direct SQLAlchemy) or over HTTP:

from context_control import ContextControlClient, models

client = ContextControlClient(mode="local")

package = models.ContextPackage(
    system_prompt="Explain things simply.",
    config=models.ConfigModel(
        model_provider="openai",
        model_name="gpt-4o-mini",
        temperature=0.3,
        max_tokens=800,
        top_p=1.0,
    ),
    rag_manifest=models.RagManifestModel(
        version="1.0.0",
        sources=[{"id": "faq", "type": "file", "path": "./docs/faq.txt"}],
    ),
)

client.upsert_context("assistant", "beta", package)
print(client.get_context("assistant", "beta"))

Switch to HTTP mode by instantiating with ContextControlClient(mode="remote", base_url="https://context-control.com").

Core REST Endpoints

  • GET /contexts – list every stored context.
  • GET /contexts/{agent} – list contexts for a single agent.
  • GET /contexts/{agent}/{label} – retrieve a specific context envelope.
  • POST /contexts/{agent}/{label} – create or update a context.
  • DELETE /contexts/{agent}/{label} – remove a context.
  • POST /prompts – log a prompt/response pair.
  • GET /prompts – list prompts (filterable by agent_name and label).
  • POST /memories – create a general or user-specific memory.
  • GET /memories – list memories, optionally filtered by agent/user and including general memories.
  • DELETE /memories/{memory_id} – delete a stored memory.
  • GET /dashboard – serve the local dashboard UI.

Development Utilities

  • scripts/seed_local_db.py – Seed contexts, prompts, and memories into the SQLite store.
  • scripts/test_local_api.py – Run a smoke test against a local API instance.
  • scripts/push_contexts.py – Push context payloads to any Context Control deployment (defaults to https://context-control.com, configurable via --base-url).
  • context-control-mcp – Start a JSON-over-stdio MCP-style server that mirrors the REST endpoints (send newline-delimited JSON commands such as {"id":1,"command":"list_contexts"}).

Use PYTHONPATH=. when invoking scripts directly to ensure they resolve the local package modules.

Remote Deployments

The scripts/push_contexts.py helper is designed to sync local context definitions with remote deployments (e.g., the placeholder production endpoint at https://context-control.com). Provide a custom payload via --payload-path or override the destination with --base-url.

Configuration Notes

  • Swap the default SQLite database by setting CONTEXT_CONTROL_DATABASE_URL or editing the engine configuration in context_control/storage.py.
  • Add authentication (e.g., API keys, OAuth) via FastAPI dependencies before exposing the service publicly.
  • Extend the data models or add new tables by defining additional SQLAlchemy models and accompanying endpoints.

Packaging & Releases

PyPI publishing instructions live in PUBLISHING.md to keep this README focused on product usage.

License

MIT License. Add or update LICENSE as appropriate for your project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

context_control-0.0.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

context_control-0.0.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file context_control-0.0.1.tar.gz.

File metadata

  • Download URL: context_control-0.0.1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for context_control-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e8701c7957c77b83b9ead6ea3e1af114802b13676237453b292e759c9a748b83
MD5 bdb8304a00ab90babf48a49a06738314
BLAKE2b-256 6ebf3cfdb203640ae8c5a18ffa6ed2a024e9ef3a403708cfa26323202420a7e0

See more details on using hashes here.

File details

Details for the file context_control-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for context_control-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f82f0eb31a4a2691d9b2899f5ca31499e362b84b2569c571ec6528d4336d0564
MD5 661e6d038ee9aca7f0b747be35c7b785
BLAKE2b-256 f0d8ad58355287b64e4d7c22bc399f9a87f684300862d5661b3b9f1949d6a7db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page