Documentation
¶
Overview ¶
Package chat implements the in-app assistant: a stateless tool-using agent loop that helps operators set up jobs and troubleshoot failures.
The package owns three responsibilities:
- Building the system prompt (assistant persona + embedded doc grounding).
- Running an N-turn ChatTurn loop against any llm.ToolCapableProvider.
- Routing tool calls to read-only inspection helpers that wrap the same queries the rest of webapi uses (runs, schedules, skills, audit).
The agent is intentionally read-only. Setup help is delivered as YAML snippets the operator pastes into their repo — there is no code path that mutates schedules, secrets, or repos from chat.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Caller ¶
Caller identifies the human asking the chat agent for help. Tools may use the role to gate behavior — e.g. an admin can see manifest contents that reference secret names, while a viewer only sees redacted summaries.
type Config ¶
type Config struct {
// Provider is the LLM provider implementation. Must support tool use.
Provider llm.ToolCapableProvider
// Model is the provider-specific model identifier.
Model string
// APIKey authenticates the LLM call.
APIKey string
// Endpoint / Deployment are forwarded to llm.CallOptions for Azure.
Endpoint string
Deployment string
// MaxTurns caps the tool-loop iteration count. Falls back to 6.
MaxTurns int
// MaxTokens caps each turn's output. Falls back to 2048.
MaxTokens int
// Tools is the read-only tool surface available to the model.
Tools Toolbox
// Caller carries identity (login, role) for tool authorization decisions.
Caller Caller
// PageContext is an optional short string describing where the user is in
// the UI ("/jobs/abc123"). It's included in the system prompt verbatim.
PageContext string
}
Config holds per-request configuration for a chat turn.
type Message ¶
type Message struct {
Role string `json:"role"` // "user" | "assistant"
Content string `json:"content"`
}
Message is a chat turn for the agent loop. Mirrors llm.Message but with a JSON-friendly shape suitable for the SSE wire protocol.
type Sink ¶
type Sink interface {
// Token is called for every text delta the model emits.
Token(delta string)
// ToolStart is called when a tool call begins (for UI signaling).
ToolStart(name string, input json.RawMessage)
// ToolEnd is called when a tool call completes. errMsg is empty on success.
ToolEnd(name string, errMsg string)
}
Sink receives streaming events as the agent runs. Implementations are expected to be cheap and non-blocking; the SSE handler buffers writes via http.Flusher.
type Toolbox ¶
Toolbox is the read-only tool surface exposed to the chat agent. It wraps the same sqlc Queries the rest of webapi uses, but only the safe-to-read subset and only filtered to the org the operator belongs to.
func (Toolbox) Call ¶
func (tb Toolbox) Call(ctx context.Context, caller Caller, name string, raw json.RawMessage) (json.RawMessage, error)
Call dispatches a single tool invocation. Returns the JSON-encoded tool result that will be fed back to the model. errors are returned to the caller (not stuffed into the result) so the agent loop can decide whether to surface them as tool errors or as fatal.