Skip to main content

A lightweight, agent-centric context management framework for LLMs.

Project description

ContextAware

ContextAware is a lightweight, agent-centric context management framework. It acts as a "Map Provider" for LLMs, allowing them to navigate large codebases efficiently without consuming massive amounts of tokens.

🚀 Why ContextAware?

Standard RAG (Retrieval-Augmented Generation) is often too imprecise for coding tasks (missing dependencies, hallucinating imports). Reading the entire codebase is too expensive and slow.

ContextAware solves this by treating your code as a Navigable Graph.

  • Token Efficiency: Reduces exploration costs by 90% via "Skeleton Mode".
  • Zero Hallucinations: Provides explicit dependency chains (Import Graph).
  • Scalable: Built on SQLite + AST Analysis, works on projects of any size.
  • Agent-Ready: Returns structured XML optimized for LLM consumption.

🤖 Agent Protocol (How to use this tool)

If you are an AI Agent (e.g., Devin, Cline, Gemini Code Assist), follow this explicit protocol to solve tasks with maximum efficiency.

Workflow: "Skeleton-First" Navigation

Do not read file contents blindly. Use the tool to find what matters.

Phase 1: Discovery (Low Cost)

Ask "Where is the code related to X?" getting only the high-level structure.

  • Command: context_aware query "your search terms" --mode=skeleton
  • Goal: Identify relevant classes/functions and their relationships.
  • Output: You will see signatures and <dependencies> tags.

Phase 2: Traversal (Optional)

If a class depends on another service (e.g., OrderProcessor uses InventoryService), follow the link.

  • Command: context_aware retrieve "class:inventory.py:InventoryService" --mode=skeleton
  • Goal: Understand the API of the dependency without reading its implementation.

Phase 3: Extraction (High Cost, High Value)

Once you pinpoint the exact function/class to modify or debug, fetch its full source code.

  • Command: context_aware retrieve "function:file.py:target_function"
  • Goal: Get the actual code to work on.

� Installation & Setup

  1. Install via pip:

    pip install context-aware
    
  2. Initialize a Project: Navigate to your target project root and run:

    context_aware init
    

    Or for an external project:

    context_aware --root /path/to/project init
    
  3. Index the Codebase: Parse and store the project structure (runs locally, no data leaves your machine).

    context_aware index .
    # Or
    context_aware --root /path/to/project index /path/to/project
    

📖 CLI Reference

init

Creates the local SQLite store (.context_aware/context.db).

context_aware init

index <path>

Parses Python files, extracts AST nodes (classes, functions, imports), and updates the graph.

context_aware index ./src

query <text>

Semantic fuzzy search on the graph.

  • --mode=skeleton (Recommended): Returns signatures + dependencies.
  • --mode=full: Returns full source code.
context_aware query "payment processing" --mode=skeleton

retrieve <id>

Fetches a specific item by its unique ID (found in previous query results).

context_aware retrieve "class:payments.py:PaymentGateway"

Global Options

  • --root <path>: Specify the root directory of the project (where .context_aware lives). Essential when working on projects outside the current working directory.

⚡️ Example Scenario

Task: "Fix a bug in the discount calculation logic."

  1. Agent asks: Where are discounts handled?

    context_aware query "discount calculation" --mode=skeleton
    

    Output: Found class:PricingService in pricing.py. It uses UserTierService.

  2. Agent analyzes: I see PricingService.calculate_discount. I need to see the code.

    context_aware retrieve "class:pricing.py:PricingService"
    

    Output: Full Python code of the class.

  3. Agent executes: The bug is identified. The agent creates a patch.


🏗 Architecture (v0.4 - Hybrid Lookup)

  • Analyzer: PythonAnalyzer extracts symbols and dependencies but stores only metadata (pointers) in the DB to keep it light.
  • Store: SQLiteContextStore with FTS5 for fast fuzzy search of docstrings and names.
  • Router: GraphRouter performs graph traversal on the metadata.
  • Retriever: On-Demand AST Parsing. When you request code (retrieve), the system reads the file from disk at that moment and extracts the function body. This ensures zero stale data—you always get the current code.
  • Compiler: Converts nodes into XML prompts (<item>, <dependencies>) for the LLM.

⚠️ Limitations

  • Language Support: Currently optimized for Python only.
  • Semantic Understanding: Relies on keyword/symbol matching + FTS. Does not yet use Vector Embeddings (planned for v0.5).

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_aware-0.1.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

context_aware-0.1.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file context_aware-0.1.1.tar.gz.

File metadata

  • Download URL: context_aware-0.1.1.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for context_aware-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d858c9c03e66ce11f1e1617fc1f67e3106a3c92ed68313cedd6b0af96384ac0e
MD5 513b47a6ef65b652ee2e10d0000cbc9d
BLAKE2b-256 c8e8487df0ea7c3683ae6f7757baff01b6a1505c87b9e1705e3a7f3e3ac223bf

See more details on using hashes here.

File details

Details for the file context_aware-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: context_aware-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for context_aware-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb75b9ed26f281349775c412350606171e77d15456be98befb7c0838b9e1e00e
MD5 869337eb7f3c247d98be59e7386aa061
BLAKE2b-256 ff5472570641435afc1febfa4c03e0d63216af2b23f3c180b00cc1fdfad64cc0

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