Skip to content

Commit 4558739

Browse files
Zie619claude
andcommitted
fix(n8n): wire brain mode UI params to TruseraAgent + include analysis in output
Brain mode was hardcoded OFF in TruseraAgent. Now reads enableBrainMode, brainApiKey, brainBaseUrl, brainModel from node UI. Brain analysis (decision, reasoning, confidence, flaggedConcerns) included in intermediateSteps and _trusera output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6c31cc0 commit 4558739

1 file changed

Lines changed: 54 additions & 2 deletions

File tree

n8n-node/nodes/TruseraAgent/TruseraAgent.node.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,38 @@ export class TruseraAgent implements INodeType {
120120
default: true,
121121
description: 'Whether to detect prompt injection in tool arguments',
122122
},
123+
{
124+
displayName: 'Enable Brain Mode',
125+
name: 'enableBrainMode',
126+
type: 'boolean',
127+
default: false,
128+
description: 'Whether to use an LLM to evaluate complex policies contextually (adds ~1s per tool call)',
129+
},
130+
{
131+
displayName: 'Brain Mode API Key',
132+
name: 'brainApiKey',
133+
type: 'string',
134+
typeOptions: { password: true },
135+
default: '',
136+
displayOptions: { show: { enableBrainMode: [true] } },
137+
description: 'API key for the brain mode LLM (OpenAI-compatible)',
138+
},
139+
{
140+
displayName: 'Brain Mode Base URL',
141+
name: 'brainBaseUrl',
142+
type: 'string',
143+
default: 'https://api.openai.com/v1',
144+
displayOptions: { show: { enableBrainMode: [true] } },
145+
description: 'Base URL for the brain mode LLM API',
146+
},
147+
{
148+
displayName: 'Brain Mode Model',
149+
name: 'brainModel',
150+
type: 'string',
151+
default: 'gpt-4o-mini',
152+
displayOptions: { show: { enableBrainMode: [true] } },
153+
description: 'Model for AI-powered policy evaluation',
154+
},
123155
{
124156
displayName: 'Max Iterations',
125157
name: 'maxIterations',
@@ -146,6 +178,10 @@ export class TruseraAgent implements INodeType {
146178
const inlineCedarDsl = this.getNodeParameter('inlineCedarDsl', 0, '') as string;
147179
const enablePiiDetection = this.getNodeParameter('enablePiiDetection', 0, true) as boolean;
148180
const enablePromptInjection = this.getNodeParameter('enablePromptInjection', 0, true) as boolean;
181+
const enableBrainMode = this.getNodeParameter('enableBrainMode', 0, false) as boolean;
182+
const brainApiKey = this.getNodeParameter('brainApiKey', 0, '') as string;
183+
const brainBaseUrl = this.getNodeParameter('brainBaseUrl', 0, 'https://api.openai.com/v1') as string;
184+
const brainModel = this.getNodeParameter('brainModel', 0, 'gpt-4o-mini') as string;
149185
const maxIterations = this.getNodeParameter('maxIterations', 0, 10) as number;
150186
const platformUrl = credentials.platformUrl.replace(/\/+$/, '');
151187

@@ -161,7 +197,12 @@ export class TruseraAgent implements INodeType {
161197
enableContentFilter: false,
162198
inlineCedarDsl,
163199
policyCacheTtlMs: 60_000,
164-
brainMode: { enabled: false },
200+
brainMode: {
201+
enabled: enableBrainMode,
202+
model: brainModel,
203+
},
204+
brainApiKey: brainApiKey || undefined,
205+
brainBaseUrl: brainBaseUrl || undefined,
165206
});
166207

167208
const reporter = new SidecarReporter(platformUrl, credentials.apiKey, agentName);
@@ -478,6 +519,12 @@ export class TruseraAgent implements INodeType {
478519
input: toolArgs,
479520
output: `BLOCKED: ${reasons}`,
480521
blocked: true,
522+
brainAnalysis: policyResult.brainAnalysis ? {
523+
decision: policyResult.brainAnalysis.decision,
524+
reasoning: policyResult.brainAnalysis.reasoning,
525+
confidence: policyResult.brainAnalysis.confidence,
526+
flaggedConcerns: policyResult.brainAnalysis.flaggedConcerns,
527+
} : undefined,
481528
});
482529

483530
// Break out of the agent loop
@@ -533,7 +580,12 @@ export class TruseraAgent implements INodeType {
533580
input: toolArgs,
534581
output: toolResult.slice(0, 1000),
535582
blocked: false,
536-
debug: rawToolCallDebug,
583+
brainAnalysis: policyResult.brainAnalysis ? {
584+
decision: policyResult.brainAnalysis.decision,
585+
reasoning: policyResult.brainAnalysis.reasoning,
586+
confidence: policyResult.brainAnalysis.confidence,
587+
flaggedConcerns: policyResult.brainAnalysis.flaggedConcerns,
588+
} : undefined,
537589
});
538590
}
539591

0 commit comments

Comments
 (0)