Polyweave

@polyweave/triz (1.0.5)

Published 2026-07-11 15:34:37 +00:00 by Dvorak

Installation

@polyweave:registry=https://hub.kl1.tenere.ai/api/packages/Polyweave/npm/
npm install @polyweave/triz@1.0.5
"@polyweave/triz": "1.0.5"

About this package

@polyweave/triz

LLM-driven TRIZ and DIKWP-TRIZ methodology engine: contradiction detection, inventive-principle selection, 3-No classification, DIKWP transformations with semantic axioms, and technical spec writing. Multi-state evidence grounding and bt-harness orchestration.

Synopsis

import { createTrizTool, detectTrizContradictions, proposeInventivePrinciples } from '@polyweave/triz';

const contradictions = detectTrizContradictions({
  statement: 'Battery weight vs. capacity trade-off in electric vehicles',
  domain: 'automotive'
});

const principles = proposeInventivePrinciples(contradictions[0]);
console.log(principles.map(p => p.name)); // e.g. ["Parameter changes", "Universality", "Feedback", "Segmentation"]

Install

npm install @polyweave/triz

Why

The triz package implements a full LLM-driven TRIZ (Theory of Inventive Problem Solving) methodology engine, extended with DIKWP (Data-Information-Knowledge-Wisdom-Purpose) transformations and semantic axioms for creative problem-solving. It detects engineering contradictions in problem statements, selects appropriate inventive principles from the TRIZ matrix, applies 3-No classification (No Compromise, No Delay, No Waste — actually Incomplete/Inconsistent/Imprecise), performs DIKWP layer transformations, and scores creative ideas against a multi-dimensional rubric.

The package includes:

  • TRIZ Tool — A bt-harness duplex tool that orchestrates the full TRIZ pipeline: contradiction detection → inventive principle selection → DIKWP transformation → semantic axiom verification → idea scoring.
  • TRIZ Harness — Standalone bt-harness wrapper with the TRIZ behavior tree spec (TRIZ_SPEC).
  • Pure Functions — All core TRIZ logic exposed as standalone functions for programmatic use.
  • Data Tables — Full TRIZ engineering parameters (39 parameters), inventive principles (40 principles), and DIKWP-TRIZ contradiction matrix.
  • Protocol GrowinggrowTrizProtocol and defaultTrizProtocolSeeds for nursery-based TRIZ protocol optimization.

API

Constants

TRIZ_SPEC

The behavior tree specification string for the TRIZ pipeline. Defines problem (string) and maxIdeas (number=3) parameters, symbolic guards (@problem_ready, @evidence_ready, etc.), and a tree: sequence { define_problem, ground_evidence, choose_branch, form_contradictions, select_principles, generate_ideas }.

TRIZ_PROJECTIONS

Object.freeze-d mapping of 7 multi-state entity projections: sleuth/SleuthEvidence, triz/TRIZProblem, triz/TRIZContradiction, triz/InventivePrinciple, triz/Idea, triz/DIKWPTransformation, triz/EvidenceUse, triz/SpecPhase.

TRIZ_ENGINEERING_PARAMETERS

Object.freeze-d array of 39 engineering parameters. Each entry: { number, name }.

TRIZ_INVENTIVE_PRINCIPLES

Object.freeze-d array of 40 inventive principles. Each entry: { number, name, description }.

DIKWP_DIMENSIONS

Object.freeze-d array of 5 dimension objects. Each: { key: 'D'|'I'|'K'|'W'|'P', name, description }.

DIKWP_TRIZ_MATRIX

Object.freeze-d mapping from "from:to" (e.g. "D:I") to arrays of principle numbers. 25 entries covering D,D through P,P.

Tool Factories

createTrizTool(options)

Name Type Required Default Description
options object no {} Configuration
options.apiKey string no API key for LLM calls
options.model string no 'deepseek-v4-flash' Agent model name
options.state object no auto-created via createMultiStateStore Multi-state store for evidence grounding
options.createAdapter function no Custom adapter factory
options.adapterConfig object no Adapter factory configuration
options.debug boolean no Enable debug output
options.direct boolean no If true, runs the deterministic (non-LLM) pipeline directly
options.maxIdeas number no 3 Max ideas to generate
options.problem string no '' Default problem statement
options.sleuthTool object no null Pre-built Sleuth tool (avoids auto-creation)
options.sleuthOptions object no Options for auto-created Sleuth tool
options.createSleuth boolean no true Whether to auto-create a Sleuth tool

Returns { source, sink, _toolName: 'triz', state, close }.

Frame protocol (tick-driven):

Inbound Outbound
DESCRIBE DESCRIPTION (name='triz', capabilities=['write','execute']), END
TOOL_CALL PROGRESS (phase: 'starting'), TOOL_RESULT (success, state), END
TICK (forwarded to harness)
CANCEL cancels current harness
ABORT aborts current harness
ERROR (message: 'Already running' — if TOOL_CALL arrives while running)
ERROR (harness errors joined by '; ' — if harness creation fails validation)
ERROR (bt:error frame content)

TOOL_CALL args (merged from content.arguments or content.args):

  • problem / problemSpace / statement — the problem to solve
  • direct — override for deterministic run
  • maxIdeas — override for max idea count

When direct mode is active, runs the deterministic pipeline synchronously (no LLM) and emits TOOL_RESULT directly. Otherwise, creates a bt-harness, wires it to bt:tree_complete / bt:tree_failed / bt:error events, and streams progress.

createTrizHarness(options)

Name Type Required Default Description
options object no {} Configuration
options.state object no auto-created Multi-state store
options.sleuthTool object no auto-created Sleuth tool instance
options.spec string|object no parsed TRIZ_SPEC Behavior tree spec
options.apiKey string no API key
options.model / options.agentModel string no 'deepseek-v4-flash' Agent model
options.evalModel string no same as model Evaluator model
options.problem string no '' Problem for params
options.maxIdeas number no 3 Max ideas for params
options.maxTreeLoops number no 10 Max behavior tree iterations
options.initialSymbolics object no {} Initial symbolic state
options.createAdapter function no Custom adapter factory
options.adapterConfig object no Adapter config
options.agentAdapter object no null Pre-built agent adapter
options.evaluatorAdapter object no null Pre-built evaluator adapter
options.agentSystem string no Agent system prompt
options.evalSystem string no Evaluator system prompt
options.agentMaxTokens number no Agent max tokens
options.evalMaxTokens number no Evaluator max tokens
options.agentTemperature number no Agent temperature
options.evalTemperature number no Evaluator temperature
options.timeoutMs number no Timeout
options.debugText string no Debug text
options.debug / options._debug boolean no false Debug flag
Plus all createTrizTools options for the internal tool bundle.

Returns a bt-harness-compatible tool with { source, sink, cancel, abort, valid, errors }. Internally creates a createTrizTools bundle, optionally adds a Sleuth tool, parses the behavior tree spec, and delegates to createBtHarness.

createTrizTools(options)

Creates an internal tool bundle with 8 individual tool duplexes registered in a multi-state store.

Name Type Required Default Description
options object no {} Configuration
options.state object no auto-created Multi-state store
options.reasoner object no auto-created via createTrizReasoner TRIZ reasoner instance
options.reasonerOptions object no {} Options for auto-created reasoner
options.llm object no null LLM adapter (sink/source duplex)
options.embeddings object no null Embedding adapter
options.llmOptions object no {} { temperature, maxTokens } for LLM calls
options.useLLM boolean no true Whether to use LLM for contradiction/principles detection

Returns { tools: Array<{ source, sink, _toolName }>, state, reasoner }.

The 8 registered tools:

  • triz_read — reads entities from state / returns parameter/principles lists
  • triz_problem — creates TRIZProblem record
  • triz_evidence — searches SleuthEvidence, creates EvidenceUse records
  • triz_branch — chooses TRIZ vs DIKWP-TRIZ branch via reasoner
  • triz_contradiction — detects contradictions (deterministic keyword match or LLM)
  • triz_principles — selects inventive principles (deterministic matrix lookup or LLM)
  • triz_dikwp — proposes DIKWP transformations (deterministic 3-No routing or LLM)
  • triz_idea — creates and scores an Idea record
  • triz_spec_writer — LLM-only; generates DIKWP spec phases for a requirement

Each tool follows the createToolDuplex contract: receives TOOL_CALL frames and emits TOOL_RESULT on the source.

createTrizReasoner(options)

Name Type Required Default Description
options object no {} Default options merged into every call

Returns a plain object with methods:

  • chooseBranch(problemSpace, overrides) — delegates to chooseTrizBranch
  • classifyThreeNo(problemSpace) — delegates to classifyThreeNo
  • detectContradictions(problemSpace, overrides) — delegates to detectTrizContradictions
  • proposeDikwpTransformations(problemSpace, overrides) — delegates to proposeDikwpTransformations
  • proposePrinciples(contradiction, overrides) — delegates to proposeInventivePrinciples
  • scoreIdea(idea, context) — delegates to scoreTrizIdea

No thrown errors.

Pure Functions

classifyThreeNo(problemSpace)

Name Type Required Default Description
problemSpace string|object yes Problem string or { statement, objective, purpose, system, context, domain, constraints }

Returns { incomplete, inconsistent, imprecise, type, missingFields: Array<string>, score: number }. Uses keyword matching against the lowercased joined text. type is one of 'incomplete', 'inconsistent', 'imprecise', 'incomplete+inconsistent', 'inconsistent+imprecise', 'incomplete+imprecise', or 'none'. score ranges 0–1 (0=clean, 1=all three issues present).

Does not throw.

chooseTrizBranch(problemSpace, options)

Name Type Required Default Description
problemSpace string|object yes Problem space (same as classifyThreeNo)
options.branch string no Force a branch: 'pure-triz' or 'dikwp-triz'

Returns { branch, threeNo, cognitive, rationale }. Branch defaults to 'dikwp-triz' if 3-No score > 0 or cognitive keywords are matched, otherwise 'pure-triz'.

Does not throw.

detectTrizContradictions(problemSpace, options)

Name Type Required Default Description
problemSpace string|object yes Problem with statement, objective, system, constraints, idealFinalResult
options.limit number no 2 Max contradictions to return

Returns an array of contradiction objects: { improvingParameter, worseningParameter, improvingNumber, worseningNumber, contradictionText, context, severity }. Uses keyword matching against the lowercased problem text to pick improving/worsening parameter pairs from the 39 TRIZ parameters. Falls back to [35, 36, 'Improve adaptability...'] if no keywords match.

Does not throw.

proposeInventivePrinciples(contradiction, options)

Name Type Required Default Description
contradiction object yes Contradiction with improvingNumber/improvingParameter and worseningNumber/worseningParameter
options.limit number no 4 Max principles to return

Returns an array of principle objects: { number, name, description }. Looks up imp:wors and wors:imp keys in TRIZ_CONTRADICTION_MATRIX. Falls back to [15, 35, 1, 23] with special cases for complexity (param 36), energy loss (22), and stability (13).

Does not throw.

proposeDikwpTransformations(problemSpace, options)

Name Type Required Default Description
problemSpace string|object yes Problem space
options.limit number no 5 Max transformations to return

Returns an array of transformation objects: { branch: 'dikwp-triz', from, to, threeNoType, transformationText, principleNumbers, principles, semanticChecks }. Routes based on 3-No classification: incomplete/inconsistent/imprecise each produce specific D→I→K→W→P transformation pairs.

Does not throw.

checkSemanticAxioms(record, context)

Name Type Required Default Description
record object yes Record with expressions (or statement/purpose/transformationText/proposal), concepts (or from/to/branch/threeNoType), and labels
context object no {} Context with optional context or omega field

Returns { context, existence, uniqueness, transitivity, passed }. existence checks that all expressions and concepts are non-empty. uniqueness checks no duplicate lowercased expressions or label values. transitivity checks that from:to is present in DIKWP_TRIZ_MATRIX (or either field is missing).

Does not throw.

scoreTrizIdea(idea, context)

Name Type Required Default Description
idea object yes Idea with expectedGain, confidence, risk (string)
context object no {} Context with optional evidence (array) or evidenceCount (number)

Returns a number 0–1 computed as clamp01(gain * 0.4 + confidence * 0.4 + evidenceScore * 0.2 - penalty). Risk containing 'high' applies a 0.1 penalty. Missing evidence counts as 0.

Does not throw.

defaultTrizProtocolSeeds(options)

Name Type Required Default Description
options object no {} Options with optional requirement string

Returns an array of 2 protocol seed objects, each with id, name, usesExecutionGraph, spec, metrics, uncertainty, selfImproving, tokenEconomics, decomposition. The first seed uses TRIZ_SPEC directly; the second generates a convergence staging spec.

Does not throw.

growTrizProtocol(options)

Name Type Required Default Description
options object no {} Options passed to growProtocol from @polyweave/nursery
options.packageInventory array no DEFAULT_PACKAGE_ROLES + triz/sleuth/state entries Available packages
options.candidates array no defaultTrizProtocolSeeds(options) Protocol candidates

Returns the result of growProtocol() call.

No thrown errors (delegates to nursery).

Tests

npm test

Tests cover TRIZ tool creation and execution, contradiction detection with parameter mapping, inventive principle selection from the matrix, 3-No classification, DIKWP transformation proposals, semantic axiom verification, idea scoring across all dimensions, bt-harness integration, protocol growing, and multi-state evidence grounding.

Requirements

  • Node.js >= 22.0.0
  • ESM only
  • @polyweave/core (dependency)
  • @polyweave/tools (dependency)
  • @polyweave/bt-harness (dependency)
  • @polyweave/state (dependency)
  • @polyweave/sleuth (dependency)
  • @polyweave/nursery (dependency)
  • @polyweave/creativity (dependency)

Caveats

  • The TRIZ matrix lookup uses the classical 39×39 contradiction matrix. Non-standard contradictions or domains may require manual principle mapping.
  • DIKWP transformations are LLM-generated and should be validated against domain-specific semantic axioms before production use.
  • The package includes all TRIZ data tables (parameters, principles, matrix) as static data. These are reference implementations; extend or customize for specialized domains.

Dependencies

Dependencies

ID Version
@polyweave/bt-harness *
@polyweave/core *
@polyweave/creativity *
@polyweave/nursery *
@polyweave/sleuth *
@polyweave/state *
@polyweave/tools *

Development Dependencies

ID Version
@rigor/core *

Keywords

polyweave triz dikwp-triz innovation behavior-tree llm
Details
npm
2026-07-11 15:34:37 +00:00
4
John Dvorak
SEE LICENSE IN LICENSE
latest
21 KiB
Assets (1)
Versions (3) View all
1.0.5 2026-07-11
1.0.2 2026-07-11
1.0.1 2026-07-10