Documentation
¶
Overview ¶
Package helpers provides utility functions for state machine operations.
Index ¶
- Variables
- func BuildSystemPrompt(tmplStr string, contextData map[string]any) (string, error)
- func ExtractContextFromState(smCtx *statemachine.Context, keys []string) map[string]any
- func FormatContextChunks(chunks []ContextChunk) string
- func FormatContextForPrompt(contextData map[string]any) string
- func HandleGracefulDegradation(err error, fallback any) (any, error)
- func IsCapabilityMissing(err error) bool
- func IsElicitationError(err error) bool
- func IsSamplingError(err error) bool
- func IsUserDeclined(err error) bool
- func LogCapabilityCheck(ctx context.Context, capability string, available bool)
- func LogElicitationAttempt(ctx context.Context, operation string, mode string, message string)
- func LogElicitationResult(ctx context.Context, operation string, action string, declined bool, err error)
- func LogGracefulDegradation(ctx context.Context, operation string, reason string, fallbackType string)
- func LogSamplingAttempt(ctx context.Context, operation string, prompt string, opts map[string]any)
- func LogSamplingResult(ctx context.Context, operation string, source string, resultLength int, ...)
- func MergeContextData(contexts ...map[string]any) map[string]any
- func TruncateToTokenLimit(content string, maxTokens int) string
- func WrapElicitationError(operation string, err error, context map[string]any) error
- func WrapSamplingError(operation string, err error, context map[string]any) error
- type ContextChunk
- type ElicitationError
- type SamplingError
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserDeclinedAction = errors.New("user declined action") ErrValidationFailed = errors.New("validation failed") ErrJSONParseFailed = errors.New("failed to parse JSON from response") ErrCapabilityCheckFailed = errors.New("capability check failed") ErrFallbackExecutionFailed = errors.New("fallback execution failed") ErrUnsupportedFallbackType = errors.New("unsupported fallback type") )
Sentinel errors for common failure modes.
Functions ¶
func BuildSystemPrompt ¶
BuildSystemPrompt builds a system prompt from a template and context data.
func ExtractContextFromState ¶
func ExtractContextFromState(smCtx *statemachine.Context, keys []string) map[string]any
ExtractContextFromState extracts multiple values from state machine context.
func FormatContextChunks ¶
func FormatContextChunks(chunks []ContextChunk) string
FormatContextChunks formats context chunks into a readable string.
func FormatContextForPrompt ¶
FormatContextForPrompt formats context data as a readable string for inclusion in prompts.
func HandleGracefulDegradation ¶
HandleGracefulDegradation handles an error with graceful fallback If the error is capability-related or user decline, returns the fallback value Otherwise, returns the error.
func IsCapabilityMissing ¶
IsCapabilityMissing checks if an error is due to missing sampling/elicitation capability.
func IsElicitationError ¶
IsElicitationError checks if an error is an elicitation error.
func IsSamplingError ¶
IsSamplingError checks if an error is a sampling error.
func IsUserDeclined ¶
IsUserDeclined checks if an error represents a user declining an action.
func LogCapabilityCheck ¶
LogCapabilityCheck logs capability checking results.
func LogElicitationAttempt ¶
LogElicitationAttempt logs an elicitation request attempt.
func LogElicitationResult ¶
func LogElicitationResult(ctx context.Context, operation string, action string, declined bool, err error)
LogElicitationResult logs an elicitation response.
func LogGracefulDegradation ¶
func LogGracefulDegradation(ctx context.Context, operation string, reason string, fallbackType string)
LogGracefulDegradation logs when a fallback is used.
func LogSamplingAttempt ¶
LogSamplingAttempt logs a sampling request attempt.
func LogSamplingResult ¶
func LogSamplingResult(ctx context.Context, operation string, source string, resultLength int, err error)
LogSamplingResult logs a sampling response.
func MergeContextData ¶
MergeContextData merges multiple context data maps, with later maps taking precedence.
func TruncateToTokenLimit ¶
TruncateToTokenLimit truncates content to approximately fit within a token limit Uses rough heuristic: 1 token ≈ 4 characters.
func WrapElicitationError ¶
WrapElicitationError wraps an error with elicitation context.
Types ¶
type ContextChunk ¶
ContextChunk represents a piece of context information.
type ElicitationError ¶
ElicitationError wraps elicitation-related errors with additional context.
func (*ElicitationError) Error ¶
func (e *ElicitationError) Error() string
func (*ElicitationError) Unwrap ¶
func (e *ElicitationError) Unwrap() error
type SamplingError ¶
SamplingError wraps sampling-related errors with additional context.
func (*SamplingError) Error ¶
func (e *SamplingError) Error() string
func (*SamplingError) Unwrap ¶
func (e *SamplingError) Unwrap() error