Documentation
¶
Index ¶
- Variables
- type APIError
- type EventType
- type Provider
- type ProviderMessage
- type Role
- type Runtime
- func (r *Runtime) DeleteThread(c *echo.Context) error
- func (r *Runtime) GetThread(c *echo.Context) error
- func (r *Runtime) ListThreads(c *echo.Context) error
- func (r *Runtime) Register(group *echo.Group)
- func (r *Runtime) RenameThread(c *echo.Context) error
- func (r *Runtime) Run(c *echo.Context) error
- type Store
- func (s *Store) DeleteThread(ctx context.Context, ownerID, threadID string) error
- func (s *Store) FinishRun(ctx context.Context, ownerID, threadID, runID string, ...) error
- func (s *Store) RenameThread(ctx context.Context, ownerID, threadID, title string) error
- func (s *Store) StartRun(ctx context.Context, ownerID string, input agtypes.RunAgentInput) ([]agtypes.Message, error)
- func (s *Store) Thread(ctx context.Context, ownerID, threadID string) (Thread, error)
- func (s *Store) Threads(ctx context.Context, ownerID string, options ThreadListOptions) ([]ThreadSummary, error)
- type StreamEvent
- type StreamParams
- type Thread
- type ThreadListOptions
- type ThreadSummary
- type TokenUsage
- type ToolCall
- type ToolDef
- type ToolExecution
- type ToolRegistry
- type ToolResult
Constants ¶
This section is empty.
Variables ¶
var ErrThreadNotFound = errors.New("agent thread not found")
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider interface {
Stream(context.Context, StreamParams, func(StreamEvent) error) error
}
Provider streams model completions. The provider must:
- Emit zero or more EventText events with text deltas
- Emit zero or more EventToolUse events (ToolCall must be non-nil)
- Emit EventUsage snapshots when counts arrive before terminal processing
- Emit exactly one EventStop OR EventError as the final event
- EventError is terminal: the provider must return after emitting it
- Stop streaming if the callback returns a non-nil error
func NewProvider ¶
type ProviderMessage ¶
type ProviderMessage struct {
Role Role
Content string
ToolCalls []ToolCall
ToolResult *ToolResult
// ProviderItems are opaque assistant output retained only in the current run.
ProviderItems []json.RawMessage `json:"-"`
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists agent threads and runs.
func (*Store) DeleteThread ¶
DeleteThread permanently removes one owner-scoped conversation and its runs.
func (*Store) FinishRun ¶
func (s *Store) FinishRun(ctx context.Context, ownerID, threadID, runID string, messages []agtypes.Message, eventJSON [][]byte, truncated bool, runErr error) error
FinishRun persists the final conversation and the run outcome. The thread's messages_json is written wholesale: if two runs on the same thread finish concurrently, the later commit wins (last-write-wins) — concurrent runs on one thread are not a supported flow, and each run row still records its own events and outcome. truncated marks a run whose answer was cut off at the provider's token limit; it only applies when runErr is nil.
func (*Store) RenameThread ¶
RenameThread replaces the display title for one owner-scoped conversation.
func (*Store) StartRun ¶
func (s *Store) StartRun(ctx context.Context, ownerID string, input agtypes.RunAgentInput) ([]agtypes.Message, error)
StartRun creates or updates the caller's thread and records the run as running. The SELECT-then-INSERT runs under BEGIN IMMEDIATE on a pinned connection so two concurrent first-runs on the same thread serialize instead of racing into a unique-constraint error.
func (*Store) Threads ¶
func (s *Store) Threads(ctx context.Context, ownerID string, options ThreadListOptions) ([]ThreadSummary, error)
Threads returns owner-scoped conversation summaries in reverse update order.
type StreamEvent ¶
type StreamEvent struct {
Type EventType
Delta string // text token (EventText)
ToolCall *ToolCall // completed tool call (EventToolUse)
StopReason string // e.g. "end_turn", "tool_calls", "length", "max_tokens" (EventStop)
ToolStep bool // a tool call was begun, including an unfinished call (EventStop)
Error string // error message (EventError)
Model string // model reported by the provider response
Usage *TokenUsage // provider-reported token snapshot, including failed calls
ProviderItems []json.RawMessage `json:"-"` // opaque continuation items (EventStop)
}
StreamEvent is a single event from the model stream; Type discriminates which payload field is set.
type StreamParams ¶
type StreamParams struct {
System string
Messages []ProviderMessage
Tools []ToolDef
MaxTokens int
}
type Thread ¶
type Thread struct {
ThreadID string `json:"id"`
Messages []agtypes.Message `json:"messages"`
Updated string `json:"updated_at"`
}
Thread is a persisted agent conversation owned by one user.
type ThreadListOptions ¶
ThreadListOptions controls owner-scoped conversation history queries. BeforeUpdated and BeforeID form one compound keyset cursor: callers must provide both or neither. Limit defaults to 30 and is capped at 101.
type ThreadSummary ¶
type ThreadSummary struct {
ThreadID string `json:"id"`
Title string `json:"title"`
Updated string `json:"updated_at"`
}
ThreadSummary is the compact representation returned by conversation history.
type TokenUsage ¶
type TokenUsage struct {
InputTokens int
OutputTokens int
ReasoningTokens int
CacheReadTokens int
CacheWriteTokens int
}
TokenUsage includes reasoning tokens in OutputTokens; ReasoningTokens is a subset.
type ToolExecution ¶
type ToolRegistry ¶
type ToolRegistry struct {
// contains filtered or unexported fields
}
func NewToolRegistry ¶
func (*ToolRegistry) Close ¶
func (r *ToolRegistry) Close() error
func (*ToolRegistry) Definitions ¶
func (r *ToolRegistry) Definitions() []ToolDef
func (*ToolRegistry) Execute ¶
func (r *ToolRegistry) Execute(ctx context.Context, call ToolCall) (ToolExecution, error)
func (*ToolRegistry) ReadOnly ¶
func (r *ToolRegistry) ReadOnly(name string) bool