import {
TealEngineV12,
TealGuard,
TealRegistry,
TealAudit,
PolicyMode,
} from 'tealtiger';
// --- Initialize modules ---
const guard = new TealGuard({
promptInjection: { enabled: true, mode: PolicyMode.ENFORCE },
contentModeration: { enabled: true, mode: PolicyMode.ENFORCE },
});
const registry = new TealRegistry({
tools: {
allowlist: ['issue_refund', 'check_order_status', 'search_customer_history'],
},
});
const audit = new TealAudit({
enabled: true,
redactPII: true,
outputs: ['file', 'http'],
});
const engine = new TealEngineV12({
modules: [guard, registry, audit],
policies: {
tools: {
issue_refund: {
allowed: true,
conditions: {
requireApprovalAbove: 100.0, // Human review for refunds > $100
denyAbove: 5000.0, // Hard deny above $5,000
maxRefundsPerDay: 10,
},
},
},
},
mode: PolicyMode.ENFORCE,
});
// --- Orchestration flow ---
async function handleSupportRequest(userMessage: string, agentId: string) {
const context = engine.createContext({
agentId,
channel: 'customer-support',
environment: 'production',
});
// Step 1: TealGuard scans input
const guardResult = await guard.scan({
content: userMessage,
direction: 'input',
context,
});
if (guardResult.action === 'DENY') {
await audit.log({
type: 'input_blocked',
reason: guardResult.reasonCodes,
correlationId: context.correlationId,
});
return { blocked: true, reason: guardResult.reasonCodes };
}
// Step 2: Agent processes and decides to call a tool
const toolCall = await agentProcess(userMessage); // Your agent logic
// toolCall = { tool: 'issue_refund', args: { orderId: '4821', amount: 150 } }
// Step 3: TealRegistry checks tool authorization
const registryResult = await registry.checkTool({
tool: toolCall.tool,
agentId,
context,
});
if (registryResult.action === 'DENY') {
await audit.log({
type: 'tool_unauthorized',
tool: toolCall.tool,
correlationId: context.correlationId,
});
return { blocked: true, reason: ['TOOL_NOT_ALLOWLISTED'] };
}
// Step 4: TealEngine evaluates tool call against policies
const decision = await engine.evaluate({
action: 'tool.execute',
tool: toolCall.tool,
arguments: toolCall.args,
context,
});
if (decision.action === 'REQUIRE_APPROVAL') {
// Queue for human review
const approvalId = await queueForApproval({
tool: toolCall.tool,
args: toolCall.args,
correlationId: context.correlationId,
decision,
});
await audit.log({
type: 'approval_requested',
tool: toolCall.tool,
amount: toolCall.args.amount,
approvalId,
correlationId: context.correlationId,
});
return { pending: true, approvalId, correlationId: context.correlationId };
}
if (decision.action === 'DENY') {
await audit.log({
type: 'tool_denied',
tool: toolCall.tool,
reason: decision.reasonCodes,
correlationId: context.correlationId,
});
return { blocked: true, reason: decision.reasonCodes };
}
// Step 5: Execute tool
const result = await executeTool(toolCall.tool, toolCall.args);
// Step 6: Audit the full chain
await audit.log({
type: 'tool_executed',
tool: toolCall.tool,
amount: toolCall.args.amount,
result: result.status,
correlationId: context.correlationId,
});
return { success: true, result, correlationId: context.correlationId };
}