kitsetup

package
v0.142.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package kitsetup contains agent creation logic used by both the CLI binary and the SDK's kit.New(). It is internal — external SDK consumers should use kit.New() which delegates here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildProviderConfig

func BuildProviderConfig(v *viper.Viper) (*models.ProviderConfig, string, error)

BuildProviderConfig creates a *models.ProviderConfig from the supplied viper store (or the process-global store when v is nil). All entry points (root, script, SDK) converge through this function.

Generation parameter pointers (Temperature, TopP, etc.) are only set when the user has explicitly configured them via CLI flag, environment variable, or global config file. This allows per-model defaults from modelSettings and customModels to fill in unset parameters downstream.

Types

type AgentSetupOptions

type AgentSetupOptions struct {
	// MCPConfig is the MCP server configuration. Required.
	MCPConfig *config.Config
	// ShowSpinner shows a loading spinner for Ollama models.
	ShowSpinner bool
	// SpinnerFunc provides the spinner implementation (nil = no spinner).
	SpinnerFunc agent.SpinnerFunc
	// UseBufferedLogger captures debug messages for later display (root
	// non-interactive path). When false a simple logger is used instead.
	UseBufferedLogger bool
	// Quiet suppresses output. Replaces the cmd package's quietFlag variable.
	Quiet bool
	// CoreTools overrides the default core tool set. If empty, CoreToolList
	// is used. Allows SDK users to pass custom tools (e.g. with WithWorkDir).
	CoreTools []fantasy.AgentTool
	// CoreToolList lists core tool names to add. Overridden by CoreTools.
	// If both CoreToolList is true and CoreTools is empty, the agent
	// will have no tools (useful for simple chat completions).
	CoreToolList []string
	// ExtraTools are additional tools added alongside core, MCP, and extension
	// tools. They do not replace the defaults — they extend them.
	ExtraTools []fantasy.AgentTool
	// NamedAgents lists discovered named agent definitions to advertise in
	// the subagent tool description.
	NamedAgents []core.NamedAgentSpec
	// ShellTimeout sets the default per-call timeout (seconds) for the shell
	// tool. Zero uses the built-in default (120s).
	ShellTimeout int
	// ShellMaxTimeout caps the maximum timeout (seconds) a shell tool call may
	// request. Zero uses the built-in default (600s).
	ShellMaxTimeout int
	// ImageMaxEdge caps the width and height, in pixels, of an image the read
	// tool attaches to a message. Zero uses the built-in default.
	ImageMaxEdge int
	// ImageMaxBytes caps the encoded size, in bytes, of an image the read tool
	// attaches to a message. Zero uses the built-in default.
	ImageMaxBytes int
	// ImageNoResize makes the read tool reject an oversized image instead of
	// scaling it down.
	ImageNoResize bool
	// Shell is the argument vector prefix the shell tool runs a command
	// string through. Empty uses the built-in default ["bash"].
	Shell []string
	// WorkDir is the base directory for the core file and shell tools.
	// Empty uses the process working directory.
	WorkDir string
	// CoreToolOptions are extra options for the built-in core tools.
	CoreToolOptions []core.ToolOption
	// ToolWrapper is an optional function that wraps tools after extension
	// wrapping. Used by the SDK hook system. Both wrappers compose:
	// extension wrapper runs first (inner), then this wrapper (outer).
	ToolWrapper func([]fantasy.AgentTool) []fantasy.AgentTool

	// ProviderConfig, when non-nil, is used directly instead of calling
	// BuildProviderConfig(). Callers (e.g. Kit.New) pre-build this from their
	// per-instance config store and pass it here, so the slow agent/MCP
	// initialisation can run without further config reads.
	ProviderConfig *models.ProviderConfig
	// Debug enables debug logging. When zero-value, viper is consulted.
	// Only meaningful when ProviderConfig is also set.
	Debug bool
	// DebugLogger, if non-nil, is used directly as the engine/MCP debug
	// logger — overriding the built-in SimpleDebugLogger / BufferedDebugLogger
	// selected by Debug + UseBufferedLogger. Callers supply this when they
	// want to route debug output into their own logging system.
	DebugLogger tools.DebugLogger
	// NoExtensions skips extension loading. When false, viper is consulted.
	// Only meaningful when ProviderConfig is also set.
	NoExtensions bool
	// AllowMissingCredentials lets agent creation succeed when the provider
	// cannot be created (no credentials, a failed OAuth token refresh, an
	// unsupported provider, and so on); the agent then reports the error via
	// ProviderError until a working model is installed with SetModel. A
	// malformed model string is still fatal.
	AllowMissingCredentials bool
	// Bare restricts extension loading to paths named explicitly via
	// --extension / -e. No system, user or project directory is scanned.
	Bare bool
	// MaxSteps overrides the agent step limit. 0 means use viper value.
	// Only meaningful when ProviderConfig is also set.
	MaxSteps int
	// StreamingEnabled controls streaming. Only meaningful when ProviderConfig
	// is also set.
	StreamingEnabled bool
	// RetryPolicy limits retries per model request. Nil uses defaults.
	RetryPolicy *agent.RetryPolicy
	// AuthHandler handles OAuth authorization for remote MCP servers.
	// When set, remote transports are configured with OAuth support.
	AuthHandler tools.MCPAuthHandler
	// TokenStoreFactory, if non-nil, creates a custom token store for each
	// remote MCP server's OAuth tokens. When nil, the default file-based
	// token store is used.
	TokenStoreFactory tools.TokenStoreFactory
	// OnMCPServerLoaded, if non-nil, is called when each MCP server finishes
	// loading (successfully or with error). Called from the background goroutine.
	OnMCPServerLoaded func(serverName string, toolCount int, err error)
	// MCPTaskConfig configures task-augmented tools/call execution. The
	// zero value preserves historical synchronous-only behaviour.
	MCPTaskConfig tools.MCPTaskConfig
	// Viper is the per-instance configuration store. When set, it is used for
	// any fallback config reads (debug, no-extensions, max-steps, stream,
	// extension paths) and is attached to the extension runner. When nil, the
	// process-global viper store is used.
	Viper *viper.Viper
}

AgentSetupOptions configures agent creation.

type AgentSetupResult

type AgentSetupResult struct {
	Agent          *agent.Agent
	BufferedLogger *tools.BufferedDebugLogger
	// ExtRunner is the extension runner (nil when --no-extensions or no
	// extensions were discovered).
	ExtRunner *extensions.Runner
}

AgentSetupResult bundles the created agent and any debug logger so the caller can flush buffered messages when appropriate.

func SetupAgent

func SetupAgent(ctx context.Context, opts AgentSetupOptions) (*AgentSetupResult, error)

SetupAgent creates an agent from the current viper state + the provided options. It wraps BuildProviderConfig and agent.CreateAgent.

Jump to

Keyboard shortcuts

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