Documentation
¶
Overview ¶
Package agentclient provides a lightweight HTTP client for querying the klaus agent's /status endpoint. Unlike the MCP client, this does not require session initialization — it's a simple GET request.
Index ¶
- Variables
- func StreamCompletion(ctx context.Context, client *http.Client, req CompletionRequest) (<-chan CompletionDelta, error)
- func WaitForReady(ctx context.Context, client *http.Client, baseURL string) error
- type AgentInfo
- type CompletionDelta
- type CompletionRequest
- type HTTPError
- type StatusResponse
Constants ¶
This section is empty.
Variables ¶
var ErrAgentRunFailed = errors.New("agent run ended in error")
ErrAgentRunFailed is set on the final CompletionDelta when the agent run ended in error (finish_reason "error"). Blocking callers return it so the process exits non-zero, preventing silent success on a failed run.
Functions ¶
func StreamCompletion ¶
func StreamCompletion(ctx context.Context, client *http.Client, req CompletionRequest) (<-chan CompletionDelta, error)
StreamCompletion sends a prompt via POST to the completions URL with stream=true and returns a channel of deltas. The channel is closed when the stream ends (either cleanly via [DONE] or due to an error).
The wire body is identical regardless of whether req.Bearer/Headers are set — local (direct-to-agent) and remote (gateway) callers share the same request shape so the server side sees no difference.
Types ¶
type AgentInfo ¶
type AgentInfo struct {
Status string `json:"status"`
SessionID string `json:"session_id,omitempty"`
MessageCount int `json:"message_count,omitempty"`
}
AgentInfo holds the agent-level fields returned by the /status endpoint.
type CompletionDelta ¶
CompletionDelta is a single streaming delta from the completions endpoint. When the channel is closed the stream has ended. If the stream was interrupted by an I/O error (as opposed to a clean [DONE] or context cancellation), Err is set on the final delta before the channel closes.
type CompletionRequest ¶ added in v0.0.58
CompletionRequest describes a single /v1/chat/completions call. URL is the full endpoint (the caller is responsible for composing the instance-scoped path). Bearer and Headers are optional — Bearer becomes an `Authorization: Bearer <token>` header and Headers are applied on top of the default Content-Type/Accept pair.
type HTTPError ¶ added in v0.0.58
HTTPError is returned by StreamCompletion when the completions endpoint responds with a non-200 status. Callers (notably the remote path) can type-assert on this to trigger refresh-on-401.
type StatusResponse ¶
type StatusResponse struct {
Name string `json:"name"`
Version string `json:"version"`
Agent AgentInfo `json:"agent"`
Mode string `json:"mode,omitempty"`
}
StatusResponse represents the JSON body returned by GET /status.
func FetchStatus ¶
FetchStatus queries the agent's HTTP /status endpoint and returns the parsed response. Returns an error if the agent is unreachable, returns a non-200 status, or returns invalid JSON.