Documentation
¶
Index ¶
- Variables
- type AgentIO
- type AgentState
- type Conversation
- type ConversationMessage
- type ConversationRole
- type ConversationStatus
- type Emitter
- type ErrorLevel
- type LoadStateStatus
- type MessagePart
- type MessagePartText
- type PTYConversation
- func (c *PTYConversation) Messages() []ConversationMessage
- func (c *PTYConversation) SaveState() error
- func (c *PTYConversation) Send(messageParts ...MessagePart) error
- func (c *PTYConversation) Start(ctx context.Context)
- func (c *PTYConversation) Status() ConversationStatus
- func (c *PTYConversation) Text() string
- type PTYConversationConfig
- type RingBuffer
- type StatePersistenceConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrMessageValidationWhitespace = xerrors.New("message must be trimmed of leading and trailing whitespace") ErrMessageValidationEmpty = xerrors.New("message must not be empty") ErrMessageValidationChanging = xerrors.New("message can only be sent when the agent is waiting for user input") )
var ConversationRoleValues = []ConversationRole{ ConversationRoleUser, ConversationRoleAgent, }
var ErrorLevelValues = []ErrorLevel{ ErrorLevelWarning, ErrorLevelError, }
Functions ¶
This section is empty.
Types ¶
type AgentState ¶ added in v0.12.0
type AgentState struct {
Version int `json:"version"`
Messages []ConversationMessage `json:"messages"`
InitialPrompt string `json:"initial_prompt"`
InitialPromptSent bool `json:"initial_prompt_sent"`
}
type Conversation ¶
type Conversation interface {
Messages() []ConversationMessage
Send(...MessagePart) error
Start(context.Context)
Status() ConversationStatus
Text() string
SaveState() error
}
Conversation represents a conversation between a user and an agent. It is intended as the primary interface for interacting with a session. Implementations must support the following capabilities:
- Fetching all messages between the user and agent,
- Sending a message to the agent,
- Starting a background loop to update the conversation state, if required,
- Fetching the status of the conversation,
- Returning a textual representation of the conversation "screen" (used for notifying subscribers of updates to the conversation).
type ConversationMessage ¶
type ConversationMessage struct {
Id int `json:"id"`
Message string `json:"message"`
Role ConversationRole `json:"role"`
Time time.Time `json:"time"`
}
type ConversationRole ¶
type ConversationRole string
const ( ConversationRoleUser ConversationRole = "user" ConversationRoleAgent ConversationRole = "agent" )
type ConversationStatus ¶
type ConversationStatus string
const ( ConversationStatusChanging ConversationStatus = "changing" ConversationStatusStable ConversationStatus = "stable" ConversationStatusInitializing ConversationStatus = "initializing" )
type Emitter ¶ added in v0.12.0
type Emitter interface {
EmitMessages([]ConversationMessage)
EmitStatus(ConversationStatus)
EmitScreen(string)
EmitError(message string, level ErrorLevel)
}
Emitter receives conversation state updates.
type ErrorLevel ¶ added in v0.12.0
type ErrorLevel string
const ( ErrorLevelWarning ErrorLevel = "warning" ErrorLevelError ErrorLevel = "error" )
type LoadStateStatus ¶ added in v0.12.0
type LoadStateStatus int
LoadStateStatus represents the state of loading persisted conversation state.
const ( // LoadStatePending indicates state loading has not been attempted yet. LoadStatePending LoadStateStatus = iota // LoadStateSucceeded indicates state was successfully loaded. LoadStateSucceeded // LoadStateFailed indicates state loading was attempted but failed. LoadStateFailed )
type MessagePart ¶
type MessagePartText ¶
func (MessagePartText) Do ¶
func (p MessagePartText) Do(writer AgentIO) error
func (MessagePartText) String ¶
func (p MessagePartText) String() string
type PTYConversation ¶ added in v0.12.0
type PTYConversation struct {
// contains filtered or unexported fields
}
PTYConversation is a conversation that uses a pseudo-terminal (PTY) for communication. It uses a combination of polling and diffs to detect changes in the screen.
func NewPTY ¶ added in v0.12.0
func NewPTY(ctx context.Context, cfg PTYConversationConfig, emitter Emitter) *PTYConversation
func (*PTYConversation) Messages ¶ added in v0.12.0
func (c *PTYConversation) Messages() []ConversationMessage
func (*PTYConversation) SaveState ¶ added in v0.12.0
func (c *PTYConversation) SaveState() error
func (*PTYConversation) Send ¶ added in v0.12.0
func (c *PTYConversation) Send(messageParts ...MessagePart) error
func (*PTYConversation) Start ¶ added in v0.12.0
func (c *PTYConversation) Start(ctx context.Context)
func (*PTYConversation) Status ¶ added in v0.12.0
func (c *PTYConversation) Status() ConversationStatus
func (*PTYConversation) Text ¶ added in v0.12.0
func (c *PTYConversation) Text() string
type PTYConversationConfig ¶ added in v0.12.0
type PTYConversationConfig struct {
AgentType msgfmt.AgentType
AgentIO AgentIO
// Clock provides time operations for the conversation
Clock quartz.Clock
// How often to take a snapshot for the stability check
SnapshotInterval time.Duration
// How long the screen should not change to be considered stable
ScreenStabilityLength time.Duration
// Function to format the messages received from the agent
// userInput is the last user message
FormatMessage func(message string, userInput string) string
// ReadyForInitialPrompt detects whether the agent has initialized and is ready to accept the initial prompt
ReadyForInitialPrompt func(message string) bool
// FormatToolCall removes the coder report_task tool call from the agent message and also returns the array of removed tool calls
FormatToolCall func(message string) (string, []string)
// InitialPrompt is the initial prompt to send to the agent once ready
InitialPrompt []MessagePart
Logger *slog.Logger
StatePersistenceConfig StatePersistenceConfig
}
PTYConversationConfig is the configuration for a PTYConversation.
type RingBuffer ¶
type RingBuffer[T any] struct { // contains filtered or unexported fields }
RingBuffer is a generic circular buffer that can store items of any type
func NewRingBuffer ¶
func NewRingBuffer[T any](size int) *RingBuffer[T]
NewRingBuffer creates a new ring buffer with the specified size
func (*RingBuffer[T]) Capacity ¶
func (b *RingBuffer[T]) Capacity() int
Capacity returns the capacity of the ring buffer
func (*RingBuffer[T]) GetAll ¶
func (b *RingBuffer[T]) GetAll() []T
GetAll returns all items in the buffer, oldest first