Documentation
¶
Overview ¶
Package chatservice persists the conversation thread. Terminal output, file reads, and agent steps are stored here so the thread survives restarts.
Index ¶
- func CompactHistory(ctx context.Context, exec ChainExecutor, chain *taskengine.TaskChainDefinition, ...) ([]taskengine.Message, error)
- type ChainExecutor
- type Manager
- func (m *Manager) AddInstruction(ctx context.Context, tx libdb.Exec, id string, sendAt time.Time, ...) error
- func (m *Manager) AppendMessage(_ context.Context, messages []taskengine.Message, sendAt time.Time, ...) ([]taskengine.Message, error)
- func (m *Manager) ClearSession(ctx context.Context, tx libdb.Exec, sessionID string) error
- func (m *Manager) DeleteSession(ctx context.Context, tx libdb.Exec, sessionID string, identity string) error
- func (m *Manager) ListMessages(ctx context.Context, tx libdb.Exec, subjectID string) ([]taskengine.Message, error)
- func (m *Manager) PersistDiff(ctx context.Context, tx libdb.Exec, subjectID string, ...) error
- func (m *Manager) RenameSession(ctx context.Context, tx libdb.Exec, sessionID string, name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompactHistory ¶
func CompactHistory(ctx context.Context, exec ChainExecutor, chain *taskengine.TaskChainDefinition, history []taskengine.Message, keep int) ([]taskengine.Message, error)
CompactHistory summarizes the older portion of a conversation into a single <compact-summary> user message. Leading system messages and the last `keep` messages are preserved verbatim; everything between them is replaced by the summary the chain produces.
The caller is responsible for setting the chain's template vars (model, provider, …) on ctx via taskengine.WithTemplateVars before calling.
Types ¶
type ChainExecutor ¶
type ChainExecutor interface {
Execute(ctx context.Context, chain *taskengine.TaskChainDefinition, input any, inputType taskengine.DataType) (any, taskengine.DataType, []taskengine.CapturedStateUnit, error)
}
ChainExecutor runs a task chain over a history. It is satisfied by enginesvc.Engine.TaskService (execservice.TasksEnvService) — the seam lets CompactHistory stay free of the engine and cobra wiring so both the CLI (`session fork --summary`) and the ACP `/compact` command can call it.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) AddInstruction ¶
func (m *Manager) AddInstruction(ctx context.Context, tx libdb.Exec, id string, sendAt time.Time, message string) error
AddInstruction inserts a system message into an existing chat index.
func (*Manager) AppendMessage ¶
func (m *Manager) AppendMessage(_ context.Context, messages []taskengine.Message, sendAt time.Time, message string, role string) ([]taskengine.Message, error)
AppendMessage appends a message to an in-memory slice (no DB write). Call PersistDiff afterwards to persist the result.
func (*Manager) ClearSession ¶
ClearSession removes all messages for a session while keeping the index, so the session keeps its identity and name but starts a fresh conversation.
func (*Manager) DeleteSession ¶
func (m *Manager) DeleteSession(ctx context.Context, tx libdb.Exec, sessionID string, identity string) error
DeleteSession removes all messages and the index for a session.
func (*Manager) ListMessages ¶
func (m *Manager) ListMessages(ctx context.Context, tx libdb.Exec, subjectID string) ([]taskengine.Message, error)
ListMessages retrieves all stored messages for a given subject ID.