Documentation
¶
Overview ¶
Package agentenv defines the environment boundary used by Kodelet's central agent loop.
Index ¶
- type AgentInitDecision
- type CommandAction
- type CommandRequest
- type CommandResult
- type Environment
- type EnvironmentConfig
- type ExtensionSetter
- type LocalEnvironment
- func (e *LocalEnvironment) ApplyCommandResult(result CommandResult)
- func (e *LocalEnvironment) CanStreamToolUpdates() bool
- func (e *LocalEnvironment) Close(_ context.Context) error
- func (e *LocalEnvironment) DispatchAgentEnd(ctx context.Context, messages []llmtypes.Message) ([]string, error)
- func (e *LocalEnvironment) DispatchAgentStart(ctx context.Context) error
- func (e *LocalEnvironment) DispatchToolCall(ctx context.Context, request ToolRequest) (ToolCallDecision, error)
- func (e *LocalEnvironment) DispatchToolResult(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)
- func (e *LocalEnvironment) DispatchToolUpdate(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)
- func (e *LocalEnvironment) DispatchTurnEnd(ctx context.Context, finalOutput string, turnCount int) error
- func (e *LocalEnvironment) DispatchTurnStart(ctx context.Context, turnNumber int) error
- func (e *LocalEnvironment) ExecuteCommand(ctx context.Context, request CommandRequest) (CommandResult, error)
- func (e *LocalEnvironment) ExecuteTool(ctx context.Context, request ToolRequest, updates ToolUpdateSink) (ToolExecution, error)
- func (e *LocalEnvironment) IsOpen() bool
- func (e *LocalEnvironment) Manifest() Manifest
- func (e *LocalEnvironment) Open(ctx context.Context, spec RunSpec) (Manifest, error)
- func (e *LocalEnvironment) ProcessAgentInit(ctx context.Context, systemPrompt string, allowedTools []string) (AgentInitDecision, error)
- func (e *LocalEnvironment) ProcessUserMessage(ctx context.Context, message string) (string, error)
- func (e *LocalEnvironment) SetExtensions(runtime any)
- func (e *LocalEnvironment) State() tooltypes.State
- type Manifest
- type OutcomeCloser
- type RemoteController
- type RemoteEnvironment
- func (e *RemoteEnvironment) CanStreamToolUpdates() bool
- func (e *RemoteEnvironment) Close(ctx context.Context) error
- func (e *RemoteEnvironment) CloseWithError(ctx context.Context, runErr error) error
- func (e *RemoteEnvironment) DispatchAgentEnd(ctx context.Context, messages []llmtypes.Message) ([]string, error)
- func (e *RemoteEnvironment) DispatchAgentStart(ctx context.Context) error
- func (e *RemoteEnvironment) DispatchToolCall(ctx context.Context, request ToolRequest) (ToolCallDecision, error)
- func (e *RemoteEnvironment) DispatchToolResult(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)
- func (e *RemoteEnvironment) DispatchToolUpdate(ctx context.Context, request ToolOutputRequest) (ToolOutputDecision, error)
- func (e *RemoteEnvironment) DispatchTurnEnd(ctx context.Context, finalOutput string, turnCount int) error
- func (e *RemoteEnvironment) DispatchTurnStart(ctx context.Context, turnNumber int) error
- func (e *RemoteEnvironment) ExecuteCommand(ctx context.Context, request CommandRequest) (CommandResult, error)
- func (e *RemoteEnvironment) ExecuteTool(ctx context.Context, request ToolRequest, updates ToolUpdateSink) (ToolExecution, error)
- func (e *RemoteEnvironment) IsOpen() bool
- func (e *RemoteEnvironment) Manifest() Manifest
- func (e *RemoteEnvironment) Open(ctx context.Context, spec RunSpec) (Manifest, error)
- func (e *RemoteEnvironment) ProcessAgentInit(ctx context.Context, systemPrompt string, allowedTools []string) (AgentInitDecision, error)
- func (e *RemoteEnvironment) ProcessUserMessage(ctx context.Context, message string) (string, error)
- func (e *RemoteEnvironment) RunID() string
- type RemoteEnvironmentOption
- type RunSpec
- type StateProvider
- type ToolCallDecision
- type ToolDefinition
- type ToolExecution
- type ToolOutputDecision
- type ToolOutputRequest
- type ToolPlacement
- type ToolRequest
- type ToolUpdate
- type ToolUpdateSink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentInitDecision ¶
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 ¶
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 ¶
func (c *EnvironmentConfig) Clone() *EnvironmentConfig
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 ¶
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 ¶
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 ¶
AvailableTools returns the pinned model-facing tool implementations.
func (Manifest) ToolDefinition ¶
func (m Manifest) ToolDefinition(name string) (ToolDefinition, bool)
ToolDefinition returns a pinned tool definition by name.
type OutcomeCloser ¶
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 ¶
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 ¶
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.
type StateProvider ¶
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 ¶
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 ¶
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.