pythonrepl

package
v0.0.0-...-5389549 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package pythonrepl mounts a stateful Python REPL as two native Eino Agent tools. Interpreter state is isolated by durable session and workspace and is intentionally process-local: it is lost on cancellation, timeout, clear, runner failure, remount, restart, or resume in a new process.

Python runs with the host user's authority. The package is not a sandbox: Python may access files, the network, processes, and every explicitly supplied environment value. Tool input and output are durable Eino data and must not contain secrets. Output and protocol frames are bounded, but Python memory, CPU use, side effects, and intentionally detached descendants are not.

Index

Constants

View Source
const (
	// ExecuteToolName is the stateful Python execution tool.
	ExecuteToolName = "python_repl"
	// ClearToolName discards one owner's live interpreter state.
	ClearToolName = "python_repl_clear"
	// DefaultOrder is used when Options.Order is zero.
	DefaultOrder = 100

	// ExecuteStatusCompleted means the snippet completed without a Python exception.
	ExecuteStatusCompleted = "completed"
	// ExecuteStatusPythonError means the snippet raised a Python exception.
	ExecuteStatusPythonError = "python_error"
	// StateResetCanceled means caller cancellation forced a fresh interpreter.
	StateResetCanceled = "canceled"
	// StateResetTimedOut means the execution deadline forced a fresh interpreter.
	StateResetTimedOut = "timed_out"
	// StateResetCleared means an explicit clear discarded interpreter state.
	StateResetCleared = "cleared"
	// StateResetRunnerFailed means a runner failure forced a fresh interpreter.
	StateResetRunnerFailed = "runner_failed"
)

Variables

This section is empty.

Functions

func ConfigHash

func ConfigHash(options Options) (string, error)

ConfigHash returns the deterministic identity of behavior-bearing options. It intentionally excludes environment values, scope, and order.

func Mount

func Mount(ctx context.Context, registry *composition.Registry, component extension.Component, options Options) (*composition.Mount, error)

Mount validates and freezes options and atomically registers the execute and clear tools plus manager cleanup. It creates no virtual environment or Python process; those resources are provisioned lazily by the first execution.

Types

type BoundedText

type BoundedText struct {
	Text      string `json:"text"`
	Truncated bool   `json:"truncated"`
}

BoundedText is an inline text field with an explicit truncation indicator.

type ClearResult

type ClearResult struct {
	HadState   bool   `json:"had_state"`
	Generation uint64 `json:"generation"`
}

ClearResult describes whether clear invalidated live interpreter state.

type Environment

type Environment struct {
	Entries  map[string]string
	Identity string
}

Environment is the explicit environment frozen at mount. Identity is a non-secret host version and must rotate whenever any effective value changes.

func (Environment) GoString

func (environment Environment) GoString() string

GoString returns the same non-sensitive diagnostic summary as String.

func (Environment) String

func (environment Environment) String() string

String returns a diagnostic summary that excludes keys and values.

type ExecuteResult

type ExecuteResult struct {
	// Status is ExecuteStatusCompleted or ExecuteStatusPythonError.
	Status     string      `json:"status"`
	Stdout     BoundedText `json:"stdout"`
	Stderr     BoundedText `json:"stderr"`
	Result     BoundedText `json:"result"`
	Exception  BoundedText `json:"exception"`
	Generation uint64      `json:"generation"`
	StateReset bool        `json:"state_reset"`
	// StateResetReason is empty or one of the exported StateReset constants.
	StateResetReason string `json:"state_reset_reason"`
}

ExecuteResult is the bounded result of one Python request.

type Limits

type Limits struct {
	MaxSessions             int
	MaxQueuedPerSession     int
	MaxCodeBytes            int
	MaxOutputBytesPerStream int
	MaxResultBytes          int
	MaxExceptionBytes       int
	MaxEnvironmentEntries   int
	MaxEnvironmentBytes     int
	DefaultTimeout          time.Duration
	MaxTimeout              time.Duration
	VenvCreateTimeout       time.Duration
	RunnerStartTimeout      time.Duration
	TerminateGrace          time.Duration
	KillWait                time.Duration
}

Limits bounds every package-owned resource and deadline. Every field must be positive; DefaultTimeout and MaxTimeout must be whole seconds.

type Options

type Options struct {
	Scope          extension.Scope
	Order          int
	PythonPath     string
	PythonIdentity string
	TempRoot       string
	Environment    Environment
	Limits         Limits
}

Options describes one immutable Python REPL mount.

func (Options) GoString

func (options Options) GoString() string

GoString returns the same non-sensitive diagnostic summary as String.

func (Options) String

func (options Options) String() string

String returns a diagnostic summary that excludes paths and environment data.

Jump to

Keyboard shortcuts

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