agentenv

package
v0.5.36-beta Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package agentenv defines the environment boundary used by Kodelet's central agent loop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentInitDecision

type AgentInitDecision struct {
	SystemPrompt  string
	AllowedTools  []string
	ToolsModified bool
}

AgentInitDecision is the effective result of environment agent.init handlers.

type CommandAction

type CommandAction string

CommandAction describes how an environment handled a slash command.

const (
	// CommandActionRespond returns a direct response without invoking the model.
	CommandActionRespond CommandAction = "respond"
	// CommandActionRunAgent replaces the submitted command with an agent prompt.
	CommandActionRunAgent CommandAction = "run_agent"
)

type CommandRequest

type CommandRequest struct {
	Message string
	RunSpec RunSpec
}

CommandRequest asks the environment to resolve a workspace or extension command.

type CommandResult

type CommandResult struct {
	Matched         bool
	Action          CommandAction
	CommandName     string
	Response        string
	Prompt          string
	Display         string
	DisplayOverride bool
	RecipeName      string
	AllowedTools    []string
	AllowedCommands []string
}

CommandResult is the normalized result of workspace command resolution.

type Environment

type Environment interface {
	Open(ctx context.Context, spec RunSpec) (Manifest, error)
	IsOpen() bool
	Manifest() Manifest
	ExecuteCommand(ctx context.Context, request CommandRequest) (CommandResult, error)
	ProcessUserMessage(ctx context.Context, message string) (string, error)
	DispatchAgentStart(ctx context.Context) error
	DispatchTurnStart(ctx context.Context, turnNumber int) error
	ProcessAgentInit(ctx context.Context, systemPrompt string, allowedTools []string) (AgentInitDecision, error)
	DispatchTurnEnd(ctx context.Context, finalOutput string, turnCount int) error
	DispatchAgentEnd(ctx context.Context, messages []llmtypes.Message) ([]string, error)
	DispatchToolCall(ctx context.Context, request ToolRequest) (ToolCallDecision, error)
	DispatchToolUpdate(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)
	DispatchToolResult(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)
	CanStreamToolUpdates() bool
	ExecuteTool(ctx context.Context, request ToolRequest, updates ToolUpdateSink) (ToolExecution, error)
	Close(ctx context.Context) error
}

Environment is the run-scoped boundary between the central agent loop and its workspace resources.

type EnvironmentConfig

type EnvironmentConfig struct {
	AllowedCommands     []string
	ToolMode            llmtypes.ToolMode
	EnableFSSearchTools bool
	SystemPromptPath    string
	SystemPromptContent string
	SystemPromptArgs    map[string]string
	SystemInformation   *llmtypes.SystemInformation
}

EnvironmentConfig is the runner-owned configuration projection pinned with a manifest.

func (*EnvironmentConfig) Clone

Clone returns a defensive copy of the configuration projection.

type ExtensionSetter

type ExtensionSetter interface {
	SetExtensions(runtime any)
}

ExtensionSetter is implemented by environments whose local extension runtime can be replaced between runs.

type LocalEnvironment

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

LocalEnvironment executes against the current process and a local tool state.

func NewLocalEnvironment

func NewLocalEnvironment(workingDirectory string, runtime *extensions.Runtime) *LocalEnvironment

NewLocalEnvironment creates an environment that builds a fresh BasicState whenever a run opens.

func NewLocalEnvironmentFromState

func NewLocalEnvironmentFromState(state tooltypes.State, runtime *extensions.Runtime) *LocalEnvironment

NewLocalEnvironmentFromState creates a compatibility environment around an existing state.

func (*LocalEnvironment) ApplyCommandResult

func (e *LocalEnvironment) ApplyCommandResult(result CommandResult)

ApplyCommandResult updates run-scoped recipe and restriction context without changing the pinned manifest.

func (*LocalEnvironment) CanStreamToolUpdates

func (e *LocalEnvironment) CanStreamToolUpdates() bool

CanStreamToolUpdates reports whether transient updates can preserve extension policy.

func (*LocalEnvironment) Close

func (e *LocalEnvironment) Close(_ context.Context) error

Close releases the pinned run snapshot. It does not own or close the persistent extension runtime.

func (*LocalEnvironment) DispatchAgentEnd

func (e *LocalEnvironment) DispatchAgentEnd(ctx context.Context, messages []llmtypes.Message) ([]string, error)

DispatchAgentEnd applies agent.end extension handlers.

func (*LocalEnvironment) DispatchAgentStart

func (e *LocalEnvironment) DispatchAgentStart(ctx context.Context) error

DispatchAgentStart applies agent.start extension handlers.

func (*LocalEnvironment) DispatchToolCall

func (e *LocalEnvironment) DispatchToolCall(ctx context.Context, request ToolRequest) (ToolCallDecision, error)

DispatchToolCall applies tool.call extension policy without executing the tool.

func (*LocalEnvironment) DispatchToolResult

func (e *LocalEnvironment) DispatchToolResult(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)

DispatchToolResult applies tool.result extension policy without executing the tool.

func (*LocalEnvironment) DispatchToolUpdate

func (e *LocalEnvironment) DispatchToolUpdate(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)

DispatchToolUpdate applies tool.update extension policy without executing the tool.

func (*LocalEnvironment) DispatchTurnEnd

func (e *LocalEnvironment) DispatchTurnEnd(ctx context.Context, finalOutput string, turnCount int) error

DispatchTurnEnd applies turn.end extension handlers.

func (*LocalEnvironment) DispatchTurnStart

func (e *LocalEnvironment) DispatchTurnStart(ctx context.Context, turnNumber int) error

DispatchTurnStart applies turn.start extension handlers.

func (*LocalEnvironment) ExecuteCommand

func (e *LocalEnvironment) ExecuteCommand(ctx context.Context, request CommandRequest) (CommandResult, error)

ExecuteCommand resolves extension commands first, then workspace recipes.

func (*LocalEnvironment) ExecuteTool

func (e *LocalEnvironment) ExecuteTool(ctx context.Context, request ToolRequest, updates ToolUpdateSink) (ToolExecution, error)

ExecuteTool executes a tool against the pinned state and applies the complete extension lifecycle.

func (*LocalEnvironment) IsOpen

func (e *LocalEnvironment) IsOpen() bool

IsOpen reports whether this environment currently has a pinned run snapshot.

func (*LocalEnvironment) Manifest

func (e *LocalEnvironment) Manifest() Manifest

Manifest returns the currently pinned manifest.

func (*LocalEnvironment) Open

func (e *LocalEnvironment) Open(ctx context.Context, spec RunSpec) (Manifest, error)

Open snapshots context, tools, commands, and extension behavior for one top-level run.

func (*LocalEnvironment) ProcessAgentInit

func (e *LocalEnvironment) ProcessAgentInit(ctx context.Context, systemPrompt string, allowedTools []string) (AgentInitDecision, error)

ProcessAgentInit applies agent.init extension handlers.

func (*LocalEnvironment) ProcessUserMessage

func (e *LocalEnvironment) ProcessUserMessage(ctx context.Context, message string) (string, error)

ProcessUserMessage applies user.message extension handlers.

func (*LocalEnvironment) SetExtensions

func (e *LocalEnvironment) SetExtensions(runtime any)

SetExtensions replaces the local extension runtime used by the next opened run.

func (*LocalEnvironment) State

func (e *LocalEnvironment) State() tooltypes.State

State returns the pinned local state used for tool execution.

type Manifest

type Manifest struct {
	WorkingDirectory string                  `json:"workingDirectory"`
	Contexts         map[string]string       `json:"contexts"`
	Tools            []ToolDefinition        `json:"tools"`
	Commands         []slashcommands.Command `json:"commands"`
	Config           *EnvironmentConfig      `json:"config,omitempty"`
}

Manifest is the immutable environment snapshot pinned to one top-level run.

func (Manifest) AvailableTools

func (m Manifest) AvailableTools() []tooltypes.Tool

AvailableTools returns the pinned model-facing tool implementations.

func (Manifest) Clone

func (m Manifest) Clone() Manifest

Clone returns a defensive copy of the manifest collections.

func (Manifest) ToolDefinition

func (m Manifest) ToolDefinition(name string) (ToolDefinition, bool)

ToolDefinition returns a pinned tool definition by name.

func (Manifest) ToolNames

func (m Manifest) ToolNames() []string

ToolNames returns the pinned model-facing tool names.

type OutcomeCloser

type OutcomeCloser interface {
	CloseWithError(ctx context.Context, runErr error) error
}

OutcomeCloser lets a remote environment record the terminal outcome of a run.

type RemoteController

type RemoteController interface {
	OpenRun(ctx context.Context, runnerID string, params protocol.RunOpenParams) (runnerpayload.Manifest, error)
	CallRun(ctx context.Context, runID, method string, params any, result any) error
	ExecuteTool(ctx context.Context, params runnerpayload.ToolExecuteParams, updates func(runnerpayload.ToolUpdateParams)) (runnerpayload.ToolExecuteResult, error)
	CancelRun(ctx context.Context, runID, reason string) error
	CloseRun(ctx context.Context, runID string, status protocol.RunStatus, runErr error) error
}

RemoteController is the control-plane runner API used by RemoteEnvironment.

type RemoteEnvironment

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

RemoteEnvironment proxies a run-scoped agent environment to one registered runner.

func NewRemoteEnvironment

func NewRemoteEnvironment(controller RemoteController, runnerID string, options ...RemoteEnvironmentOption) *RemoteEnvironment

NewRemoteEnvironment creates an unopened environment bound to one stable runner ID.

func (*RemoteEnvironment) CanStreamToolUpdates

func (e *RemoteEnvironment) CanStreamToolUpdates() bool

CanStreamToolUpdates reports the capability pinned in the active manifest.

func (*RemoteEnvironment) Close

func (e *RemoteEnvironment) Close(ctx context.Context) error

Close records a successful remote run and releases its runner lease.

func (*RemoteEnvironment) CloseWithError

func (e *RemoteEnvironment) CloseWithError(ctx context.Context, runErr error) error

CloseWithError records the terminal run outcome and releases its runner lease.

func (*RemoteEnvironment) DispatchAgentEnd

func (e *RemoteEnvironment) DispatchAgentEnd(ctx context.Context, messages []llmtypes.Message) ([]string, error)

DispatchAgentEnd applies runner-owned agent.end handlers.

func (*RemoteEnvironment) DispatchAgentStart

func (e *RemoteEnvironment) DispatchAgentStart(ctx context.Context) error

DispatchAgentStart applies runner-owned agent.start handlers.

func (*RemoteEnvironment) DispatchToolCall

func (e *RemoteEnvironment) DispatchToolCall(ctx context.Context, request ToolRequest) (ToolCallDecision, error)

DispatchToolCall proxies extension policy for a control-plane tool call.

func (*RemoteEnvironment) DispatchToolResult

func (e *RemoteEnvironment) DispatchToolResult(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)

DispatchToolResult proxies extension policy for an authoritative control-plane tool result.

func (*RemoteEnvironment) DispatchToolUpdate

func (e *RemoteEnvironment) DispatchToolUpdate(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)

DispatchToolUpdate proxies extension policy for a transient control-plane tool result.

func (*RemoteEnvironment) DispatchTurnEnd

func (e *RemoteEnvironment) DispatchTurnEnd(ctx context.Context, finalOutput string, turnCount int) error

DispatchTurnEnd applies runner-owned turn.end handlers.

func (*RemoteEnvironment) DispatchTurnStart

func (e *RemoteEnvironment) DispatchTurnStart(ctx context.Context, turnNumber int) error

DispatchTurnStart applies runner-owned turn.start handlers.

func (*RemoteEnvironment) ExecuteCommand

func (e *RemoteEnvironment) ExecuteCommand(ctx context.Context, request CommandRequest) (CommandResult, error)

ExecuteCommand proxies workspace and extension slash commands to the active runner.

func (*RemoteEnvironment) ExecuteTool

func (e *RemoteEnvironment) ExecuteTool(ctx context.Context, request ToolRequest, updates ToolUpdateSink) (ToolExecution, error)

ExecuteTool performs one complete runner-side tool lifecycle.

func (*RemoteEnvironment) IsOpen

func (e *RemoteEnvironment) IsOpen() bool

IsOpen reports whether a remote run lease is active.

func (*RemoteEnvironment) Manifest

func (e *RemoteEnvironment) Manifest() Manifest

Manifest returns the manifest pinned by run.open.

func (*RemoteEnvironment) Open

func (e *RemoteEnvironment) Open(ctx context.Context, spec RunSpec) (Manifest, error)

Open reserves runner capacity and pins the returned environment manifest.

func (*RemoteEnvironment) ProcessAgentInit

func (e *RemoteEnvironment) ProcessAgentInit(ctx context.Context, systemPrompt string, allowedTools []string) (AgentInitDecision, error)

ProcessAgentInit applies runner-owned system prompt and tool-list patches.

func (*RemoteEnvironment) ProcessUserMessage

func (e *RemoteEnvironment) ProcessUserMessage(ctx context.Context, message string) (string, error)

ProcessUserMessage applies runner-owned user.message handlers.

func (*RemoteEnvironment) RunID

func (e *RemoteEnvironment) RunID() string

RunID returns the active opaque control-plane run ID.

type RemoteEnvironmentOption

type RemoteEnvironmentOption func(*RemoteEnvironment)

RemoteEnvironmentOption configures a remote runner environment.

func WithRemoteClientCapabilities

func WithRemoteClientCapabilities(capabilities protocol.ClientCapabilities) RemoteEnvironmentOption

WithRemoteClientCapabilities advertises the client UI attached to remote runs.

func WithRemoteRunIDGenerator

func WithRemoteRunIDGenerator(generate func() (string, error)) RemoteEnvironmentOption

WithRemoteRunIDGenerator overrides opaque run ID generation, primarily for tests.

type RunSpec

type RunSpec struct {
	ConversationID     string
	EnvironmentProfile string
	Config             llmtypes.Config
	Metadata           map[string]any
	InvokedBy          string
}

RunSpec describes the central run opening this environment.

func (RunSpec) Clone

func (s RunSpec) Clone() RunSpec

Clone returns a copy safe for retention by an environment implementation.

type StateProvider

type StateProvider interface {
	State() tooltypes.State
}

StateProvider is implemented by local environments that expose their pinned tool state for compatibility. Provider loops must use Environment methods rather than depending on this optional interface.

type ToolCallDecision

type ToolCallDecision struct {
	Blocked bool
	Reason  string
	Input   string
}

ToolCallDecision is the effective pre-execution extension policy result.

type ToolDefinition

type ToolDefinition struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"inputSchema"`
	Placement   ToolPlacement  `json:"placement"`
	Tool        tooltypes.Tool `json:"-"`
}

ToolDefinition is one model-facing tool and its execution placement.

type ToolExecution

type ToolExecution struct {
	Input            string
	Result           tooltypes.ToolResult
	StructuredResult tooltypes.StructuredToolResult
	Modified         bool
}

ToolExecution is the environment's authoritative result for one host tool call.

type ToolOutputDecision

type ToolOutputDecision struct {
	StructuredResult tooltypes.StructuredToolResult
	Modified         bool
	Accepted         bool
}

ToolOutputDecision is the effective post-policy tool output.

type ToolOutputRequest

type ToolOutputRequest struct {
	Name             string
	Input            string
	ToolCallID       string
	StructuredResult tooltypes.StructuredToolResult
}

ToolOutputRequest describes a transient or final structured tool output.

type ToolPlacement

type ToolPlacement string

ToolPlacement identifies where a host-executed tool runs.

const (
	// ToolPlacementControlPlane identifies tools that execute beside central conversation state.
	ToolPlacementControlPlane ToolPlacement = "control_plane"
	// ToolPlacementEnvironment identifies tools that execute in the workspace environment.
	ToolPlacementEnvironment ToolPlacement = "environment"
)

type ToolRequest

type ToolRequest struct {
	Name       string
	Input      string
	ToolCallID string
}

ToolRequest describes one model-requested host tool execution.

type ToolUpdate

type ToolUpdate struct {
	Result           tooltypes.ToolResult
	StructuredResult tooltypes.StructuredToolResult
	Modified         bool
}

ToolUpdate is one transient post-policy tool result snapshot.

type ToolUpdateSink

type ToolUpdateSink func(ToolUpdate)

ToolUpdateSink receives transient tool result snapshots.

Jump to

Keyboard shortcuts

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