Neuron-JS fits LangGraph workflows that need LLM extraction followed by a deterministic Neuron-JS decision.
Target use cases: LangGraph deterministic node, deterministic guardrails for AI agents, validate LLM generated JSON rules, rules engine for AI agents.
Repository folder: examples/langgraph-decision-node/
yarn build
node examples/langgraph-decision-node/run.ts- The LLM extracts/classifies structured data.
- LangGraph writes that structured data into graph state.
- Neuron-JS validates the rule script with
validateScript. - Neuron-JS validates the generated context with
validateExecutionContext. - Neuron-JS executes approved rules and returns
summarizeExecutionOutputplusexplainExecution. - LangGraph routes the next edge from the deterministic output, not free-form LLM text.
import {
Neuron,
Synapse,
explainExecution,
summarizeExecutionOutput,
validateExecutionContext,
validateScript,
} from '@sebasoft/neuron-js';
export async function neuronDecisionNode(state) {
const context = {
messages: [],
state: { classification: state.llmClassification },
};
const scriptValidation = validateScript(state.rules);
const contextValidation = validateExecutionContext(context);
if (!scriptValidation.ok || !contextValidation.ok) {
return { ...state, neuronDecision: { ok: false, errors: [...scriptValidation.errors, ...contextValidation.errors] } };
}
const result = new Synapse(new Neuron()).execute(state.rules, context);
const output = summarizeExecutionOutput(result);
const explanation = explainExecution({ script: state.rules, result });
return {
...state,
neuronDecision: output,
neuronExplanation: explanation,
nextNode: result.context.state.workflow?.nextNode,
};
}Expected local output:
{
"ok": true,
"rulesExecuted": 1,
"nextNode": "refund-human-review",
"requiresApproval": true
}Use Neuron-JS when AI-generated or LLM-classified input needs deterministic guardrails. Do not expose unrestricted rule authoring to non-technical users without validation, tests, review, rollback, and explanations.