llm

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContextWindowExceeded = errors.New("context window exceeded")

Functions

func AutoCompact

func AutoCompact(ctx context.Context, client LLMClient, history []Message, sessionID string) ([]Message, *TokenUsage, error)

func Build

func Build(workingDir, skillsCatalog, subagentsCatalog string, mode AgentMode) string

func BuildAdversaryPrompt

func BuildAdversaryPrompt(workingDir string) string

func BuildAutoCompactionPrompt

func BuildAutoCompactionPrompt() string

func BuildBtwPrompt

func BuildBtwPrompt(workingDir string) string

func BuildCompactionPrompt

func BuildCompactionPrompt(extraPrompt string) string

func FormatMessageForProvider

func FormatMessageForProvider(message Message) string

func ProjectInstructions

func ProjectInstructions(workingDir string) string

func ToGenkitTool

func ToGenkitTool(t tools.Tool) *ai.ToolDef[any, any]

func ToGenkitTools

func ToGenkitTools(registry *tools.Registry) []ai.ToolRef

Types

type AgentMode

type AgentMode string
const (
	ModeBuild AgentMode = "build"
	ModePlan  AgentMode = "plan"
)

type AnthropicClient

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

func NewAnthropicClient

func NewAnthropicClient(cfg *ClientConfig) (*AnthropicClient, error)

func (*AnthropicClient) Reset

func (c *AnthropicClient) Reset()

func (*AnthropicClient) StreamChat

func (c *AnthropicClient) StreamChat(
	ctx context.Context,
	messages []Message,
	toolRegistry *tools.Registry,
	opts ...StreamOptions,
) (<-chan StreamEvent, error)

type AutoCompactionEvent

type AutoCompactionEvent struct {
	Cancel      func()
	Replacement []Message
	Usage       *TokenUsage
	Error       error
}

type BedrockClient

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

func NewBedrockClient

func NewBedrockClient(cfg *ClientConfig) (*BedrockClient, error)

func (*BedrockClient) Reset

func (c *BedrockClient) Reset()

func (*BedrockClient) StreamChat

func (c *BedrockClient) StreamChat(
	ctx context.Context,
	messages []Message,
	toolRegistry *tools.Registry,
	opts ...StreamOptions,
) (<-chan StreamEvent, error)

type ClientConfig

type ClientConfig struct {
	Provider            Provider
	APIKey              string
	APIKeyHelper        string
	Model               string
	ThinkingEffort      string
	BaseURL             string
	MaxRetries          int
	ContextWindowTokens int
	Headers             map[string]string
}

type ContextBreakdown

type ContextBreakdown struct {
	SystemPromptTokens  int
	ToolDefinitionCount int
	ToolDefTokens       int
	UserMessageTokens   int
	AssistantTokens     int
	ToolResultTokens    int
	TotalEstimated      int
}

func EstimateContextBreakdown

func EstimateContextBreakdown(systemPrompt string, toolDefs []ContextToolDef, messages []ContextMessage) ContextBreakdown

type ContextMessage

type ContextMessage struct {
	Role         Role
	Content      string
	ToolActivity []HistoricalToolActivity
}

type ContextToolDef

type ContextToolDef struct {
	Name        string
	Description string
	InputSchema map[string]any
}

type GenkitClient

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

func NewGenkitClient

func NewGenkitClient(cfg *ClientConfig) (*GenkitClient, error)

func (*GenkitClient) Reset

func (c *GenkitClient) Reset()

func (*GenkitClient) StreamChat

func (c *GenkitClient) StreamChat(
	ctx context.Context,
	messages []Message,
	toolRegistry *tools.Registry,
	opts ...StreamOptions,
) (<-chan StreamEvent, error)

type HistoricalToolActivity

type HistoricalToolActivity struct {
	TextOffset     int            `json:"text_offset"`
	Tool           string         `json:"tool"`
	Input          map[string]any `json:"input,omitempty"`
	Status         string         `json:"status"`
	ExitCode       *int           `json:"exit_code,omitempty"`
	HasRawOutput   bool           `json:"-"`
	RawOutput      any            `json:"-"`
	RetainedOutput any            `json:"retained_output,omitempty"`
}

type LLMClient

type LLMClient interface {
	StreamChat(ctx context.Context, messages []Message, toolRegistry *tools.Registry, opts ...StreamOptions) (<-chan StreamEvent, error)
	Reset()
}

func NewClient

func NewClient(cfg *config.ResolvedConfig) (LLMClient, error)

type Message

type Message struct {
	Role       Role
	Content    string
	TurnMemory *TurnMemory
}

func BuildCompactionRequest

func BuildCompactionRequest(history []Message, extraPrompt string, automatic bool) ([]Message, error)

func CloneMessage

func CloneMessage(message Message) Message

func CloneMessages

func CloneMessages(messages []Message) []Message

type OpenAICodexClient

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

func NewOpenAICodexClient

func NewOpenAICodexClient(cfg *ClientConfig) (*OpenAICodexClient, error)

func (*OpenAICodexClient) Reset

func (c *OpenAICodexClient) Reset()

func (*OpenAICodexClient) StreamChat

func (c *OpenAICodexClient) StreamChat(ctx context.Context, messages []Message, toolRegistry *tools.Registry, opts ...StreamOptions) (<-chan StreamEvent, error)

type OpenAICompatibleClient

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

func NewOpenAICompatibleClient

func NewOpenAICompatibleClient(cfg *ClientConfig) (*OpenAICompatibleClient, error)

func (*OpenAICompatibleClient) Reset

func (c *OpenAICompatibleClient) Reset()

func (*OpenAICompatibleClient) StreamChat

func (c *OpenAICompatibleClient) StreamChat(
	ctx context.Context,
	messages []Message,
	toolRegistry *tools.Registry,
	opts ...StreamOptions,
) (<-chan StreamEvent, error)

type OpenAIResponsesClient

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

func NewOpenAIResponsesClient

func NewOpenAIResponsesClient(cfg *ClientConfig) (*OpenAIResponsesClient, error)

func (*OpenAIResponsesClient) Reset

func (c *OpenAIResponsesClient) Reset()

func (*OpenAIResponsesClient) StreamChat

func (c *OpenAIResponsesClient) StreamChat(
	ctx context.Context,
	messages []Message,
	toolRegistry *tools.Registry,
	opts ...StreamOptions,
) (<-chan StreamEvent, error)

type Provider

type Provider string

type Role

type Role string
const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
)

type StreamEvent

type StreamEvent struct {
	Type           StreamEventType
	Content        string
	Error          error
	ToolCall       *ToolCall
	Usage          *TokenUsage
	Attempt        int
	AutoCompaction *AutoCompactionEvent
}

type StreamEventType

type StreamEventType string
const (
	StreamEventTypeChunk                   StreamEventType = "chunk"
	StreamEventTypeReasoningChunk          StreamEventType = "reasoning_chunk"
	StreamEventTypeDone                    StreamEventType = "done"
	StreamEventTypeError                   StreamEventType = "error"
	StreamEventTypeToolStart               StreamEventType = "tool_start"
	StreamEventTypeToolEnd                 StreamEventType = "tool_end"
	StreamEventTypeUsage                   StreamEventType = "usage"
	StreamEventTypeRetry                   StreamEventType = "retry"
	StreamEventTypeIncomplete              StreamEventType = "incomplete"
	StreamEventTypeAutoCompactionStarted   StreamEventType = "auto_compaction_started"
	StreamEventTypeAutoCompactionApplied   StreamEventType = "auto_compaction_applied"
	StreamEventTypeAutoCompactionCancelled StreamEventType = "auto_compaction_cancelled"
	StreamEventTypeAutoCompactionFailed    StreamEventType = "auto_compaction_failed"
)

type StreamOptions

type StreamOptions struct {
	SessionID             string
	OneShot               bool
	DisableAutoCompaction bool
}

type TokenUsage

type TokenUsage struct {
	InputTokens     int
	OutputTokens    int
	TotalTokens     int
	ReasoningTokens int
	CachedTokens    int
}

type ToolCall

type ToolCall struct {
	Name     string
	Input    map[string]any
	Output   any
	Error    string
	Duration time.Duration
}

type TurnMemory

type TurnMemory struct {
	ToolActivity []HistoricalToolActivity `json:"tool_activity,omitempty"`
}

func CloneTurnMemory

func CloneTurnMemory(memory *TurnMemory) *TurnMemory

func (*TurnMemory) IsEmpty

func (m *TurnMemory) IsEmpty() bool

Jump to

Keyboard shortcuts

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