Problem Statement
Is your feature request related to a problem? Please describe.
The docs/features/enterprise-hitl.md documentation describes comprehensive enterprise HITL (Human-in-the-Loop) features that do not exist in the actual codebase. This creates a significant gap between documented capabilities and actual implementation, potentially misleading users who rely on the documentation.
Current implemented HITLConfig in src/lib/types/hitlTypes.ts:
export type HITLConfig = {
enabled: boolean;
dangerousActions: string[];
timeout?: number;
confirmationMethod?: "event";
allowArgumentModification?: boolean;
autoApproveOnTimeout?: boolean;
auditLogging?: boolean;
customRules?: HITLRule[];
};
Documented but NOT implemented features:
confidenceThreshold - AI confidence threshold for automatic approval
contentPatterns - RegExp patterns for content-based HITL triggers
mode - Synchronous vs asynchronous approval workflows
reviewCallback - Custom callback for review logic
statusCallback - Callback for checking async review status
escalationPolicy - Multi-level escalation configuration
requireApproval - Explicit tool names requiring approval
- Enhanced
auditLog with storage backends (file/database/custom)
Proposed Solution
Describe the solution you'd like
Implement the missing enterprise HITL features to match the documentation. The enhanced HITLConfig should support:
1. Confidence Threshold Trigger
confidenceThreshold?: number; // 0-1, trigger review if AI confidence below this
2. Content Pattern Matching
contentPatterns?: RegExp[]; // Patterns that trigger mandatory review
3. Approval Mode
mode?: 'synchronous' | 'asynchronous'; // Blocking vs non-blocking approval
4. Review Callbacks
reviewCallback?: (action: HITLAction, context: HITLContext) => Promise<HITLReviewResult>;
statusCallback?: (reviewId: string) => Promise<HITLReviewStatus>;
5. Escalation Policy
escalationPolicy?: {
onTimeout: 'approve' | 'reject' | 'escalate';
escalationLevels?: Array<{
level: number;
reviewers: string[];
timeout: number;
finalAuthority?: boolean;
}>;
};
6. Enhanced Audit Logging
auditLog?: {
enabled: boolean;
storage: 'file' | 'database' | 'custom';
path?: string;
database?: DatabaseConfig;
customLogger?: (entry: AuditEntry) => Promise<void>;
};
7. Explicit Tool Approval List
requireApproval?: string[]; // Tool names that always require approval
Example Usage
Describe how you would use this feature
import { NeuroLink } from "@juspay/neurolink";
const neurolink = new NeuroLink({
hitl: {
enabled: true,
mode: "synchronous",
// Confidence-based triggers
confidenceThreshold: 0.85, // Review if AI confidence < 85%
// Content-based triggers
contentPatterns: [
/\b\d{3}-\d{2}-\d{4}\b/, // SSN pattern
/password|secret|token/i, // Sensitive keywords
],
// Explicit tool approval
requireApproval: ["deleteFile", "sendEmail", "executeCode"],
// Review callback
reviewCallback: async (action, context) => {
// Custom approval logic (Slack, email, custom UI)
const approved = await showApprovalDialog(action);
return {
approved,
reason: approved ? "User authorized" : "User denied",
reviewer: "admin@company.com",
};
},
// Escalation for timeouts
escalationPolicy: {
onTimeout: "escalate",
escalationLevels: [
{ level: 1, reviewers: ["team-lead@company.com"], timeout: 300000 },
{ level: 2, reviewers: ["manager@company.com"], timeout: 600000 },
{ level: 3, reviewers: ["cto@company.com"], timeout: 1800000, finalAuthority: true },
],
},
// Enhanced audit logging
auditLog: {
enabled: true,
storage: "database",
customLogger: async (entry) => {
await complianceDB.insert("hitl_audit", entry);
},
},
// Existing features
dangerousActions: ["delete", "remove", "drop"],
timeout: 300000,
allowArgumentModification: true,
autoApproveOnTimeout: false,
},
});
Asynchronous mode example:
const neurolink = new NeuroLink({
hitl: {
enabled: true,
mode: "asynchronous",
reviewCallback: async (action, context) => {
// Queue for review, return immediately
const reviewId = await queueForReview(action);
return {
pending: true,
reviewId,
estimatedTime: 900000, // 15 minutes
};
},
statusCallback: async (reviewId) => {
// Check approval status
const status = await checkReviewStatus(reviewId);
return {
approved: status.decision === "approved",
pending: status.decision === "pending",
reason: status.reason,
reviewer: status.reviewerEmail,
};
},
},
});
Alternatives Considered
Describe alternatives you've considered
- Alternative 1: Keep current simple implementation - This limits enterprise adoption in regulated industries (healthcare, finance, legal)
- Alternative 2: External webhook-only approach - Less type-safe and harder to integrate
- Alternative 3: Separate enterprise package - Fragments the ecosystem and complicates maintenance
The proposed solution provides a unified, type-safe API that supports both simple and complex enterprise workflows.
Use Case
What is your use case?
- Industry: Healthcare, Finance, Legal, Government
- Application type: AI assistants handling sensitive operations
- Scale: Enterprise production deployments with compliance requirements
Specific scenarios:
- Medical AI requiring physician oversight for diagnosis recommendations
- Financial systems needing multi-level approval for transactions above thresholds
- Legal document generation requiring attorney review
- Code execution safety with security review gates
Impact
Who would benefit from this feature?
Additional Context
Documentation vs Implementation Gap:
| Feature |
Documented |
Implemented |
enabled |
Yes |
Yes |
dangerousActions |
Yes |
Yes |
timeout |
Yes |
Yes |
allowArgumentModification |
Yes |
Yes |
autoApproveOnTimeout |
Yes |
Yes |
auditLogging |
Yes |
Yes (basic) |
customRules |
Yes |
Yes |
confidenceThreshold |
Yes |
No |
contentPatterns |
Yes |
No |
mode (sync/async) |
Yes |
No |
reviewCallback |
Yes |
No |
statusCallback |
Yes |
No |
escalationPolicy |
Yes |
No |
requireApproval |
Yes |
No |
Enhanced auditLog |
Yes |
No |
Related Files:
- Documentation:
docs/features/enterprise-hitl.md
- Current Implementation:
src/lib/types/hitlTypes.ts
- HITL Manager:
src/lib/hitl/hitlManager.ts
Implementation Considerations
Optional: Technical details
- Affected components:
src/lib/hitl/, src/lib/types/hitlTypes.ts, src/lib/neurolink.ts
- Breaking changes: No - new features are additive, existing config remains valid
- Provider compatibility: All providers
- Performance implications:
- Synchronous mode adds latency during approval
- Asynchronous mode requires state management
- Content pattern matching adds minimal overhead
Suggested Implementation Order:
requireApproval - Simple array-based tool matching
mode with reviewCallback - Core async/sync workflow
confidenceThreshold - Requires confidence scoring integration
contentPatterns - RegExp matching on content
escalationPolicy - Complex state machine
statusCallback - Async polling mechanism
- Enhanced
auditLog - Storage backend abstraction
Checklist
Problem Statement
Is your feature request related to a problem? Please describe.
The
docs/features/enterprise-hitl.mddocumentation describes comprehensive enterprise HITL (Human-in-the-Loop) features that do not exist in the actual codebase. This creates a significant gap between documented capabilities and actual implementation, potentially misleading users who rely on the documentation.Current implemented
HITLConfiginsrc/lib/types/hitlTypes.ts:Documented but NOT implemented features:
confidenceThreshold- AI confidence threshold for automatic approvalcontentPatterns- RegExp patterns for content-based HITL triggersmode- Synchronous vs asynchronous approval workflowsreviewCallback- Custom callback for review logicstatusCallback- Callback for checking async review statusescalationPolicy- Multi-level escalation configurationrequireApproval- Explicit tool names requiring approvalauditLogwith storage backends (file/database/custom)Proposed Solution
Describe the solution you'd like
Implement the missing enterprise HITL features to match the documentation. The enhanced
HITLConfigshould support:1. Confidence Threshold Trigger
2. Content Pattern Matching
3. Approval Mode
4. Review Callbacks
5. Escalation Policy
6. Enhanced Audit Logging
7. Explicit Tool Approval List
Example Usage
Describe how you would use this feature
Asynchronous mode example:
Alternatives Considered
Describe alternatives you've considered
The proposed solution provides a unified, type-safe API that supports both simple and complex enterprise workflows.
Use Case
What is your use case?
Specific scenarios:
Impact
Who would benefit from this feature?
Additional Context
Documentation vs Implementation Gap:
enableddangerousActionstimeoutallowArgumentModificationautoApproveOnTimeoutauditLoggingcustomRulesconfidenceThresholdcontentPatternsmode(sync/async)reviewCallbackstatusCallbackescalationPolicyrequireApprovalauditLogRelated Files:
docs/features/enterprise-hitl.mdsrc/lib/types/hitlTypes.tssrc/lib/hitl/hitlManager.tsImplementation Considerations
Optional: Technical details
src/lib/hitl/,src/lib/types/hitlTypes.ts,src/lib/neurolink.tsSuggested Implementation Order:
requireApproval- Simple array-based tool matchingmodewithreviewCallback- Core async/sync workflowconfidenceThreshold- Requires confidence scoring integrationcontentPatterns- RegExp matching on contentescalationPolicy- Complex state machinestatusCallback- Async polling mechanismauditLog- Storage backend abstractionChecklist