chat

package
v1.4.26 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package chat implements the dedicated conversational DevOps/SRE agent.

Index

Constants

View Source
const (
	MaxToolIterations    = 8
	DefaultToolTimeout   = 20 * time.Second
	MaxOutputBytes       = 8192
	MaxModelContextTurns = 20
)
View Source
const (
	MaxSessions          = 100
	MaxTurnsPerSession   = 100
	MaxMessageBytes      = 8192
	MaxToolPayloadBytes  = 8192
	MaxEventsPerTurn     = 128
	MaxCitationsPerTrace = 4
	MaxEventBytesPerTurn = 32 * 1024
	MaxToolBytesPerTurn  = 32 * 1024
	MaxSessionBlobBytes  = 5 * 1024 * 1024
	SessionRetention     = 30 * 24 * time.Hour
)
View Source
const (
	DefaultRunTimeout = 10 * time.Minute
)

Variables

View Source
var (
	ErrRunActive         = errors.New("chat: run already active")
	ErrNoActiveRun       = errors.New("chat: no active run")
	ErrInvalidMessage    = errors.New("chat: invalid message")
	ErrInvalidAttachment = errors.New("chat: invalid attachment")
	ErrInvalidTime       = errors.New("chat: invalid time range")
)
View Source
var (
	ErrSessionNotFound = errors.New("chat: session not found")
	ErrStoreConflict   = errors.New("chat: storage conflict")
	ErrLeaseFenced     = errors.New("chat: lease fenced")
	ErrSessionTooLarge = errors.New("chat: session exceeds storage limit")
)

Functions

func LocationFromReportSettings

func LocationFromReportSettings(provider storage.Provider) *time.Location

LocationFromReportSettings returns the durable report timezone used when a chat turn resolves time hints. Runtime changes apply to the next turn; unreadable, absent, or invalid settings fall back to UTC.

func PromptOrder

func PromptOrder() []string

PromptOrder returns a defensive copy of the canonical fragment order.

func ResolveTimePhrase

func ResolveTimePhrase(phrase string, now time.Time, loc *time.Location) (core.ChatTimeRange, error)

ResolveTimePhrase converts the deliberately small supported phrase set into absolute bounds in loc. Unsupported or ambiguous phrases return an error.

func SystemPrompt

func SystemPrompt() string

SystemPrompt returns the assembled prompt used for chat runs.

Types

type Agent

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

func New

func New(ctx context.Context, cfg config.AgentAIConfig, tools []core.Tool, opts Options) (*Agent, error)

func (*Agent) Kind

func (agent *Agent) Kind() core.AITaskKind

func (*Agent) Name

func (agent *Agent) Name() string

func (*Agent) RunChatTurn

func (agent *Agent) RunChatTurn(ctx context.Context, task core.ChatTask) (*core.ChatTurnResult, error)

func (*Agent) Seed

func (agent *Agent) Seed(ctx context.Context) []core.ToolCallTrace

Seed collects the available discovery evidence once for a new session.

type Options

type Options struct {
	HTTPClient     *http.Client
	BaseURL        string
	Timeout        time.Duration
	RuntimeKeyFunc func(context.Context) (string, bool)
	Runtime        einowrap.RuntimeAI
	ChatModel      model.ToolCallingChatModel
	ToolTimeout    time.Duration
	ToolProvider   func() ([]core.Tool, error)
	SeedProvider   func() ([]core.Tool, error)
}

type Service

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

func NewService

func NewService(store *SessionStore, chatRouter TurnRunner, seeder discoverySeeder, now func() time.Time) *Service

func NewServiceWithLocation

func NewServiceWithLocation(store *SessionStore, chatRouter TurnRunner, seeder discoverySeeder, now func() time.Time, loc *time.Location) *Service

NewServiceWithLocation constructs a service with deterministic date phrase resolution in loc. Nil clocks and locations default to time.Now and UTC.

func NewServiceWithLocationProvider

func NewServiceWithLocationProvider(store *SessionStore, chatRouter TurnRunner, seeder discoverySeeder, now func() time.Time, location func() *time.Location) *Service

NewServiceWithLocationProvider resolves the current report timezone for every turn so runtime settings changes do not require a process restart.

func NewServiceWithLocationProviderAndContextDecorator added in v1.4.26

func NewServiceWithLocationProviderAndContextDecorator(store *SessionStore, chatRouter TurnRunner, seeder discoverySeeder, now func() time.Time, location func() *time.Location, decorate func(context.Context) context.Context) *Service

NewServiceWithLocationProviderAndContextDecorator constructs a service that decorates every detached turn context before seed, tool, and model execution. A nil decorator preserves the OSS identity behavior.

func (*Service) Available

func (service *Service) Available() bool

func (*Service) Cancel

func (service *Service) Cancel(id string) error

func (*Service) Create

func (service *Service) Create() (*Session, error)

func (*Service) Delete

func (service *Service) Delete(id string) error

func (*Service) Get

func (service *Service) Get(id string) (*Session, error)

func (*Service) List

func (service *Service) List() ([]*Session, error)

func (*Service) Send

func (service *Service) Send(ctx context.Context, id, message string, attachment *core.ChatAttachment) (result *core.ChatTurnResult, err error)

func (*Service) Start

func (service *Service) Start(ctx context.Context, id, message string, attachment *core.ChatAttachment) (<-chan TurnOutcome, error)

Start atomically admits and starts a detached turn. Admission errors such as an already-active session are returned before an SSE response is committed.

type Session

type Session struct {
	ID        string        `json:"id"`
	Status    SessionStatus `json:"status"`
	Seeded    bool          `json:"seeded"`
	Turns     []Turn        `json:"turns"`
	CreatedAt time.Time     `json:"created_at"`
	UpdatedAt time.Time     `json:"updated_at"`
}

type SessionStatus

type SessionStatus string
const (
	SessionIdle    SessionStatus = "idle"
	SessionRunning SessionStatus = "running"
	SessionFailed  SessionStatus = "failed"
)

type SessionStore

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

func NewSessionStore

func NewSessionStore(provider storage.Provider, scope tenancy.OrgScope, now func() time.Time) *SessionStore

func (*SessionStore) AcquireLease

func (store *SessionStore) AcquireLease(id, owner string, ttl time.Duration) (uint64, bool, error)

func (*SessionStore) Append

func (store *SessionStore) Append(id string, turns ...Turn) (*Session, error)

func (*SessionStore) Create

func (store *SessionStore) Create(id string) (*Session, error)

func (*SessionStore) Delete

func (store *SessionStore) Delete(id string) error

func (*SessionStore) Get

func (store *SessionStore) Get(id string) (*Session, error)

func (*SessionStore) LeaseActive

func (store *SessionStore) LeaseActive(id string) (bool, error)

func (*SessionStore) List

func (store *SessionStore) List() ([]*Session, error)

func (*SessionStore) ReleaseLease

func (store *SessionStore) ReleaseLease(id, owner string, epoch uint64) error

func (*SessionStore) RenewLease

func (store *SessionStore) RenewLease(id, owner string, epoch uint64, ttl time.Duration) (bool, bool, error)

func (*SessionStore) RequestCancel

func (store *SessionStore) RequestCancel(id string) (bool, error)

func (*SessionStore) SetStatus

func (store *SessionStore) SetStatus(id string, status SessionStatus, seeded bool) error

type Turn

type Turn struct {
	ID         string               `json:"id"`
	Role       TurnRole             `json:"role"`
	Content    string               `json:"content"`
	CreatedAt  time.Time            `json:"created_at"`
	Attachment *core.ChatAttachment `json:"attachment,omitempty"`
	ToolCalls  []core.ToolCallTrace `json:"tool_calls,omitempty"`
	Citations  []core.ChatCitation  `json:"citations,omitempty"`
	Events     []core.ChatEvent     `json:"events,omitempty"`
}

type TurnOutcome

type TurnOutcome struct {
	Result *core.ChatTurnResult
	Err    error
}

type TurnRole

type TurnRole string
const (
	TurnUser       TurnRole = "user"
	TurnAssistant  TurnRole = "assistant"
	TurnCompaction TurnRole = "compaction"
)

type TurnRunner

type TurnRunner interface {
	RunChat(context.Context, core.ChatTask) (*core.ChatTurnResult, error)
}

Jump to

Keyboard shortcuts

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