Expand description
§anda_kip — a Rust implementation of KIP 2.0
🧬 KIP (Knowledge Interaction Protocol) is a cognitive state protocol between an Agent and a persistent Cognitive Nexus. KIP 2.0 is not a bigger KIP 1.x: it separates the things 1.x kept in one graph —
meaning · belief · evidence · provenance · mnemonic state · retention · Governance · Schema— because collapsing them is what lets a memory system confidently repeat things nobody ever claimed. The single distinction the rest follows from:
a Proposition existing ≠ the Proposition being trueA Proposition is a truth-neutral tuple. An Assertion is one actor’s commitment about it, with a stance, a mode, a confidence and its Evidence. What is currently believed is projected from those, never stored.
§What is public
pub means API. Each module is re-exported wholesale at the crate root —
except cognitive and timestamp, which are addressed by module path,
and json, which exports its three entry points — so an item is either
part of the contract this crate keeps or it is pub(crate); the nom combinators, the raw single-surface sub-parsers, the
validation gates behind Operation::parse and the semantic checks the
parsers apply are the latter. tests/surface.rs lists every public item
from the sources and compares the list with
tests/fixtures/public_surface.txt, so widening or narrowing the surface
is a change to that file, made on purpose.
§What this crate is
The protocol half: parse, classify, validate. Everything that needs state —
Schema resolution, Governance, transactions, projection — belongs to an
engine behind the Executor trait.
ast— the executable AST, field-for-field compatible with the reference toolkit@ldclabs/kip-lang, so a Rust engine and a TypeScript one can be differentially tested against each other;parser— nom parsers for the three surfaces, enforcing the schema-independent rules as they parse;semantics— the Core Package registries (§20.13) and the other rules decidable without a Schema Environment;error— the Core Error Registry (§87) with categories and retry classes;request— the runtime envelope (§71–§85);types— the Core data model (§6–§19);capsule— portable Cognitive Capsules (§37–§41);conformance— the profile names an implementation declares (§89);executor— the engine seam.
§Standards compliance
Follows the official KIP 2.0 specification, a copy of which ships with this
crate as SPECIFICATION.md, alongside the LLM-facing KIPSyntax.md.
§Quick start
use anda_kip::{Command, parse_kip};
// Read raw claims — truth-neutral.
let read = parse_kip(
r#"
FIND(?a.asserted_by, ?a.confidence)
WHERE {
?p (:alice, "timezone", ?tz)
?a ASSERTION {proposition: ?p}
}
ORDER BY ?a.confidence DESC
LIMIT 10
"#,
)
.unwrap();
assert!(matches!(read, Command::Kql(_)));
// Read what is currently believed — a Projection, not stored state.
let belief = parse_kip(
r#"FIND(?b) WHERE { ?b BELIEF (:alice, "timezone", ?tz) }"#,
)
.unwrap();
assert!(matches!(belief, Command::Kql(_)));
// Record an attributed claim. `by` and `mode` have no safe default.
let write = parse_kip(
r#"ASSERT (:alice, "prefers", :dark_mode) {
by: :alice,
mode: "stated",
confidence: 0.9,
evidence: :msg
}"#,
)
.unwrap();
assert!(write.is_mutation());Changing your mind never rewrites history:
use anda_kip::parse_kml;
// Correcting a claim is a new Assertion plus supersession.
let revision = parse_kml(
r#"ASSERT ?new (:alice, "timezone", "+09:00") { by: :alice, mode: "stated" }
SUPERSEDING :old"#,
)
.unwrap();
assert_eq!(revision.clauses.len(), 3);
// Rewriting the old one is rejected before it reaches an engine.
assert!(
parse_kml(
r#"UPDATE ?a SET FIELDS { confidence: 0.1 }
WHERE { ?a ASSERTION {id: "A-1"} }"#,
)
.is_err()
);Re-exports§
pub use json::MAX_SAFE_INTEGER;pub use json::parse_canonical_json;pub use json::validate_json;pub use ast::*;pub use capsule::*;pub use conformance::*;pub use draft::*;pub use error::*;pub use executor::*;pub use memory::*;pub use parser::*;pub use request::*;pub use semantics::*;pub use types::*;
Modules§
- ast
- The executable KIP 2.0 AST
- capsule
- Cognitive Capsule (Spec §37–§41)
- cognitive
- Protected cognitive runtime host contracts. Host-side contracts shared by Nexus engines and Brain implementations.
- conformance
- Conformance levels (Spec §89–§102)
- draft
- Draft vocabulary definitions (Spec §20.16)
- error
- The KIP 2.0 error model
- executor
- Execution framework
- json
- Strict portable JSON decoding (KIP §9.3, §70.1, kip-jcs-safe-v1).
- memory
- Optional Agent-to-Brain interface artifacts. A raw Nexus does not acquire a Brain binding merely by installing the Cognitive Memory vocabulary.
- parser
- Nom-based parsers for KQL, KML and META
- request
- The KIP 2.0 runtime envelope (Spec §70–§85)
- semantics
- Static checks the Core Package decides on its own (Spec §20.13)
- timestamp
- Canonical protocol timestamps (KIP §6.5). Validation never rewrites input.
- types
- The KIP 2.0 Core data model (Spec §6–§19)
Statics§
- COGNITIVE_
MEMORY_ PROFILE - The Cognitive Memory Profile — the standard portable memory structures the bundled prompts are written against.
- KIP_
FUNCTION_ DEFINITION - The tool definition for the state-capable
execute_kipentry point. - KIP_
READONLY_ FUNCTION_ DEFINITION - The tool definition for the read-only
execute_kip_readonlyentry point. - KIP_
SYNTAX - The KIP 2.0 syntax reference, condensed for a model to read in context.
- SELF_
INSTRUCTIONS - How an Agent should use KIP as its own memory protocol.
- SYSTEM_
INSTRUCTIONS - What a KIP runtime owes its callers, from the execution and governance side.