Skip to main content

Crate phago

Crate phago 

Source
Expand description

§Phago

Self-evolving knowledge substrates through biological computing primitives.

Phago is a framework that maps cellular biology mechanisms to computational operations for autonomous knowledge graph construction. Agents digest documents, wire concepts through Hebbian learning, and evolve through fitness-directed mutation.

§Quick Start

use phago::prelude::*;

// Create a colony
let mut colony = Colony::new();

// Ingest documents
colony.ingest_document("Biology 101", "The cell membrane controls transport.", Position::new(0.0, 0.0));

// Spawn a digester agent
colony.spawn(Box::new(Digester::new(Position::new(0.0, 0.0)).with_max_idle(30)));

// Run the simulation
colony.run(30);

// Query with hybrid scoring
let results = hybrid_query(&colony, "cell membrane", &HybridConfig {
    alpha: 0.5,
    max_results: 5,
    candidate_multiplier: 3,
});

for r in results {
    println!("{} (score: {:.3})", r.label, r.final_score);
}

§Architecture

Phago is organized into several crates:

  • phago_core - Core traits (10 biological primitives) and shared types
  • phago_agents - Agent implementations (Digester, Sentinel, Synthesizer)
  • phago_runtime - Colony management, substrate, sessions
  • phago_rag - Query engine, hybrid scoring, MCP adapter

§Key Concepts

§Biological Primitives

PrimitiveBiological AnalogWhat It Does
DIGESTPhagocytosisConsume input, extract fragments
APOPTOSEProgrammed cell deathSelf-assess, gracefully terminate
SENSEChemotaxisDetect signals, follow gradients
WIREHebbian learningStrengthen used connections
EMERGEQuorum sensingCollective behavior at threshold
NEGATENegative selectionDetect anomalies by exclusion

§Agent Types

  • Digester - Consumes documents, extracts keywords, wires concepts
  • Sentinel - Learns “normal”, flags anomalies
  • Synthesizer - Detects cross-document patterns, generates insights

§Hebbian Learning

“Neurons that fire together wire together.”

  • First co-occurrence: edge at 0.1 weight (tentative)
  • Subsequent co-occurrences: +0.1 weight (reinforcement)
  • Unused edges decay and are pruned

§MCP Integration

Phago provides an MCP adapter for external LLM/agent integration:

use phago::prelude::*;

let mut colony = Colony::new();

// Ingest via MCP
let resp = phago_remember(&mut colony, &RememberRequest {
    title: "Doc".into(),
    content: "Content here".into(),
    ticks: Some(15),
});

// Query via MCP
let results = phago_recall(&colony, &RecallRequest {
    query: "search terms".into(),
    max_results: 5,
    alpha: 0.5,
});

// Explore graph structure
let stats = phago_explore(&colony, &ExploreRequest::Stats);

§Session Persistence

Save and restore colony state:

use phago::prelude::*;
use std::path::Path;

let colony = Colony::new();

// Save session
save_session(&colony, Path::new("session.json"), &["doc1.txt".to_string()]).unwrap();

// Load session
let state = load_session(Path::new("session.json")).unwrap();
let mut restored = Colony::new();
restore_into_colony(&mut restored, &state);

Re-exports§

pub use phago_core as core;
pub use phago_runtime as runtime;
pub use phago_agents as agents;
pub use phago_rag as rag;

Modules§

prelude
Prelude module for convenient imports.

Constants§

VERSION
Version information.