Skip to main content

Manage, retrieve, and compact AI project instructions, lessons learned, and contextual rules for LLM workflows.

Project description

Contextile

Contextile is a Python toolkit for managing, retrieving, and compacting AI project instructions, lessons learned, and contextual rules for LLM workflows.

Documentation guides:

The MVP focuses on a small local workflow:

  • initialize a .contextile/ workspace;
  • store durable lessons in JSONL;
  • validate lesson records;
  • search relevant lessons for a task;
  • build a compact Markdown context block for an LLM;
  • run a thin MCP server layer on top of the same core functions.

Install locally

pip install -e .

Initialize a project

contextile init

This creates:

.contextile/
  config.json
  lessons.jsonl
  project-rules.json
  instructions/
    project-context.md
    architecture-rules.md
    code-standards.md
    validation.md

Add a lesson

contextile add-lesson \
  --id preserve-domain-terms \
  --when "Editing existing domain terms in code, docs, routes, schemas, enums, or API contracts." \
  --do "Preserve domain terms exactly as used in the project." \
  --avoid "Do not translate established domain terms." \
  --scope "Code, docs, API, DB, routes, enums, UI." \
  --tags domain,terminology,api,routes,enums

Search lessons

contextile search "api validation reports" --limit 5

Build compact context

contextile build-context \
  --task "Refactor API validation for reports" \
  --file src/schemas/par/relatorio.py \
  --tag api \
  --tag validation \
  --rule-limit 6 \
  --max-tokens 800

By default, build-context selects relevant rules from:

  • bundled default rule catalog (ships with Contextile);
  • optional project overrides/extensions in .aiassistant/rules.

Selection uses:

  • project profiles from .contextile/project-rules.json;
  • detected stack/dependencies (pyproject.toml, requirements*.txt, directories);
  • task text, file hints, and tags.

When rules are selected, they are always included in full (not token-truncated). --max-tokens applies to non-rule sections.

Use --no-rules to disable rule selection for a call.

Validate records

contextile validate

Compact records

contextile compact

Detect and manage rule profiles

contextile detect-rules
contextile detect-rules --write
contextile list-rule-scenarios
contextile apply-rule-scenario --scenario python-core
contextile apply-rule-scenario --scenario fastapi-api
contextile select-rules --task "add sqlalchemy pagination" --file src/repositories/orders.py
contextile validate-rules

detect-rules --write updates .contextile/project-rules.json (enable_profiles) so existing projects can adopt rule selection quickly. apply-rule-scenario updates enabled_scenarios using predefined scenario groups from the bundled catalog plus any project rules.

Run MCP server

Install MCP extra:

pip install -e ".[mcp]"

Run over stdio (default):

contextile mcp-server --root .

or:

contextile-mcp --root .

Run over HTTP transport:

contextile mcp-server --root . --transport streamable-http

Available MCP tools:

  • build_context_tool
  • build_agents_md_tool
  • add_lesson_tool
  • search_lessons_tool
  • select_rules_tool
  • detect_rules_tool
  • validate_rules_tool
  • list_rule_scenarios_tool
  • apply_rule_scenario_tool

Lesson JSONL schema

Each line in .contextile/lessons.jsonl is one lesson:

{"id":"preserve-domain-terms","when":"Editing existing domain terms.","do":"Preserve terms exactly as used.","avoid":"Do not translate established terms.","scope":"Code, docs, API, DB, routes, enums, UI.","tags":["domain","terms","api"]}

Required fields:

  • id
  • when
  • do
  • avoid

Recommended fields:

  • scope
  • tags
  • why
  • updated_at

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

contextile-0.2.0.tar.gz (114.2 kB view details)

Uploaded Source

Built Distribution

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

contextile-0.2.0-py3-none-any.whl (138.0 kB view details)

Uploaded Python 3

File details

Details for the file contextile-0.2.0.tar.gz.

File metadata

  • Download URL: contextile-0.2.0.tar.gz
  • Upload date:
  • Size: 114.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for contextile-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c0b5cc4f4496bd6b3e046fef6edd562d5fe74ee14a9ec6077f24f88643164ef1
MD5 686057cc14706fad9e46d03b2a9a5ead
BLAKE2b-256 58680c65422fbffb3225698517d6ddf22f5b24d4799697297543ac8b90faaab3

See more details on using hashes here.

File details

Details for the file contextile-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: contextile-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 138.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for contextile-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a311b7adeac7db5d495987124665331622162aee8832a695a47ac94c27d98ab2
MD5 d1684cd903d1e939b05940f8f00a7764
BLAKE2b-256 2d0a7ad27ad270b2ee4593cd4eefdf0d438072308af970e95ca57cba062bf99c

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