Replace the flat "run 17 adapters in parallel and sum" design with a collaborative, layered blackboard MoA where the backend engines compose: agents declare produces/consumes typed artifacts, a scheduler topologically orders them into layers, and each layer commits its artifacts to a shared blackboard before the next runs — so downstream agents genuinely build on upstream findings. Composition core (lib/moa): - types.ts: MoaAgent contract (produces/consumes/gate/run(ctx,bb)) + typed artifact taxonomy (source_labels, effect_sizes, quality, relevance, contested, entities, mechanisms, design_priors, sufficiency, debate, research_brief) - blackboard.ts: typed single-producer-per-kind shared memory - scheduler.ts: dependency-DAG layering; parallel within a layer, artifacts committed between layers - router.ts + planner.ts: deterministic gate + advisory Claude planner (boosts never revive a 0 gate) - aggregate.ts: deterministic vote mix -> verdict + trust (no LLM; the moat) - synthesize.ts: grounded Claude narrative (explains, never decides) - 21 composing agents under lib/moa/agents/* Real composition edges proven live: MiniCheck produces source_labels -> MultiVerS aggregates them + Valsci produces contested -> STORM debates; quant-extractor produces effect_sizes -> PyMARE pools them; paper-qa quality + Loki relevance feed MiniCheck. Sample (EMPA-REG vs DECLARE) yields a calibrated "supported, trust 73/100" with an honest heterogeneity caveat. New production engines from vendored research repos (MVP -> production), wired as Layer-3 deliberation agents with papertrail_*.py + PAPERTRAIL.md: - autoreview (eimenhmdt/autoresearcher): citation-grounded literature review - autogather (lucereal/AutoResearcher): query-gen + coverage-gap analysis - autoloop (karpathy/autoresearch pattern): bounded evidence-refinement loop Platform robustness: callClaudeForJson now tolerates prose-wrapped JSON (balanced-value extraction) with one stricter retry — fixes model editorializing that previously broke MiniCheck and any strict-JSON engine. API /api/moa/orchestrate + console page /console/orchestrator visualizing the layered DAG, artifact provenance, and per-agent produce/consume.
62 lines
3.4 KiB
TypeScript
62 lines
3.4 KiB
TypeScript
// MoA expert adapter — PyKEEN (category: bio-kg). A native TypeScript mirror of PyKEEN's
|
|
// TransE link predictor, exposed as an interchangeable "expert" agent.
|
|
//
|
|
// PyKEEN here is a LEARNED KNOWLEDGE-GRAPH LINK PREDICTOR: given a source entity already
|
|
// present in an org's knowledge graph, it ranks candidate NOVEL links by the deterministic
|
|
// TransE translation distance ||h + r - t|| over embeddings trained on kg_edges (see
|
|
// lib/kg/learnedLinkPredict.ts, mirrored in backend/engines/pykeen/papertrail_train.py).
|
|
//
|
|
// Why this expert gates 0 on the plain-claim path (honest Mixture-of-Experts behavior):
|
|
// - The engine is FUNDAMENTALLY STATEFUL. Every scorable step needs a DB pool: it loads
|
|
// (or trains-on-demand) embeddings from kg_embeddings, resolves the source entity via
|
|
// getNodeByNormalizedId, and gathers candidates with a bounded BFS over kg_edges. None
|
|
// of that can run statelessly — the orchestrator is stateless and MUST NOT open a pool.
|
|
// - The OrchestrationContext carries only { claim, sources, options }. It never carries a
|
|
// built KG, a normalized source-entity id, or a pool. A plain claim + free-text sources
|
|
// give this predictor nothing to translate over, so there is no deterministic signal to
|
|
// produce and NO learned vector to ground against.
|
|
//
|
|
// Therefore gate(ctx) is a HONEST 0 for the plain-claim path: PyKEEN never runs in the
|
|
// stateless MoA pipeline, and run() returns a clear skippedContribution rather than
|
|
// inventing a pool or fabricating a link. Registering the adapter keeps PyKEEN a first-class
|
|
// expert so it can fire once the pipeline is extended to supply built-KG context.
|
|
//
|
|
// No Claude anywhere: the underlying scorer is pure deterministic math with no LLM in any
|
|
// score or in training, so run() never invokes Claude (usedClaude is always false).
|
|
|
|
import type { Expert, OrchestrationContext, ExpertContribution } from "../types";
|
|
import { skippedContribution } from "../types";
|
|
|
|
const EXPERT_ID = "pykeen";
|
|
|
|
// The single, honest reason PyKEEN cannot participate statelessly. Surfaced verbatim so the
|
|
// UI trace explains WHY this expert abstained (missing built KG) instead of silently dropping.
|
|
const SKIP_REASON = "needs a built knowledge graph — run via Knowledge Graph";
|
|
|
|
const expert: Expert = {
|
|
id: EXPERT_ID,
|
|
name: "PyKEEN learned link predictor",
|
|
category: "bio-kg",
|
|
description:
|
|
"Ranks novel knowledge-graph links from a source entity by deterministic TransE " +
|
|
"distance over embeddings trained on the org KG. Requires a built knowledge graph " +
|
|
"and a DB pool, so it abstains on the stateless plain-claim path.",
|
|
|
|
// Pure + deterministic. The stateless context never carries a built KG, a normalized
|
|
// source-entity id, or a pool — everything this engine needs to score — so the engine is
|
|
// never applicable here. Honest 0: PyKEEN belongs to the Knowledge Graph path, not the
|
|
// plain-claim MoA path. No I/O, no LLM, no throwing.
|
|
gate(_ctx: OrchestrationContext): number {
|
|
return 0;
|
|
},
|
|
|
|
// gate is always 0, so the router never selects this expert. If it is ever invoked
|
|
// directly, return an honest skip — never open a DB pool, never fetch, never fabricate a
|
|
// link. This is a stateless, side-effect-free no-op vote.
|
|
async run(_ctx: OrchestrationContext): Promise<ExpertContribution> {
|
|
return skippedContribution(EXPERT_ID, SKIP_REASON);
|
|
},
|
|
};
|
|
|
|
export default expert;
|