Contexting Mechanism in QonQrete
QonQrete’s contexting mechanism is how the system provides its AI agents (including Qwen) with the necessary information to understand their current task, the state of the codebase, and the historical progression of work. It’s designed to be dynamic, layered, and optimized for LLM consumption.
The primary goal of contexting is to ensure that LLMs receive relevant, actionable information within their limited context windows, preventing “hallucination” and keeping them grounded in the project’s reality.
Layers of Context
QonQrete builds context for its AI agents using several interconnected layers:
1. tasq.d/ (Current Directive Context)
- Source:
qrane/paths.py, generated byqrane.pyandhandle_cheqpoint. - Content: The
cyqleXXX_tasq.mdfile contains the explicit instructions and objectives for the current cycle. This is the most direct and immediate form of context. - Role in AI interaction: This file is usually the primary prompt for the
instruqtoragent, setting the stage for what needs to be done. It often incorporates thereQapfrom the previous cycle, linking historical feedback to the current directive.
2. bloq.d/ (Structural Context / Code Skeletons)
- Source:
worqer/qompressor.pypopulates this directory (worqspace/bloq.d). - Content: Contains “qompressed” versions of source code files. These files retain structural elements (imports, function/class signatures, docstrings, comments) but strip out implementation bodies.
- Role in AI interaction: Provides LLMs with an architectural overview of the codebase. When an agent needs to understand how to interact with an existing component or where to place new code, the
bloq.dfiles offer a token-efficient map of the system’s structure. This structural context is often explicitly passed via thecontext_filesargument toworqer/lib_ai.py.
3. qontext.d/ (Semantic Context / Code Index)
- Source:
worqer/qontextor.pypopulates this directory (worqspace/qontext.d). - Content: Stores YAML summaries of files. This process is now dual-mode:
- Local Mode (
provider: local): When configured for local execution,qontextorperforms a deterministic analysis using a sophisticated stack of local tools. This is the default and recommended mode.- Python AST: Extracts the fundamental structure of the code, including function and class names and their signatures.
- Docstrings: Parses docstrings to get a high-confidence understanding of what a function or class does.
- Verb Heuristics: When docstrings are missing, it infers the purpose of a function based on its name (e.g.,
get_userimplies retrieval). - Jedi: Performs static analysis to understand types and relationships between different parts of the code.
- PyCG: Generates a call graph to understand the dependencies and execution flow between functions and modules.
- Fast vs. Complex Mode:
local_mode: 'fast': Uses the first four layers of the stack for a very fast analysis.local_mode: 'complex': Adds a fifth layer, using a localsentence-transformersmodel to create deep semantic embeddings of the code’s purpose.
- AI Mode (
provider: [ai_provider]): In legacy mode, it uses an AI to generate YAML summaries. For code, this includes structured data about symbols (name, type, signature, purpose, dependencies). For documentation and configuration, it includes concise summaries.
- Local Mode (
- Role in AI interaction: Offers a higher-level, semantically rich understanding of the codebase. Agents can query this context to find relevant functions, understand their purposes, and identify dependencies without processing raw code. This semantic context is also passed via the
context_filesargument toworqer/lib_ai.py, supplementing or replacing direct code examination. The generation of this context can be disabled by settinguse_qontextor: falseinconfig.yaml.
4. QONQ_PREVIOUS_LOG (Operational History Context)
- Source:
qrane.pyandworqer/lib_ai.py. - Content: The content of the
qonsole.logfile from the immediately preceding agent’s execution. - Role in AI interaction:
worqer/lib_ai.pyautomatically injects this log as “FALLBACK CONTEXT” into the LLM prompt. This provides the current agent with an immediate historical context of what the previous agent did, saw, or outputted, ensuring continuity in multi-step operations.
5. qodeyard/ (Raw Codebase / Reference Context)
- Source: The initial codebase provided to QonQrete.
- Content: The full, uncompressed source code, documentation, and configuration files.
- Role in AI interaction: While not directly fed to LLMs in its entirety due to token limits,
qodeyardserves as the ultimate source of truth. Agents might refer to specific files fromqodeyardwhen deep understanding or precise code modification is required, often by using tools that allow them to read specific files.qompressorandqontextorderive their initial information fromqodeyard.
6. config.yaml and pipeline_config.yaml (System Configuration Context)
- Source: User-defined configuration files in
worqspace/. - Content: Defines system-wide parameters, agent configurations, AI provider details, and the pipeline of agents to be executed.
- Role in AI interaction: While not directly fed to LLMs as a prompt, these configurations dictate the behavior of the QonQrete system itself, influencing how context is built and which agents are used. Certain agents might be designed to interpret or modify these configurations.
The Contexting Process
The contexting process in QonQrete involves:
- Initial Warmup: When
qrane.pydetects aqodeyard, it orchestrates an initial run ofqompressor(to buildbloq.d) andqontextor(to buildqontext.d), establishing foundational structural and semantic context. - Cycle-based Updates: In each operational cycle, the
tasq.mdprovides the primary directive. Agents, when making LLM calls vialib_ai.py, dynamically assemble a prompt that includes:- The
base_prompt(task-specific instructions). - The
QONQ_PREVIOUS_LOG(operational history). - Relevant files from
bloq.d(structural context). - Relevant files from
qontext.d(semantic context).
- The
- Cheqpoints and User Feedback: At
cheqpoints, thereQap(operational memory) is presented. User review and potential edits directly influence thetasq.mdfor the next cycle, effectively allowing human intervention to refine the context.
By combining these layers, QonQrete ensures that its AI agents operate with a rich, layered, and token-optimized understanding of their environment and tasks.