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 ¶
- func CleanWhitespace(text string) string
- func ContainsAny(text string, substrings []string) bool
- func ExtractCodeFromText(text string) string
- func ExtractVariableName(text string) string
- func FilterMap(data map[string]interface{}, predicate func(string, interface{}) bool) map[string]interface{}
- func FormatErrorContext(err error, context map[string]interface{}) string
- func IsValidName(name string) bool
- func JoinLines(lines []string) string
- func MakeJSONSerializable(obj interface{}) interface{}
- func MergeStringMaps(maps ...map[string]string) map[string]string
- func SafeStringConversion(value interface{}) string
- func SanitizeForLogging(content string) string
- func StringToLines(text string) []string
- func TruncateContent(content string, maxLength int) string
- func ValidateMapKeys(data map[string]interface{}, required []string) error
- type AgentError
- type AgentExecutionError
- type AgentGenerationError
- type AgentMaxStepsError
- type AgentParsingError
- type AgentToolCallError
- type AgentToolExecutionError
- type CodeBlock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanWhitespace ¶
CleanWhitespace removes excessive whitespace from text
func ContainsAny ¶
ContainsAny checks if a string contains any of the given substrings
func ExtractCodeFromText ¶
ExtractCodeFromText extracts the first code block from text
func ExtractVariableName ¶
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 ¶
FormatErrorContext formats an error with context information
func IsValidName ¶
IsValidName checks if a string is a valid Go identifier
func MakeJSONSerializable ¶
func MakeJSONSerializable(obj interface{}) interface{}
MakeJSONSerializable converts an object to a JSON-serializable format
func MergeStringMaps ¶
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 ¶
SanitizeForLogging sanitizes content for safe logging (removes sensitive data patterns)
func StringToLines ¶
StringToLines splits a string into lines, handling different line endings
func TruncateContent ¶
TruncateContent truncates content to a maximum length with ellipsis
func ValidateMapKeys ¶
ValidateMapKeys checks if all required keys are present in a map
Types ¶
type AgentError ¶
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