feat(policy): enforce truthfulness and autonomy guardrails
Add runtime truthfulness modes and autonomy-level tool gating with audit metadata for overrides/denials. Wire policy through prompt assembly, tool execution context, and daemon/gateway agent paths; update tests and planning state for Phase 3 PR #2 completion.
This commit is contained in:
@@ -212,6 +212,9 @@ const automationSchema = z.object({
|
||||
heartbeat: heartbeatSchema,
|
||||
}).default({});
|
||||
|
||||
const truthfulnessModeSchema = z.enum(['strict', 'standard', 'relaxed']);
|
||||
const autonomyLevelSchema = z.enum(['conservative', 'standard', 'autonomous']);
|
||||
|
||||
const agentsSchema = z.object({
|
||||
primary_tier: z.enum(['fast', 'default', 'complex', 'local']).default('default'),
|
||||
delegation: z.object({
|
||||
@@ -231,6 +234,10 @@ const agentsSchema = z.object({
|
||||
max_delegation_depth: z.number().min(1).max(10).default(3),
|
||||
/** Maximum tool-loop iterations before the agent stops. */
|
||||
max_iterations: z.number().min(1).max(50).default(10),
|
||||
/** Truthfulness enforcement level: strict | standard | relaxed. */
|
||||
truthfulness_mode: truthfulnessModeSchema.default('standard'),
|
||||
/** Autonomy level for tool execution: conservative | standard | autonomous. */
|
||||
autonomy_level: autonomyLevelSchema.default('standard'),
|
||||
}).default({});
|
||||
|
||||
const embeddingProviderSchema = z.enum(['openai', 'gemini', 'ollama', 'llamacpp', 'voyage']);
|
||||
@@ -252,6 +259,8 @@ const memorySchema = z.object({
|
||||
enabled: z.boolean().default(true),
|
||||
dir: z.string().optional(), // Default: ~/.local/share/flynn/memory
|
||||
auto_extract: z.boolean().default(true),
|
||||
injection_strategy: z.enum(['all', 'recent', 'adaptive']).default('all'),
|
||||
max_injection_tokens: z.number().min(100).max(10000).default(2000),
|
||||
max_context_tokens: z.number().min(100).max(10000).default(2000),
|
||||
embedding: embeddingSchema,
|
||||
}).default({});
|
||||
@@ -261,6 +270,7 @@ const compactionSchema = z.object({
|
||||
threshold_pct: z.number().min(10).max(100).default(80),
|
||||
keep_turns: z.number().min(1).max(50).default(4),
|
||||
summary_max_tokens: z.number().min(128).max(4096).default(1024),
|
||||
importance_threshold: z.number().min(0).max(1).default(1),
|
||||
}).default({});
|
||||
|
||||
const discordSchema = z.object({
|
||||
@@ -375,6 +385,34 @@ const routingSchema = z.object({
|
||||
senders: z.record(z.string(), z.string()).default({}),
|
||||
}).default({});
|
||||
|
||||
const intentTargetTypeSchema = z.enum(['agent', 'skill']);
|
||||
|
||||
const intentRuleSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
patterns: z.array(z.string().min(1)).min(1),
|
||||
target: z.object({
|
||||
type: intentTargetTypeSchema,
|
||||
name: z.string().min(1),
|
||||
}),
|
||||
priority: z.number().default(0),
|
||||
enabled: z.boolean().default(true),
|
||||
});
|
||||
|
||||
const intentsSchema = z.object({
|
||||
enabled: z.boolean().default(false),
|
||||
match_threshold: z.number().min(0).max(1).default(0.7),
|
||||
rules: z.array(intentRuleSchema).default([]),
|
||||
}).default({});
|
||||
|
||||
const routingPolicySchema = z.object({
|
||||
enabled: z.boolean().default(false),
|
||||
fast_path_threshold: z.number().min(0).max(1).default(0.85),
|
||||
llm_threshold: z.number().min(0).max(1).default(0.5),
|
||||
default_path: z.enum(['fast', 'llm']).default('llm'),
|
||||
}).default({});
|
||||
|
||||
const contextLevelSchema = z.enum(['minimal', 'normal', 'detailed', 'debug']);
|
||||
|
||||
const promptSchema = z.object({
|
||||
/** Additional directories to search for prompt template files. */
|
||||
search_dirs: z.array(z.string()).default([]),
|
||||
@@ -383,12 +421,22 @@ const promptSchema = z.object({
|
||||
name: z.string(),
|
||||
content: z.string(),
|
||||
})).default([]),
|
||||
/** Prompt context depth control: minimal | normal | detailed | debug. */
|
||||
context_level: contextLevelSchema.default('normal'),
|
||||
}).default({});
|
||||
|
||||
const sessionsSchema = z.object({
|
||||
ttl: z.string().default('30d'),
|
||||
}).default({});
|
||||
|
||||
const historyIndexSchema = z.object({
|
||||
enabled: z.boolean().default(false),
|
||||
max_keywords: z.number().min(1).max(20).default(8),
|
||||
search_limit: z.number().min(1).max(100).default(10),
|
||||
min_score: z.number().min(0).max(1).default(0.15),
|
||||
routing_boost: z.number().min(0).max(0.2).default(0.05),
|
||||
}).default({});
|
||||
|
||||
const logLevelSchema = z.enum(['debug', 'info', 'warn', 'error', 'silent']).default('info');
|
||||
|
||||
const auditLevelSchema = z.enum(['debug', 'info', 'warn', 'error']).default('debug');
|
||||
@@ -432,6 +480,9 @@ export const configSchema = z.object({
|
||||
sandbox: sandboxSchema,
|
||||
agent_configs: agentConfigsSchema,
|
||||
routing: routingSchema,
|
||||
intents: intentsSchema,
|
||||
routing_policy: routingPolicySchema,
|
||||
history_index: historyIndexSchema,
|
||||
sessions: sessionsSchema,
|
||||
pairing: pairingSchema,
|
||||
});
|
||||
@@ -453,6 +504,7 @@ export type DiscordConfig = z.infer<typeof discordSchema>;
|
||||
export type SlackConfig = z.infer<typeof slackSchema>;
|
||||
export type WhatsAppConfig = z.infer<typeof whatsappSchema>;
|
||||
export type RetryPolicyConfig = z.infer<typeof retrySchema>;
|
||||
export type ContextLevel = z.infer<typeof contextLevelSchema>;
|
||||
export type PromptConfig = z.infer<typeof promptSchema>;
|
||||
export type ToolProfile = z.infer<typeof toolProfileEnum>;
|
||||
export type ToolOverrideConfig = z.infer<typeof toolOverrideSchema>;
|
||||
@@ -460,6 +512,11 @@ export type ToolsConfig = z.infer<typeof toolsSchema>;
|
||||
export type SandboxConfig = z.infer<typeof sandboxSchema>;
|
||||
export type AgentConfigEntry = z.infer<typeof agentConfigEntrySchema>;
|
||||
export type RoutingConfig = z.infer<typeof routingSchema>;
|
||||
export type IntentTargetType = z.infer<typeof intentTargetTypeSchema>;
|
||||
export type IntentRuleConfig = z.infer<typeof intentRuleSchema>;
|
||||
export type IntentsConfig = z.infer<typeof intentsSchema>;
|
||||
export type RoutingPolicyConfig = z.infer<typeof routingPolicySchema>;
|
||||
export type HistoryIndexConfig = z.infer<typeof historyIndexSchema>;
|
||||
export type ServerConfig = z.infer<typeof serverSchema>;
|
||||
export type SessionsConfig = z.infer<typeof sessionsSchema>;
|
||||
export type ThinkingConfig = z.infer<typeof thinkingSchema>;
|
||||
@@ -475,3 +532,5 @@ export type PairingCodeConfig = z.infer<typeof pairingSchema>;
|
||||
export type LogLevel = z.infer<typeof logLevelSchema>;
|
||||
export type AuditConfig = z.infer<typeof auditSchema>;
|
||||
export type AuditLevel = z.infer<typeof auditLevelSchema>;
|
||||
export type TruthfulnessMode = z.infer<typeof truthfulnessModeSchema>;
|
||||
export type AutonomyLevel = z.infer<typeof autonomyLevelSchema>;
|
||||
|
||||
Reference in New Issue
Block a user