utils

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package utils provides utility functions and error types for the smolagents library.

This includes error handling, text processing, code parsing, and various helper functions used throughout the agent system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanWhitespace

func CleanWhitespace(text string) string

CleanWhitespace removes excessive whitespace from text

func ContainsAny

func ContainsAny(text string, substrings []string) bool

ContainsAny checks if a string contains any of the given substrings

func ExtractCodeFromText

func ExtractCodeFromText(text string) string

ExtractCodeFromText extracts the first code block from text

func ExtractVariableName

func ExtractVariableName(text string) string

ExtractVariableName extracts a valid variable name from a string

func FilterMap

func FilterMap(data map[string]interface{}, predicate func(string, interface{}) bool) map[string]interface{}

FilterMap filters a map based on a predicate function

func FormatErrorContext

func FormatErrorContext(err error, context map[string]interface{}) string

FormatErrorContext formats an error with context information

func IsValidName

func IsValidName(name string) bool

IsValidName checks if a string is a valid Go identifier

func JoinLines

func JoinLines(lines []string) string

JoinLines joins lines with the system's line separator

func MakeJSONSerializable

func MakeJSONSerializable(obj interface{}) interface{}

MakeJSONSerializable converts an object to a JSON-serializable format

func MergeStringMaps

func MergeStringMaps(maps ...map[string]string) map[string]string

MergeStringMaps merges multiple string maps, with later maps taking precedence

func SafeStringConversion

func SafeStringConversion(value interface{}) string

SafeStringConversion safely converts an interface{} to string

func SanitizeForLogging

func SanitizeForLogging(content string) string

SanitizeForLogging sanitizes content for safe logging (removes sensitive data patterns)

func StringToLines

func StringToLines(text string) []string

StringToLines splits a string into lines, handling different line endings

func TruncateContent

func TruncateContent(content string, maxLength int) string

TruncateContent truncates content to a maximum length with ellipsis

func ValidateMapKeys

func ValidateMapKeys(data map[string]interface{}, required []string) error

ValidateMapKeys checks if all required keys are present in a map

Types

type AgentError

type AgentError struct {
	Message string
	Cause   error
}

AgentError is the base error type for all agent-related errors

func NewAgentError

func NewAgentError(message string, cause ...error) *AgentError

NewAgentError creates a new AgentError

func (*AgentError) Error

func (e *AgentError) Error() string

func (*AgentError) Unwrap

func (e *AgentError) Unwrap() error

type AgentExecutionError

type AgentExecutionError struct {
	*AgentError
}

AgentExecutionError represents errors during agent execution

func NewAgentExecutionError

func NewAgentExecutionError(message string, cause ...error) *AgentExecutionError

NewAgentExecutionError creates a new AgentExecutionError

type AgentGenerationError

type AgentGenerationError struct {
	*AgentError
}

AgentGenerationError represents errors during model generation

func NewAgentGenerationError

func NewAgentGenerationError(message string, cause ...error) *AgentGenerationError

NewAgentGenerationError creates a new AgentGenerationError

type AgentMaxStepsError

type AgentMaxStepsError struct {
	*AgentError
}

AgentMaxStepsError represents errors when max steps are exceeded

func NewAgentMaxStepsError

func NewAgentMaxStepsError(message string, cause ...error) *AgentMaxStepsError

NewAgentMaxStepsError creates a new AgentMaxStepsError

type AgentParsingError

type AgentParsingError struct {
	*AgentError
}

AgentParsingError represents errors during parsing operations

func NewAgentParsingError

func NewAgentParsingError(message string, cause ...error) *AgentParsingError

NewAgentParsingError creates a new AgentParsingError

type AgentToolCallError

type AgentToolCallError struct {
	*AgentExecutionError
}

AgentToolCallError represents errors during tool calls

func NewAgentToolCallError

func NewAgentToolCallError(message string, cause ...error) *AgentToolCallError

NewAgentToolCallError creates a new AgentToolCallError

type AgentToolExecutionError

type AgentToolExecutionError struct {
	*AgentExecutionError
}

AgentToolExecutionError represents errors during tool execution

func NewAgentToolExecutionError

func NewAgentToolExecutionError(message string, cause ...error) *AgentToolExecutionError

NewAgentToolExecutionError creates a new AgentToolExecutionError

type CodeBlock

type CodeBlock struct {
	Language string `json:"language"`
	Code     string `json:"code"`
}

CodeBlock represents a parsed code block

func ParseCodeBlobs

func ParseCodeBlobs(text string) []CodeBlock

ParseCodeBlobs extracts code blocks from text, supporting various formats

Jump to

Keyboard shortcuts

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