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.
79 lines
4.3 KiB
TypeScript
79 lines
4.3 KiB
TypeScript
// PaperTrail MoA v2 — PyKEEN learned link predictor (category: bio-kg).
|
|
//
|
|
// COMPOSITION ROLE: none on the stateless plain-claim path. PyKEEN 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 the org's KG edges (mirrored in
|
|
// backend/engines/pykeen/papertrail_train.py; TS mirror in lib/kg/learnedLinkPredict.ts).
|
|
//
|
|
// Why this agent PRODUCES nothing and CONSUMES nothing (honest Mixture-of-Agents skip):
|
|
// - 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
|
|
// the KG node index, and gathers candidates with a bounded BFS over kg_edges. None of
|
|
// that can run inside a stateless MoA agent — the scheduler 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 — nothing to write to the blackboard,
|
|
// and no upstream artifact this predictor could compose on to change that.
|
|
//
|
|
// Therefore gate(ctx) is an HONEST 0 for the plain-claim path: PyKEEN never runs in the
|
|
// stateless composition pipeline, and run() returns a clear skippedContribution rather than
|
|
// inventing a pool or fabricating a link. Registering the agent keeps PyKEEN a first-class
|
|
// bio-kg expert so it can fire once the pipeline is extended to supply built-KG context.
|
|
//
|
|
// MOAT: no LLM anywhere — the underlying scorer is pure deterministic math with no Claude in
|
|
// any score or in training, so run() never invokes Claude (usedClaude is always false). No
|
|
// DB pool, no network, no I/O: this is a stateless, side-effect-free no-op vote.
|
|
//
|
|
// This UPGRADES backend/moa-v1-adapters/pykeen.ts to the v2 composition contract: the same
|
|
// honest-skip behavior, now expressed with produces/consumes and the (ctx, bb) run signature.
|
|
|
|
import type {
|
|
MoaAgent,
|
|
OrchestrationContext,
|
|
AgentContribution,
|
|
Blackboard,
|
|
} from "../types";
|
|
import { skippedContribution } from "../types";
|
|
|
|
const AGENT_ID = "pykeen";
|
|
|
|
// The single, honest reason PyKEEN cannot participate statelessly. Surfaced verbatim so the
|
|
// UI trace explains WHY this agent abstained (missing built KG) instead of silently dropping.
|
|
const SKIP_REASON = "needs a built knowledge graph — run via Knowledge Graph";
|
|
|
|
const agent: MoaAgent = {
|
|
id: AGENT_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.",
|
|
|
|
// Produces no artifact: with no built KG in the stateless context there is nothing to write.
|
|
produces: [] as const,
|
|
// Consumes no artifact: no upstream enricher can supply a trained KG or a pool, so there is
|
|
// nothing on the blackboard this predictor could compose on to become applicable.
|
|
consumes: [] as const,
|
|
|
|
// ELIGIBILITY: pure + deterministic over the INPUT only. 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 blackboard, no I/O, no LLM, never throws.
|
|
gate(_ctx: OrchestrationContext): number {
|
|
return 0;
|
|
},
|
|
|
|
// gate is always 0, so the scheduler never selects this agent. If it is ever invoked
|
|
// directly, return an honest skip — never open a DB pool, never fetch, never fabricate a
|
|
// link, never read the blackboard (there is nothing here for it to consume). This is a
|
|
// stateless, side-effect-free no-op vote that produces no artifact.
|
|
async run(_ctx: OrchestrationContext, _bb: Blackboard): Promise<AgentContribution> {
|
|
return skippedContribution(AGENT_ID, SKIP_REASON);
|
|
},
|
|
};
|
|
|
|
export default agent;
|