agent

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name             string `json:"name"`
	Reason           string `json:"reason"`
	Command          string `json:"command"`
	ModifiesResource string `json:"modifies_resource"`
}

type Agent

type Agent struct {
	// Input is the channel to receive user input.
	Input chan any

	// Output is the channel to send messages to the UI.
	Output chan any

	// RunOnce indicates if the agent should run only once.
	// If true, the agent will run only once and then exit.
	// If false, the agent will run in a loop until the context is done.
	RunOnce bool

	// CloseOutputOnDone closes Output and exits the agent loop when the agent reaches Done.
	// This is useful for "one prompt -> multi-step -> stream -> end" workflows that still
	// need interactive permission prompts (WaitingForInput).
	CloseOutputOnDone bool

	// InitialQuery is the initial query to the agent.
	// If provided, the agent will run only once and then exit.
	InitialQuery string

	// HostInfo is an optional, short host/environment summary injected into the
	// system prompt (e.g. OS distro, package manager). It MUST NOT contain secrets.
	HostInfo string

	LLM gollm.Client

	// PromptTemplateFile allows specifying a custom template file
	PromptTemplateFile string
	// ExtraPromptPaths allows specifying additional prompt templates
	// to be combined with PromptTemplateFile
	ExtraPromptPaths []string
	Model            string
	Provider         string

	RemoveWorkDir bool

	MaxIterations int

	// Kubeconfig is the path to the kubeconfig file.
	Kubeconfig string
	// Sandbox indicates whether to execute tools in a sandbox environment
	Sandbox string

	// SandboxImage is the container image to use for the sandbox
	SandboxImage string

	SkipPermissions bool

	Tools tools.Tools

	EnableToolUseShim bool

	// MCPClientEnabled indicates whether MCP client mode is enabled
	MCPClientEnabled bool

	// Recorder captures events for diagnostics
	Recorder journal.Recorder

	// Session optionally provides a session to use.
	// This is used by the UI to track the state of the agent and the conversation.
	Session *api.Session

	// ChatMessageStore is the underlying session persistence layer.
	ChatMessageStore api.ChatMessageStore

	// SessionBackend is the configured backend for session persistence (e.g., memory, filesystem).
	SessionBackend string
	// contains filtered or unexported fields
}

func (*Agent) AgentState

func (c *Agent) AgentState() api.AgentState

func (*Agent) CancelCurrentOperation added in v1.1.1

func (c *Agent) CancelCurrentOperation() bool

CancelCurrentOperation requests cancellation of the currently running LLM/tool operation. It returns true if there was an in-flight operation to cancel.

func (*Agent) Close

func (c *Agent) Close() error

func (*Agent) CloseMCPClient

func (a *Agent) CloseMCPClient() error

CloseMCPClient closes the MCP client connections

func (*Agent) DispatchToolCalls

func (c *Agent) DispatchToolCalls(ctx context.Context) error

func (*Agent) GetMCPStatusText

func (a *Agent) GetMCPStatusText() string

GetMCPStatusText returns a formatted text representation of the MCP status This can be used by UIs that want to display the status as text

func (*Agent) GetSession

func (s *Agent) GetSession() *api.Session

func (*Agent) Init

func (s *Agent) Init(ctx context.Context) error

func (*Agent) InitializeMCPClient

func (a *Agent) InitializeMCPClient(ctx context.Context) error

InitializeMCPClient initializes MCP client functionality for the agent. It connects to servers and registers discovered tools with the kubectl-qyai tool system.

func (*Agent) LastErr

func (c *Agent) LastErr() error

func (*Agent) LoadSession

func (c *Agent) LoadSession(sessionID string) error

LoadSession loads a session by ID (or latest), updates the agent's state, and re-initializes the chat.

func (*Agent) NewSession

func (c *Agent) NewSession() (string, error)

func (*Agent) Run

func (c *Agent) Run(ctx context.Context, initialQuery string) error

func (*Agent) SaveSession

func (c *Agent) SaveSession() (string, error)

func (*Agent) UpdateMCPStatus

func (a *Agent) UpdateMCPStatus(ctx context.Context, mcpClientEnabled bool) error

UpdateMCPStatus updates the MCP status in the agent's session

type AgentManager

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

AgentManager manages the lifecycle of agents and their sessions.

func NewAgentManager

func NewAgentManager(factory Factory, sessionManager *sessions.SessionManager) *AgentManager

NewAgentManager creates a new Manager.

func (*AgentManager) Close

func (sm *AgentManager) Close() error

Close closes all active agents.

func (*AgentManager) DeleteSession

func (sm *AgentManager) DeleteSession(id string) error

DeleteSession delegates to the underlying store and closes the active agent if any.

func (*AgentManager) FindSessionByID

func (sm *AgentManager) FindSessionByID(id string) (*api.Session, error)

FindSessionByID delegates to the underlying store.

func (*AgentManager) GetAgent

func (sm *AgentManager) GetAgent(ctx context.Context, sessionID string) (*Agent, error)

GetAgent returns the agent for the given session ID, loading it if necessary.

func (*AgentManager) ListSessions

func (sm *AgentManager) ListSessions() ([]*api.Session, error)

ListSessions delegates to the underlying store.

func (*AgentManager) SetAgentCreatedCallback

func (sm *AgentManager) SetAgentCreatedCallback(cb func(*Agent))

SetAgentCreatedCallback sets the callback to be called when a new agent is created. It also calls the callback immediately for all currently active agents.

func (*AgentManager) UpdateLastAccessed

func (sm *AgentManager) UpdateLastAccessed(session *api.Session) error

UpdateLastAccessed delegates to the underlying store.

type Factory

type Factory func(context.Context) (*Agent, error)

Factory is a function that creates a new Agent instance.

type PromptData

type PromptData struct {
	Query string
	Tools tools.Tools

	EnableToolUseShim    bool
	SessionIsInteractive bool
	HostInfo             string
}

PromptData represents the structure of the data to be filled into the template.

func (*PromptData) ToolNames

func (a *PromptData) ToolNames() string

func (*PromptData) ToolsAsJSON

func (a *PromptData) ToolsAsJSON() string

type ReActResponse

type ReActResponse struct {
	Thought string  `json:"thought"`
	Answer  string  `json:"answer,omitempty"`
	Action  *Action `json:"action,omitempty"`
}

type ShimCandidate

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

func (*ShimCandidate) Parts

func (c *ShimCandidate) Parts() []gollm.Part

func (*ShimCandidate) String

func (c *ShimCandidate) String() string

type ShimPart

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

func (*ShimPart) AsFunctionCalls

func (p *ShimPart) AsFunctionCalls() ([]gollm.FunctionCall, bool)

func (*ShimPart) AsText

func (p *ShimPart) AsText() (string, bool)

type ShimResponse

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

func (*ShimResponse) Candidates

func (r *ShimResponse) Candidates() []gollm.Candidate

func (*ShimResponse) UsageMetadata

func (r *ShimResponse) UsageMetadata() any

type ToolCallAnalysis

type ToolCallAnalysis struct {
	FunctionCall        gollm.FunctionCall
	ParsedToolCall      *tools.ToolCall
	IsInteractive       bool
	IsInteractiveError  error
	ModifiesResourceStr string
	RequiresApproval    bool
	SafetyErr           *safety.SafetyError
}

Source Files

  • conversation.go
  • manager.go
  • mcp_client.go

Jump to

Keyboard shortcuts

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