engine

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const AbortedSuffix = "\n\nABORTED BY USER"
View Source
const DaemonInstanceEnvVar = "GPTSCRIPT_DAEMON_INSTANCE"

DaemonInstanceEnvVar, when present in a daemon tool's environment, scopes the cached daemon to that value in addition to the tool ID. Callers that run multiple instances of the same daemon tool with per-instance configuration set it (e.g. to an instance UID) so each instance gets its own daemon process instead of silently sharing the first one that started.

View Source
const DaemonURLSuffix = ".daemon.gptscript.local"

Variables

This section is empty.

Functions

func CloseDaemons

func CloseDaemons()

func IsChatFinishMessage

func IsChatFinishMessage(msg string) error

func IsDaemonRunning

func IsDaemonRunning(url string) bool

func SetPorts

func SetPorts(start, end int64)

func StopDaemon

func StopDaemon(url string)

func WithToolCategory

func WithToolCategory(ctx context.Context, toolCategory ToolCategory) context.Context

Types

type Call

type Call struct {
	Missing bool   `json:"missing,omitempty"`
	ToolID  string `json:"toolID,omitempty"`
	Input   string `json:"input,omitempty"`
}

type CallContext

type CallContext struct {
	ToolName    string `json:"toolName,omitempty"`
	ParentID    string `json:"parentID,omitempty"`
	DisplayText string `json:"displayText,omitempty"`
	// contains filtered or unexported fields
}

type CallResult

type CallResult struct {
	ToolID string `json:"toolID,omitempty"`
	CallID string `json:"callID,omitempty"`
	Result string `json:"result,omitempty"`
	User   string `json:"user,omitempty"`
}

type ChatHistory

type ChatHistory struct {
	History []ChatHistoryCall `json:"history,omitempty"`
}

type ChatHistoryCall

type ChatHistoryCall struct {
	ID         string                  `json:"id,omitempty"`
	Tool       types.Tool              `json:"tool,omitempty"`
	Completion types.CompletionRequest `json:"completion,omitempty"`
}

type Context

type Context struct {
	Ctx           context.Context
	Parent        *Context
	LastReturn    *Return
	CurrentReturn *Return
	Engine        *Engine
	Program       *types.Program
	// Input is saved only so that we can render display text, don't use otherwise
	Input string
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) (*Context, bool)

func NewContext

func NewContext(ctx context.Context, prg *types.Program, input string, userCancel <-chan struct{}) (Context, error)

func (*Context) CurrentAgent

func (c *Context) CurrentAgent() types.ToolReference

func (*Context) GetCallContext

func (c *Context) GetCallContext() *CallContext

func (*Context) MarshalJSON

func (c *Context) MarshalJSON() ([]byte, error)

func (*Context) OnUserCancel

func (c *Context) OnUserCancel(ctx context.Context, cancel func())

func (*Context) ParentID

func (c *Context) ParentID() string

func (*Context) SubCallContext

func (c *Context) SubCallContext(ctx context.Context, input, toolID, callID string, toolCategory ToolCategory) (Context, error)

func (*Context) UnmarshalJSON

func (c *Context) UnmarshalJSON([]byte) error

func (*Context) WrappedContext

func (c *Context) WrappedContext(e *Engine) context.Context

type Engine

type Engine struct {
	Model          Model
	RuntimeManager RuntimeManager
	Env            []string
	Progress       chan<- types.CompletionStatus
	MCPRunner      MCPRunner
}

func (*Engine) Continue

func (e *Engine) Continue(ctx Context, state *State, results ...CallResult) (ret *Return, _ error)

func (*Engine) Start

func (e *Engine) Start(ctx Context, input string) (ret *Return, err error)

type ErrChatFinish

type ErrChatFinish struct {
	Message string
}

func (*ErrChatFinish) Error

func (e *ErrChatFinish) Error() string

type InputContext

type InputContext struct {
	ToolID  string `json:"toolID,omitempty"`
	Content string `json:"content,omitempty"`
}

type MCPRunner

type MCPRunner interface {
	Run(ctx Context, progress chan<- types.CompletionStatus, tool types.Tool, input string) (string, error)
}

type Model

type Model interface {
	Call(ctx context.Context, messageRequest types.CompletionRequest, env []string, status chan<- types.CompletionStatus) (*types.CompletionMessage, error)
	ProxyInfo([]string) (string, string, error)
}

type Ports

type Ports struct {
	// contains filtered or unexported fields
}

type Return

type Return struct {
	State  *State          `json:"state,omitempty"`
	Calls  map[string]Call `json:"calls,omitempty"`
	Result *string         `json:"result,omitempty"`
}

type RuntimeManager

type RuntimeManager interface {
	GetContext(ctx context.Context, tool types.Tool, cmd, env []string) (string, []string, error)
}

type State

type State struct {
	Input      string                              `json:"input,omitempty"`
	Completion types.CompletionRequest             `json:"completion,omitempty"`
	Pending    map[string]types.CompletionToolCall `json:"pending,omitempty"`
	Results    map[string]CallResult               `json:"results,omitempty"`
}

type StreamedBody

type StreamedBody struct {
	// contains filtered or unexported fields
}

StreamedBody is the request body of an HTTP tool call, read from a stream rather than taken from the tool's input. A tool's input is a string that is copied several times on its way to the request (into the environment, into the body), so content too large to hold in memory several times over can only be sent this way.

func WithStreamedBody

func WithStreamedBody(ctx context.Context, toolID, contentType string, r io.Reader) (context.Context, *StreamedBody)

WithStreamedBody returns a context in which the HTTP tool with ID toolID sends r as its request body, with the given content type, in place of the body it would build from its input. Everything else about the call is unchanged. r is sent at most once: a second call of that tool in the same context fails rather than sending an empty body.

func (*StreamedBody) Sent

func (b *StreamedBody) Sent() bool

Sent reports whether the body was sent and the tool's server answered. A run that never called the tool, such as one whose tool is not an HTTP tool, returns without error and leaves this false.

type ToolCategory

type ToolCategory string
const (
	ProviderToolCategory   ToolCategory = "provider"
	CredentialToolCategory ToolCategory = "credential"
	ContextToolCategory    ToolCategory = "context"
	InputToolCategory      ToolCategory = "input"
	OutputToolCategory     ToolCategory = "output"
	NoCategory             ToolCategory = ""
)

func ToolCategoryFromContext

func ToolCategoryFromContext(ctx context.Context) ToolCategory

Jump to

Keyboard shortcuts

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