agentclient

package
v0.2.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

func WaitForReady

func WaitForReady(ctx context.Context, client *http.Client, baseURL string) error

WaitForReady polls the agent's /status endpoint until it responds successfully or the context is cancelled. Uses exponential backoff from 1s to 5s with a hard 2-minute deadline.

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

type CompletionDelta struct {
	Content string
	Err     error
}

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

type CompletionRequest struct {
	URL     string
	Prompt  string
	Bearer  string
	Headers map[string]string
}

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

type HTTPError struct {
	StatusCode int
	Body       string
}

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.

func (*HTTPError) Error added in v0.0.58

func (e *HTTPError) Error() string

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

func FetchStatus(ctx context.Context, client *http.Client, baseURL string) (*StatusResponse, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL