agent

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package agent contains yai's core (non-UI) logic.

It resolves the model/provider configuration, prepares the request (including MCP tools), and starts a streaming completion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyProxyConfig

func ApplyProxyConfig(httpProxy string, providerCfg *fantasybridge.Config) error

ApplyProxyConfig configures the provider HTTP client to use an HTTP proxy.

func NewFantasyClient

func NewFantasyClient(cfg fantasybridge.Config) (stream.Client, error)

NewFantasyClient creates the fantasy bridge client.

Types

type ClientFactory added in v0.2.3

type ClientFactory func(fantasybridge.Config) (stream.Client, error)

ClientFactory creates a stream.Client from a provider configuration. It allows tests to replace the real Fantasy bridge with a stub.

type Service

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

Service is the core orchestration layer for starting LLM streams.

It is intentionally UI-agnostic and can be used by both the TUI and headless commands.

func New

func New(cfg *config.Config, cache *cache.Conversations, mcpSvc *mcp.Service, opts ...ClientFactory) *Service

New creates an agent service. An optional ClientFactory can be provided for testing; when nil, the default Fantasy bridge client is used.

func (*Service) ActionForStreamError

func (s *Service) ActionForStreamError(err error, mod config.Model, prompt string) StreamErrorAction

ActionForStreamError decides whether a provider error should be retried, and if so which prompt/model override should be used.

func (*Service) Stream

func (s *Service) Stream(ctx context.Context, prompt string) (StreamStart, error)

Stream starts a streaming completion for the given prompt.

func (*Service) StreamContinue added in v0.2.4

func (s *Service) StreamContinue(ctx context.Context, history []proto.Message, prompt string) (StreamStart, error)

StreamContinue starts a streaming completion using pre-built conversation history. It prepends system messages (format + role) to the provided history and appends the new user message. This avoids per-turn disk I/O and prevents system message duplication across turns.

type StreamErrorAction

type StreamErrorAction struct {
	Retry         bool
	Prompt        string
	ModelOverride string
	Err           errs.Error
}

StreamErrorAction describes how yai should respond to a streaming error.

type StreamStart

type StreamStart struct {
	Stream   stream.Stream
	Model    config.Model
	Messages []proto.Message
}

StreamStart contains the stream plus metadata about the resolved request.

Jump to

Keyboard shortcuts

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