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.
81 lines
4.5 KiB
TypeScript
81 lines
4.5 KiB
TypeScript
// PaperTrail MoA v2 agent · Evidence Integrator (FAERS / ClinVar / ChEMBL) (category: sources).
|
|
//
|
|
// WHAT THIS ENGINE CLUSTER WOULD CONTRIBUTE: a live pharmacovigilance / variant / bioactivity
|
|
// INGEST signal. The FAERS, ClinVar and ChEMBL drivers in lib/ingest/drivers/* each perform a
|
|
// LIVE outbound HTTP fetch to a third-party database (openFDA FAERS adverse-event counts, NCBI
|
|
// ClinVar variant significance, ChEMBL molecule bioactivity) and write cacheable source records.
|
|
// That is data INGESTION, not stateless claim verification: its unit of work is a (drug, event) /
|
|
// variant / molecule lookup keyed off ingest context, not the (claim, sources) pair the MoA
|
|
// orchestrator hands an agent. Its results are meant to be persisted to the `sources` cache and
|
|
// then fed back into the pipeline as ordinary MoaSources — at which point OTHER agents read them.
|
|
//
|
|
// WHY IT DOES NOT COMPOSE STATELESSLY (honest Mixture-of-Agents skip):
|
|
// The orchestrate path is explicitly STATELESS: no DB pool, and no network beyond what an
|
|
// engine lib already does internally for a pure verification step. A live FAERS/ClinVar/ChEMBL
|
|
// fetch from inside run() would violate that contract and make the deterministic mix depend on
|
|
// external API latency/availability. There is no way to compute an adverse-event / variant /
|
|
// bioactivity signal PURELY from the fields already present on a MoaSource, and no upstream
|
|
// blackboard artifact supplies one. So this agent invents no fetch and no pool: it neither
|
|
// PRODUCES nor CONSUMES an artifact. It stays REGISTERED (so the router lists the cluster and a
|
|
// Source Ingest path can attach evidence later) while gating to 0 on the orchestrate path.
|
|
//
|
|
// COMPOSITION WIRING: produces [] and consumes [] — evidence-integrator is a leaf in the DAG. It
|
|
// reads no upstream artifact and writes none, so the scheduler places it in the root layer where
|
|
// it immediately skips. Stateless / deterministic / no LLM / no I/O: gate is the constant 0 (a
|
|
// live ingest fetch the stateless path cannot perform and no artifact supplies), run never touches
|
|
// the network or the blackboard, never invokes Claude (usedClaude is always false), never throws.
|
|
|
|
import type {
|
|
MoaAgent,
|
|
OrchestrationContext,
|
|
AgentContribution,
|
|
Blackboard,
|
|
} from "../types";
|
|
import { skippedContribution, erroredContribution } from "../types";
|
|
|
|
const AGENT_ID = "evidence-integrator";
|
|
|
|
// The one honest reason surfaced whenever this agent is (never) run on the orchestrate path.
|
|
// Kept as a constant so the gate rationale and the skip message stay in lock-step.
|
|
const SKIP_REASON = "live FAERS/ClinVar/ChEMBL lookup — run via Source Ingest";
|
|
|
|
const agent: MoaAgent = {
|
|
id: AGENT_ID,
|
|
name: "Evidence Integrator (FAERS / ClinVar / ChEMBL)",
|
|
category: "sources",
|
|
description:
|
|
"Live pharmacovigilance / variant / bioactivity ingest (FAERS, ClinVar, ChEMBL). These " +
|
|
"drivers perform outbound network fetch + caching and are ingestion, not stateless claim " +
|
|
"verification, so this agent is registered but always gates 0 on the orchestrate path — it " +
|
|
"is run via Source Ingest, not the MoA mix.",
|
|
|
|
// Produces + consumes nothing: an ingest signal needs a live FAERS/ClinVar/ChEMBL fetch and a
|
|
// source cache the stateless orchestrator has no artifact for. Leaf node in the composition DAG.
|
|
produces: [],
|
|
consumes: [],
|
|
|
|
// DETERMINISTIC and constant. This engine cluster fundamentally needs live network I/O and a
|
|
// source cache the stateless orchestrator does not provide, so it must never run in the
|
|
// orchestrate path. A pure 0 keeps it REGISTERED (visible to the router/registry) while
|
|
// guaranteeing the scheduler never schedules it; per the router contract a planner boost can
|
|
// lift a low gate but can never revive a gate of exactly 0 — exactly what an ingestion engine
|
|
// with no stateless verification mode wants. Pure, side-effect-free, never throws.
|
|
gate(_ctx: OrchestrationContext): number {
|
|
return 0;
|
|
},
|
|
|
|
// Never reached on the orchestrate path (gate is 0). Guarded anyway: if a caller invokes run()
|
|
// directly, it degrades to an honest, network-free skip rather than attempting the live
|
|
// FAERS/ClinVar/ChEMBL fetch, which belongs to the Source Ingest entry point. Nothing is
|
|
// produced or consumed; usedClaude stays false; no support/refute vote is cast.
|
|
async run(_ctx: OrchestrationContext, _bb: Blackboard): Promise<AgentContribution> {
|
|
try {
|
|
return skippedContribution(AGENT_ID, SKIP_REASON);
|
|
} catch (err: unknown) {
|
|
return erroredContribution(AGENT_ID, err);
|
|
}
|
|
},
|
|
};
|
|
|
|
export default agent;
|