Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

13KB

Architecture decision records

The specification (section 20) leaves technology choices open and asks for each consequential choice to be recorded with alternatives and trade-offs. These records describe the choices this implementation made, most of them while building phases 1 to 3. Status is “accepted” unless noted. A change to one of them is a new record that supersedes it.

ADR-001 Runtime: Classic ASP on AxonASP

  • Context: the project started from an existing Classic ASP MVC starter and must run in a Linux container.
  • Decision: VBScript on AxonASP (a Go implementation of Classic ASP), the portable language subset of AGENTS.md section 2, native libraries (G3DB, G3CRYPTO, G3STRINGBUILDER) where they exist.
  • Alternatives: rewrite in a mainstream stack (Python, Go, Node); IIS on Windows.
  • Consequences: one small container, no build step, and the starter's MVC framework reused. In exchange the runtime has quirks that cost real time (AGENTS.md section 8: error handling, class constants, string builtins that scale with length, no characters above U+FFFF), and the image is pinned by digest so upgrades are deliberate and re-tested.

ADR-002 Canonical store: SQLite through G3DB

  • Decision: one SQLite file (db/app.sqlite, WAL mode) is the source of truth for every record; schema changes only through migrations. FTS5 provides lexical search with BM25.
  • Alternatives: PostgreSQL (with pgvector), a document store.
  • Consequences: no database server to run, backups with VACUUM INTO, simple restores. One writer at a time and one application process per database, which fits a team-sized installation; a hosted multi-tenant service (roadmap phase 6) would need PostgreSQL. G3DB limits (8 parameters, no column names, open result sets) shape the data code. The database must never be opened from the host (WAL file ownership, see AGENTS.md).

ADR-003 Semantic retrieval: Ollama embeddings, Qdrant vectors, rank fusion

  • Decision: embeddings from a local Ollama model (nomic-embed-text, 768 dimensions), vectors in Qdrant, both as containers. Lexical and vector rankings are fused with reciprocal rank fusion (k = 60); vector hits below EmbeddingMinScore 0.6 are ignored. SQLite's embedding_index table tracks model, dimensions and revision per item, so the vector store can be rebuilt from SQLite at any time (embed.cmd reindex).
  • Alternatives: a hosted embedding API (data leaves the network, per-call cost); vectors inside SQLite (would need a vector extension loaded into the runtime's SQLite driver); score-weighted fusion (needs calibrated scores from both rankers).
  • Consequences: everything stays on the local network. Retrieval degrades to lexical with a warning when either service is down, and writes never fail because of indexing. The 0.6 cutoff is model-specific; the retrieval benchmark (tests/retrieval-benchmark.sh) must be rerun before changing the model or the cutoff.

ADR-004 JSON: pure VBScript parser for request bodies

  • Decision: API controllers parse JSON with core/lib.JsonLite.asp and compose responses as text.
  • Alternative: the native G3JSON. Rejected because, in a request that also uses G3DB, it caused silent lost writes and stale values (AGENTS.md section 8).
  • Consequences: correct and predictable. Parsing large bodies needs care for speed (one RegExp tokenizer) and the import size is capped at 8 MiB.

ADR-005 Jobs: a table-backed queue with leases

  • Decision: ingestion jobs live in the jobs table with their input. Processing is claimed with a conditional UPDATE and a 5-minute lease; the embed-worker container picks up queued, interrupted and retryable jobs every 30 seconds. Publishing and the job update share one transaction.
  • Alternatives: a message broker (RabbitMQ, Redis); processing only inside the request.
  • Consequences: no extra service, and job state is backed up with the data. Throughput is bounded by one worker and SQLite's single writer, which suits documents up to the 8 MiB request limit.

ADR-006 Identity: hashed API keys, tenant from the key, 404 for no access

  • Decision: callers authenticate with bearer API keys stored as SHA-256 hashes (with an 8-character prefix for identification). The tenant comes from the key, never from the request. Missing permission on a namespace answers 404, the same as a missing item, so ids cannot be probed.
  • Alternatives: an external identity provider (OIDC) and per-request tenant headers.
  • Consequences: simple provisioning through provision.cmd/ops.sh and no dependency on an identity service. Key rotation and revocation are manual. An OIDC front end can be added later without changing the data model.

ADR-007 Learning: proposals reviewed by another principal

  • Decision: agents propose lessons and facts with evidence (POST /learn); a principal with verify reviews them, and the author cannot approve its own proposal without admin. Verification is stored per revision, so a correction starts unverified. Trusted retrieval returns only verified items by default.
  • Alternatives: automatic acceptance with confidence scores; AI-assisted review (roadmap phase 5).
  • Consequences: the knowledge base only grows through reviewed items, at the cost of a review step that someone must perform (kb.sh candidates / review).

ADR-008 Context budget: estimated tokens

  • Decision: POST /context counts tokens as characters / 4 (counting_method estimate_chars_div_4, stated in every response). Constraints are required: if they do not fit, the answer is 422 context_budget_exceeded.
  • Alternative: a model-specific tokenizer. Not available in the runtime, and different for every agent's model.
  • Consequences: callers get a declared, conservative method and can leave headroom.

ADR-009 Portability: a versioned canonical export

  • Decision: exports use the agent-memory-export format, schema_version 1, with a SHA-256 digest over the exact data text. Imports keep ids, revisions, timestamps and author ids, rebuild derived data and are all-or-nothing. Unknown author ids get placeholder principals (no keys, cannot sign in).
  • Consequences: a new canonical table or column means a new schema version and an importer for the old one.

ADR-010 Operations: stdout logs, in-process metrics, file backups

  • Decision: one JSON access-log line per API response on stdout (no bodies, query strings or keys), Prometheus metrics at /api/v1/metrics behind a token, counters held in process memory. Backups are verified SQLite copies in db/backups/, restored with the server stopped.
  • Alternatives: OpenTelemetry export, a metrics database, continuous replication (for example Litestream).
  • Consequences: nothing extra to run. Counters reset on restart, and backups need a schedule and an off-machine copy (open item on the production server).

ADR-011 Management API: delegated administration without escalation

  • Context: provisioning went through a CLI on the server (provision.cmd / ops.sh), which needs shell access to the host. The specification lists management endpoints as mandatory “API or secure configuration”.
  • Decision: management endpoints inside a tenant (/me, /namespaces, /principals, /principals/{id}/keys, /keys/{id}, /grants) with authorization derived from the existing namespace grants, no new role:
    • admin on a namespace allows granting and revoking access on it; granting with inherit, and creating namespaces below it, needs an admin grant that itself inherits.
    • Listing and creating principals needs admin somewhere; a new principal has no access until granted.
    • Issuing keys for, disabling or enabling another principal needs admin over every namespace where that principal has a grant (inheriting where its grant inherits). A key therefore never lets the caller act with more access than it already holds. Callers may manage their own keys but not their own status or grants.
    • No permission answers 404; keys are returned once with Cache-Control: no-store; no Idempotency-Key replay for responses that contain a key.
    • Tenants, top-level namespaces and purges stay with the CLI (operator actions).
  • Alternatives: a tenant-wide administrator role (simpler, but all-or-nothing); exposing tenant creation (needs a service-level operator identity that does not exist yet).
  • Consequences: teams can run their own namespaces without shell access to the server. The rule has to be kept by any future endpoint that issues credentials or access (AGENTS.md).

ADR-012 Consolidation without a generative model

  • Context: agents record experiences in sessions, but turning repeated experiences into lessons was manual (POST /learn). The specification requires the core workflow to work without generative inference (AC-16) and forbids automated approval.
  • Decision: POST /consolidations groups a namespace's experiences by lexical similarity (significant words, Jaccard

    = 0.35 by default, at least 2 shared words, words present in more than half of the experiences ignored, connected components) and builds a draft that only rearranges the experiences’ own text. Proposing is explicit ("propose": true), creates ordinary proposed candidates citing the experiences, and an experience already cited by any candidate is not proposed again until enough new ones accumulate.

  • Alternatives: embedding similarity (better with paraphrases, but needs the provider and is slow per request); generative summarisation (roadmap phase 5, FR-024).
  • Consequences: predictable, explainable groups (the shared terms are returned) and no extra dependency. Paraphrased experiences with few shared words are missed, and drafts read as notes rather than generalised lessons: a reviewer rewrites them or rejects them and proposes a better wording with POST /learn.

ADR-013 HTML adapter: convert to Markdown at ingestion

  • Context: phase 4 adds source formats (FR-021). The specification asks adapters to “normalize input into versioned documents and chunks, preserving source locators”. documents.format only allows text and markdown, and changing a CHECK constraint in SQLite means rebuilding the table (and a new export schema version for a new canonical column).
  • Decision: format: "html" is converted to Markdown in the request, before the job is stored; the document is a markdown document and locators point into that text. The page's URL belongs in source_uri; the original HTML is not stored. Conversion is RegExp-based in VBScript (core/lib.HtmlAdapter.asp): invisible and active content is dropped, the structure the chunker understands (headings, lists, pre, tables) is kept, and nothing referenced by the page is fetched (no SSRF surface).
  • Alternatives: storing the original HTML next to the text (needs a schema and export change); a full HTML parser (none available in the runtime); fetching pages by URL on the server (needs SSRF controls, deferred).
  • Consequences: no schema change and identical behaviour for search, context and export. Markup-only changes do not create revisions. Malformed or script-generated pages convert poorly; clients can convert such pages themselves and send Markdown. PDF is not supported server-side: the runtime's G3PDF writes PDFs but cannot extract their text.

ADR-014 Graph relationships: reviewed, evidence-backed edges in SQLite

  • Context: phase 4 adds the optional graph module (FR-023, section 14). The specification requires typed, directed, evidence-backed relationships with provenance and temporal validity, bounded traversal, and that “traversal cannot reveal hidden nodes, edges or their existence” (section 8.1). Endpoints may be entities (concepts), memories or documents. A new canonical table is a new export schema version (ADR-009).
  • Decision: two tables, entities (type plus canonical key unique per namespace, aliases, properties) and relationships (source and target as kind plus id, type, validity window, confidence, inferred flag, state). Edges are proposed with POST /relate and need at least one evidence link, stored in evidence_links with owner kind relationship (the migration rebuilds that table to widen its CHECK). They are reviewed like learning candidates: verify permission, no self-review without admin. An edge is visible only when the caller can read the edge's namespace and both endpoints’ namespaces; the check is one SQL condition per side (Graph_NodeVisibleSql), so lists, fetches, traversal and exports apply the same rule and leave hidden edges out without a trace. POST /graph/traverse is a breadth-first search over accepted edges valid now (proposed ones on request), skipping retired memories, with limits of depth 3, 100 nodes and 300 edges and a truncated flag. Deleting a memory or an entity deletes its edges. Export schema version 2 adds entities and the relationships whose namespace and both endpoints are exported; imports accept versions 1 and 2.
  • Alternatives: a graph database (an extra service and a second source of truth, against ADR-001); recursive SQL CTEs for traversal (harder to bound and to filter per edge for visibility); storing edges without review (agents could assert links nobody checked).
  • Consequences: no new service; traversal cost is one query per depth level. Relationship types are free-form upper-case words, so vocabularies are a convention, not enforced. Not done yet: graph-enhanced retrieval (expanding recall or context along accepted edges), automatic entity extraction (needs a model, FR-024), and contradiction detection (FR-022).

Powered by TurnKey Linux.