The MentisDB Agent Memory Cookbook

Patterns and recipes for building AI agents that remember

5.1 Rust: Minimal Agent with Memory

This is the smallest direct-library pattern: open a chain, register an agent, search before writing, append a durable decision, then query it back.

fn minimal_rust_agent_memory() -> io::Result<()> {
    let dir = tempfile::tempdir()?;
    let adapter = BinaryStorageAdapter::for_chain_key(dir.path(), "minimal-agent");
    let mut chain = MentisDb::open_with_storage(Box::new(adapter))?;

    chain.upsert_agent(
        "agent-rust",
        Some("Rust Agent"),
        Some("cookbook"),
        Some("Minimal direct-library agent"),
        None,
    )?;

    let prior = chain.query_ranked(
        &RankedSearchQuery::new()
            .with_text("database choice for local state")
            .with_limit(3),
    );
    assert!(prior.hits.is_empty());

    chain.append_thought(
        "agent-rust",
        ThoughtInput::new(
            ThoughtType::Decision,
            "Use MentisDB as the local durable memory store for this agent.",
        )
        .with_concepts(["agent-memory", "local-state"])
        .with_tags(["cookbook", "minimal"])
        .with_importance(0.9),
    )?;

    let found = chain.query_ranked(
        &RankedSearchQuery::new()
            .with_text("local durable memory store")
            .with_limit(3),
    );
    assert_eq!(found.hits.len(), 1);
    assert!(found.hits[0].thought.content.contains("MentisDB"));
    Ok(())
}
Production move: replace tempdir with a stable application data directory.