Skip to main content

API Reference

Cognitive architecture primitives built on flow-state-dev. Provides attention, identity, and metacognition domains for agentic workflows.

Import: Use subpath exports. @thought-fabric/core/attention, @thought-fabric/core/identity, @thought-fabric/core/metacognition.

Memory has moved. Cross-turn memory now ships from @flow-state-dev/memory. Thought Fabric will host specialized cognitive memory variants on top of that contract when they're ready.


attention

Relevance and salience for what the agent attends to.

filterRelevance(config)

Handler block factory. Deterministic keyword-based relevance filtering. No LLM. Fast. Removes or annotates items below a threshold using keyword overlap heuristics.

import { filterRelevance } from "@thought-fabric/core/attention";

const block = filterRelevance({ name: "filter", criteria: { ... } });

Returns a BlockDefinition (handler). Use as a step in a sequencer or as a tool.

scoreSalience(config)

Generator block factory. LLM-based salience scoring along configurable dimensions (goal relevance, recency, novelty, emotional weight).

import { scoreSalience } from "@thought-fabric/core/attention";

const block = scoreSalience({
name: "salience",
dimensions: { ... },
weights: { ... },
model: "preset/fast",
});

Returns a BlockDefinition (generator). Output schema: scores, composite, ranking, itemScores.


metacognition

Bias detection, sycophancy scoring, and counter-argument generation.

Import: @thought-fabric/core/metacognition

Blocks

FunctionKindPurpose
biasAnalyzer(config?)sequencerBundled pipeline: detect → classify → score → counterpoint → format
biasDetectAgreement(config?)generatorDetects agreement patterns across four dimensions
biasClassify(config?)generatorClassifies six bias types with per-type confidence
biasScore(config?)handlerComputes composite sycophancy score (deterministic)
biasCounterpoint(config?)generatorGenerates counter-arguments when score exceeds threshold
biasFormat()handlerMaps accumulated data to AnalyzerResult output

Schemas

SchemaPurpose
biasAnalyzerInputSchemaInput: { userInput: string, aiResponse: string }
biasAnalyzerOutputSchemaFull output with bias annotations, score, counter-arguments
biasTypeSchemaEnum of six bias types
biasAnnotationSchemaPer-bias annotation (type, confidence, description, evidence)
counterArgumentSchemaCounter-argument (claim, counterpoint, strength, sources)
sycophancyScoreSchemaComposite score with label and four-dimension breakdown
sycophancyBreakdownSchemaFour dimension scores
sycophancyLabelSchemaEnum: balanced, mild_bias, moderate_bias, sycophantic
analyzerResultSchemaGeneric AnalyzerResult contract

Helpers

FunctionPurpose
labelForSycophancyScore(score)Score → label mapping
severityForSycophancyScore(score)Score → severity (info/warning/critical)
computeCompositeSycophancyScore(breakdown, biases, config?)Weighted composite from dimensions + bias confidence
shouldGenerateCounterpoints(score, threshold?)Whether score warrants counter-argument generation
summarizeBiasFindings(score, label, biases)Human-readable summary string

Config

ConstantContents
DEFAULT_BIAS_ANALYZER_CONFIGcounterpointThreshold (0.4), breakdownWeights, biasConfidenceWeight (0.3)

identity

Perspective and constitution — structured viewpoints and ranked value systems that shape how agents interpret and evaluate information.

Import: @thought-fabric/core/identity

Perspective Factory + System

FunctionPurpose
perspective(config)Create a frozen perspective instance from config
system(instance, config?)Factory that wires blocks, capability, resources, and capture pipeline

Static Blocks

FunctionKindPurpose
perspectiveApply(config)handlerInject perspective framing into content
perspectiveAnalyze(config)generatorLLM analysis through the perspective's lens
perspectiveAuditor(config)sequencerapply → analyze pipeline

Stateful Blocks

FunctionKindPurpose
perspectiveObserve(config)handlerRecord observations from analysis output or explicit batch
perspectivePosition(config)handlerRecord a position with supporting observations
perspectiveChallenge(config)handlerChallenge a position with counter-evidence
perspectiveSnapshot(config)handlerRead current observations + positions
perspectiveAdvance(config)handlerBump observation turn counter

Resources

ExportScopePurpose
perspectiveObservationsResourcesessionObservation store (singleton)
perspectivePositionsResourcesession/user/projectPosition store; scope decided by where the capability or block declares it

Capability

FunctionPurpose
createPerspectiveCapability(instance, config?)Create a capability with resources, context presets, and typed helpers

Presets: static (perspective framing), accumulated (observations + positions). Both on by default.

Static Helpers

FunctionPurpose
formatPerspective(instance)Full formatted perspective for LLM context
formatPerspectiveSalience(salience)Format salience model
formatPerspectiveReasoning(reasoning)Format reasoning config
summarizePerspective(instance)One-line summary
perspectiveContextFormatter(instance)Context slot function for generators

Observation Helpers

FunctionPurpose
addPerspectiveObservation(ref, input)Add an observation
removePerspectiveObservation(ref, id)Remove by ID
perspectiveObservations(ref, category?)Read observations, optionally filtered
advancePerspectiveObservations(ref)Bump turn counter
formatPerspectiveObservations(ref)Format for LLM context

Position Helpers

FunctionPurpose
addPerspectivePosition(ref, input, obsRef?)Add a position
challengePerspectivePosition(ref, id, evidence, obsRef?)Add counter-evidence
removePerspectivePosition(ref, id)Remove by ID
perspectivePositions(ref)Read all positions
formatPerspectivePositions(ref)Format for LLM context
formatPerspectiveAccumulated(obsRef, posRef?)Combined observations + positions

Schemas

SchemaPurpose
perspectiveConfigSchemaFull perspective configuration
perspectiveSalienceSchemaSalience model (amplify/suppress)
perspectiveReasoningSchemaReasoning config (priorities, risk model)
perspectiveCommunicationSchemaCommunication style
perspectiveAnalysisSchemaAnalysis output
perspectiveInputSchemaAnalysis input ({ content: string })
perspectiveApplyOutputSchemaApply block output
perspectiveObservationSchemaSingle observation
perspectiveObservationsStateSchemaObservations resource state
perspectivePositionSchemaSingle position
perspectivePositionChallengeSchemaChallenge entry
perspectivePositionsStateSchemaPositions resource state
perspectiveObserveInputSchemaObserve block input
perspectiveObserveOutputSchemaObserve block output
perspectivePositionInputSchemaPosition block input
perspectiveChallengeInputSchemaChallenge block input
perspectiveSnapshotOutputSchemaSnapshot block output

Constitution Factory

FunctionPurpose
constitution(config)Create a frozen constitution definition from config

Constitution Blocks

FunctionKindPurpose
constitutionAuditor(config)sequencerBundled pipeline: review → enforce
constitutionReview(config)generatorLLM-evaluates content against principles
constitutionEnforce(config)handlerComputes aggregate compliance and pass/fail verdict

Constitution Helpers

FunctionPurpose
rankConstitutionPrinciples(constitution, context?)Sort principles by effective priority, applying contextual overrides
computeConstitutionCompliance(results, constitution)Aggregate compliance score from per-principle results
formatConstitution(constitution)Human-readable string for LLM prompt injection
summarizeConstitutionReview(review)One-line summary with violation counts and severity

Constitution Schemas

SchemaPurpose
constitutionConfigSchemaFull constitution configuration
constitutionPrincipleSchemaSingle principle (id, statement, priority, rationale, weight)
constitutionContextualOverrideSchemaOverride rule (when, promote, demote, reasoning)
constitutionConflictResolutionSchemaEnum: priority, weighted, contextual
constitutionReviewInputSchemaInput: { content: string, context?: string }
constitutionReviewOutputSchemaFull review output with compliance verdict
constitutionPrincipleResultSchemaPer-principle evaluation result
constitutionViolationSchemaViolation entry (principleId, severity, description, evidence)
constitutionTradeoffSchemaTradeoff between two principles

Constitution Config

ConstantContents
DEFAULT_CONSTITUTION_CONFIGcomplianceThreshold (0.7)

Usage

import { perspective, system as perspectiveSystem } from "@thought-fabric/core/identity";
import { filterRelevance, scoreSalience } from "@thought-fabric/core/attention";
import { biasAnalyzer } from "@thought-fabric/core/metacognition";

const sec = perspectiveSystem(
perspective({
name: "security-engineer",
description: "Security-focused code reviewer",
salience: { amplify: ["auth", "injection", "data exposure"] },
reasoning: { priorities: ["identify attack vectors", "assess blast radius"] },
}),
{ model: "preset/fast" },
);

const chat = generator({
uses: [sec.capability],
// ...
});

const pipeline = sequencer({ name: "pipeline", inputSchema: chatInput })
.step(chat)
.work((response) => ({ content: response }), sec.capture);

See Identity for the full guide. For cross-turn memory, see the framework docs at Ecosystem → Memory.