Documentation
¶
Overview ¶
Package executors provides code execution capabilities for smolagents.
This implements a Go code executor that can safely execute Go code snippets while maintaining variable state between executions and providing proper error handling and security features.
Package executors - Remote execution framework for distributed agent execution
Index ¶
- func DefaultAuthorizedPackages() []string
- func GetGoStandardLibraryPackages() []string
- type ExecutionResult
- type ExecutorInterface
- type GoExecutor
- func (ge *GoExecutor) Close() error
- func (ge *GoExecutor) Execute(code string, authorizedImports []string) (interface{}, error)
- func (ge *GoExecutor) ExecuteRaw(code string, authorizedImports []string) (*ExecutionResult, error)
- func (ge *GoExecutor) ExecuteWithResult(code string) (*ExecutionResult, error)
- func (ge *GoExecutor) GetState() map[string]interface{}
- func (ge *GoExecutor) Reset() error
- func (ge *GoExecutor) SendTools(tools map[string]tools.Tool) error
- func (ge *GoExecutor) SendVariables(variables map[string]interface{}) error
- func (ge *GoExecutor) SetAuthorizedPackages(packages []string)
- func (ge *GoExecutor) SetMaxMemory(maxMemory int64)
- func (ge *GoExecutor) SetTimeout(timeout time.Duration)
- type GoExecutorWrapper
- type MockRemoteExecutionServer
- type RemoteExecutionRequest
- type RemoteExecutionResponse
- type RemoteExecutor
- type RemoteExecutorPool
- func (rep *RemoteExecutorPool) AddExecutor(language string, servers []string, options map[string]interface{})
- func (rep *RemoteExecutorPool) Execute(language, code string, options map[string]interface{}) (*ExecutionResult, error)
- func (rep *RemoteExecutorPool) GetAvailableLanguages() []string
- func (rep *RemoteExecutorPool) GetPoolStatus() map[string]map[string]interface{}
- type VariableInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAuthorizedPackages ¶
func DefaultAuthorizedPackages() []string
DefaultAuthorizedPackages returns the default list of authorized Go packages This includes the entire Go standard library for maximum flexibility
func GetGoStandardLibraryPackages ¶ added in v0.1.4
func GetGoStandardLibraryPackages() []string
GetGoStandardLibraryPackages returns a comprehensive list of Go standard library packages
Types ¶
type ExecutionResult ¶
type ExecutionResult struct {
Output interface{} `json:"output"`
Variables map[string]interface{} `json:"variables"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
Duration time.Duration `json:"duration"`
IsFinalAnswer bool `json:"is_final_answer"`
FinalAnswer interface{} `json:"final_answer,omitempty"`
Logs string `json:"logs"` // Print outputs captured during execution
}
ExecutionResult represents the result of code execution
type ExecutorInterface ¶
type ExecutorInterface interface {
Execute(language, code string, options map[string]interface{}) (*ExecutionResult, error)
}
ExecutorInterface defines the interface for code executors
type GoExecutor ¶
type GoExecutor struct {
// contains filtered or unexported fields
}
GoExecutor implements code execution for Go code snippets
func NewGoExecutor ¶
func NewGoExecutor(options ...map[string]interface{}) (*GoExecutor, error)
NewGoExecutor creates a new Go code executor
func (*GoExecutor) Execute ¶
func (ge *GoExecutor) Execute(code string, authorizedImports []string) (interface{}, error)
Execute executes Go code and returns the result
func (*GoExecutor) ExecuteRaw ¶
func (ge *GoExecutor) ExecuteRaw(code string, authorizedImports []string) (*ExecutionResult, error)
ExecuteRaw executes Go code and returns the full execution result
func (*GoExecutor) ExecuteWithResult ¶
func (ge *GoExecutor) ExecuteWithResult(code string) (*ExecutionResult, error)
ExecuteWithResult executes code and returns a structured result with final answer detection
func (*GoExecutor) GetState ¶
func (ge *GoExecutor) GetState() map[string]interface{}
GetState returns the current variable state
func (*GoExecutor) SendTools ¶
func (ge *GoExecutor) SendTools(tools map[string]tools.Tool) error
SendTools makes tools available to the executor
func (*GoExecutor) SendVariables ¶
func (ge *GoExecutor) SendVariables(variables map[string]interface{}) error
SendVariables updates the executor's variable state
func (*GoExecutor) SetAuthorizedPackages ¶
func (ge *GoExecutor) SetAuthorizedPackages(packages []string)
SetAuthorizedPackages sets the list of authorized Go packages
func (*GoExecutor) SetMaxMemory ¶
func (ge *GoExecutor) SetMaxMemory(maxMemory int64)
SetMaxMemory sets the maximum memory usage
func (*GoExecutor) SetTimeout ¶
func (ge *GoExecutor) SetTimeout(timeout time.Duration)
SetTimeout sets the execution timeout
type GoExecutorWrapper ¶
type GoExecutorWrapper struct {
// contains filtered or unexported fields
}
GoExecutorWrapper wraps GoExecutor to match the ExecutorInterface
func (*GoExecutorWrapper) Execute ¶
func (gew *GoExecutorWrapper) Execute(language, code string, options map[string]interface{}) (*ExecutionResult, error)
Execute implements ExecutorInterface for GoExecutor
type MockRemoteExecutionServer ¶
type MockRemoteExecutionServer struct {
// contains filtered or unexported fields
}
MockRemoteExecutionServer provides a simple mock server for testing
func NewMockRemoteExecutionServer ¶
func NewMockRemoteExecutionServer(port int) *MockRemoteExecutionServer
NewMockRemoteExecutionServer creates a new mock server
func (*MockRemoteExecutionServer) Start ¶
func (mrs *MockRemoteExecutionServer) Start() error
Start starts the mock server
func (*MockRemoteExecutionServer) Stop ¶
func (mrs *MockRemoteExecutionServer) Stop() error
Stop stops the mock server
type RemoteExecutionRequest ¶
type RemoteExecutionRequest struct {
ID string `json:"id"`
Language string `json:"language"`
Code string `json:"code"`
Timeout int `json:"timeout"`
Env map[string]string `json:"env,omitempty"`
Files map[string]string `json:"files,omitempty"`
}
RemoteExecutionRequest represents a request to execute code remotely
type RemoteExecutionResponse ¶
type RemoteExecutionResponse struct {
ID string `json:"id"`
Success bool `json:"success"`
Output string `json:"output"`
Error string `json:"error,omitempty"`
ExitCode int `json:"exit_code"`
Duration int64 `json:"duration_ms"`
}
RemoteExecutionResponse represents the response from remote execution
type RemoteExecutor ¶
type RemoteExecutor struct {
// contains filtered or unexported fields
}
RemoteExecutor executes code on remote execution servers
func NewRemoteExecutor ¶
func NewRemoteExecutor(servers []string, options map[string]interface{}) *RemoteExecutor
NewRemoteExecutor creates a new remote executor
func (*RemoteExecutor) Execute ¶
func (re *RemoteExecutor) Execute(language, code string, options map[string]interface{}) (*ExecutionResult, error)
Execute executes code on a remote server
func (*RemoteExecutor) GetCapabilities ¶
func (re *RemoteExecutor) GetCapabilities() map[string]interface{}
GetCapabilities returns the capabilities of the remote executor
func (*RemoteExecutor) GetHealthyServers ¶
func (re *RemoteExecutor) GetHealthyServers() []string
GetHealthyServers returns a list of healthy servers
func (*RemoteExecutor) HealthCheck ¶
func (re *RemoteExecutor) HealthCheck() map[string]bool
HealthCheck checks the health of all remote servers
type RemoteExecutorPool ¶
type RemoteExecutorPool struct {
// contains filtered or unexported fields
}
RemoteExecutorPool manages multiple remote executors for different languages
func NewRemoteExecutorPool ¶
func NewRemoteExecutorPool(config map[string]interface{}) *RemoteExecutorPool
NewRemoteExecutorPool creates a new remote executor pool
func (*RemoteExecutorPool) AddExecutor ¶
func (rep *RemoteExecutorPool) AddExecutor(language string, servers []string, options map[string]interface{})
AddExecutor adds a remote executor for a specific language
func (*RemoteExecutorPool) Execute ¶
func (rep *RemoteExecutorPool) Execute(language, code string, options map[string]interface{}) (*ExecutionResult, error)
Execute executes code using the appropriate remote executor
func (*RemoteExecutorPool) GetAvailableLanguages ¶
func (rep *RemoteExecutorPool) GetAvailableLanguages() []string
GetAvailableLanguages returns languages with configured remote executors
func (*RemoteExecutorPool) GetPoolStatus ¶
func (rep *RemoteExecutorPool) GetPoolStatus() map[string]map[string]interface{}
GetPoolStatus returns the status of all executors in the pool
type VariableInfo ¶ added in v0.1.3
type VariableInfo struct {
Name string
IsVarDecl bool // true for var declarations, false for := assignments
}
VariableInfo contains information about a variable