The open-source agent harness - the runtime layer that turns an LLM into a working agent.
end: add approval policy schema (#807)
Heer Ambavib342a211ce86
diff --git a/.changeset/user-tool-approval-policy-event.md b/.changeset/user-tool-approval-policy-event.mdnew file mode 100644index 000000000..97d861d6b--- /dev/null+++ b/.changeset/user-tool-approval-policy-event.md@@ -0,0 +1,6 @@+---+"@truefoundry/trueforge-core": patch+"@truefoundry/trueforge": patch+---++Add `user.tool_approval_policy` send-event schema (`allow_session`, optional ISO `expire_at`). Send-only like `user.tool_approval` / `user.tool_response` — not on the durable stream.diff --git a/packages/trueforge-core/src/agent-session/schemas/turn.ts b/packages/trueforge-core/src/agent-session/schemas/turn.tsindex 3c08a46db..dd6d6dec6 100644--- a/packages/trueforge-core/src/agent-session/schemas/turn.ts+++ b/packages/trueforge-core/src/agent-session/schemas/turn.ts@@ -5,6 +5,7 @@ import {AgentInputUserMessageSchema,ModelMessageEventSchema,UserToolApprovalMessageSchema,+ UserToolApprovalPolicyMessageSchema,UserToolResponseMessageSchema,} from '../../core/events/schema';@@ -177,7 +178,11 @@ export const CreateTurnRequestSchema = z.openapi('CreateTurnRequest');export const TurnInboundEventItemSchema = z- .discriminatedUnion('type', [UserToolApprovalMessageSchema, UserToolResponseMessageSchema])+ .discriminatedUnion('type', [+ UserToolApprovalMessageSchema,+ UserToolResponseMessageSchema,+ UserToolApprovalPolicyMessageSchema,+ ]).openapi('TurnInboundEventItem');export type Turn = z.infer<typeof TurnSchema>;diff --git a/packages/trueforge-core/src/core/events/schema.ts b/packages/trueforge-core/src/core/events/schema.tsindex 84b424c10..a8f193cb0 100644--- a/packages/trueforge-core/src/core/events/schema.ts+++ b/packages/trueforge-core/src/core/events/schema.ts@@ -40,6 +40,7 @@ export const EventType = {TOOL_RESPONSE_REQUIRED: 'tool.response_required',USER_TOOL_APPROVAL: 'user.tool_approval',USER_TOOL_RESPONSE: 'user.tool_response',+ USER_TOOL_APPROVAL_POLICY: 'user.tool_approval_policy',USER_MESSAGE: 'user.message',} as const;@@ -96,6 +97,39 @@ export const UserToolResponseMessageSchema = z}).openapi('UserToolResponseInputEvent');+export const ToolApprovalPolicyAllowSessionSchema = z+ .object({+ type: z.literal('allow_session').describe('Allow matching tool calls for the rest of this session.'),+ expire_at: z+ .string()+ .optional()+ .describe('ISO 8601 timestamp when this session allow expires. Omit to allow for the whole session.'),+ })+ .openapi('ToolApprovalPolicyAllowSession');++export const ToolApprovalPolicyItemSchema = z+ .object({+ server_name: z+ .string()+ .min(1, 'server_name is required')+ .describe('Configured MCP server name (same as tool_info.server_name on model.message).'),+ name: z+ .string()+ .min(1, 'name is required')+ .describe('Tool name on that server (same as tool_info.name on model.message).'),+ action: z.discriminatedUnion('type', [ToolApprovalPolicyAllowSessionSchema]),+ })+ .openapi('ToolApprovalPolicyItem');++export const UserToolApprovalPolicyMessageSchema = z+ .object({+ type: z+ .literal(EventType.USER_TOOL_APPROVAL_POLICY)+ .describe('Sticky allow-session policy for matching tools (optional expiry).'),+ policies: z.array(ToolApprovalPolicyItemSchema).min(1).describe('One or more (server_name, name) policy entries.'),+ })+ .openapi('UserToolApprovalPolicyMessage');+export const TextContentPartSchema = z.object({type: z.literal('text').describe('Text content part.'),@@ -373,6 +407,8 @@ export type AgentInfo = z.infer<typeof AgentInfoSchema>;export type ApprovalDecision = z.infer<typeof ApprovalDecisionSchema>;export type UserToolApprovalMessage = z.infer<typeof UserToolApprovalMessageSchema>;export type UserToolResponseMessage = z.infer<typeof UserToolResponseMessageSchema>;+export type ToolApprovalPolicyItem = z.infer<typeof ToolApprovalPolicyItemSchema>;+export type UserToolApprovalPolicyMessage = z.infer<typeof UserToolApprovalPolicyMessageSchema>;export type AgentApprovalDecisionMessage = z.infer<typeof AgentApprovalDecisionMessageSchema>;export type InputTokensBreakdown = z.infer<typeof InputTokensBreakdownSchema>;export type ModelMessageUsage = z.infer<typeof ModelMessageUsageSchema>;diff --git a/packages/trueforge-core/src/core/index.ts b/packages/trueforge-core/src/core/index.tsindex 1cff0d22d..c9056a503 100644--- a/packages/trueforge-core/src/core/index.ts+++ b/packages/trueforge-core/src/core/index.ts@@ -114,6 +114,7 @@ export {ToolResponseEventSchema,ToolResponseRequiredEventSchema,UserToolApprovalMessageSchema,+ UserToolApprovalPolicyMessageSchema,UserToolResponseMessageSchema,newEventId,} from './events/schema';@@ -124,6 +125,7 @@ export type {MCPServerInitInfo,ThreadDoneEvent,ThreadOverwriteContextEvent,+ UserToolApprovalPolicyMessage,} from './events/schema';export { CompletionUsageSchema } from './llm/LLMTypes';export type { CompletionUsage } from './llm/LLMTypes';