messagepolicy

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildConversationContext

func BuildConversationContext(messages []ConversationMessage) string

BuildConversationContext formats conversation history for the policy judge. System messages are excluded. Tool outputs are replaced with "[tool output redacted]".

Types

type ApplicablePolicy

type ApplicablePolicy struct {
	ID       string // Kubernetes resource name (e.g., "mp1-abc123")
	Manifest types.MessagePolicyManifest
}

ApplicablePolicy pairs a policy's Kubernetes resource name with its manifest.

type ConversationMessage

type ConversationMessage struct {
	Role       string // "user", "assistant", "tool", "system"
	Content    string
	ToolCalls  []ToolCallInfo
	ToolCallID string
}

ConversationMessage represents a message in conversation history for policy evaluation.

type Helper

type Helper struct {
	// contains filtered or unexported fields
}

func NewHelper

func NewHelper(ctx context.Context, backend backend.Backend, client kclient.Client, dispatcher *dispatcher.Dispatcher, gptClient *gptscript.GPTScript) (*Helper, error)

func (*Helper) EvaluateMessage

func (h *Helper) EvaluateMessage(ctx context.Context, policies []ApplicablePolicy, conversationHistory []ConversationMessage, targetMessage string, direction types.PolicyDirection) []MessagePolicyViolation

EvaluateMessage runs all applicable policies against a message in parallel. Returns a slice of violations (empty if all policies pass). Never returns an error; LLM failures are treated as violations (fail closed).

func (*Helper) GetApplicablePolicies

func (h *Helper) GetApplicablePolicies(user kuser.Info, direction types.PolicyDirection) ([]ApplicablePolicy, error)

GetApplicablePolicies returns all policies that apply to the given user and direction.

type MessagePolicyViolation

type MessagePolicyViolation struct {
	PolicyID         string
	PolicyName       string
	PolicyDefinition string
	Explanation      string
}

MessagePolicyViolation is the result when a message violates a policy. nolint:revive

type ToolCallInfo

type ToolCallInfo struct {
	Name      string
	Arguments string
}

ToolCallInfo contains the name and arguments of a tool call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL