agentapisdk

package module
v0.0.0-...-c8da0d6 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 8 Imported by: 2

README

agentapi-sdk-go

GoDoc

Go SDK for the AgentAPI HTTP API.

Install

go get github.com/coder/agentapi-sdk-go

Usage

package main

import (
	"context"
	"fmt"
	"log"

	agentapisdk "github.com/coder/agentapi-sdk-go"
)

func main() {
	ctx := context.Background()

	client, err := agentapisdk.NewClient("http://localhost:3284")
	if err != nil {
		log.Fatal(err)
	}

	// Send a message to the agent.
	_, err = client.PostMessage(ctx, agentapisdk.PostMessageParams{
		Content: "Hello, agent!",
		Type:    agentapisdk.MessageTypeUser,
	})
	if err != nil {
		log.Fatal(err)
	}

	// Check the agent's status.
	status, err := client.GetStatus(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Agent status:", status.Status)

	// Subscribe to server-sent events.
	events, errCh, err := client.SubscribeEvents(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for {
		select {
		case ev, ok := <-events:
			if !ok {
				return
			}
			switch e := ev.(type) {
			case agentapisdk.EventMessageUpdate:
				fmt.Println("Message update:", e.Message)
			case agentapisdk.EventStatusChange:
				fmt.Println("Status change:", e.Status)
			}
		case err, ok := <-errCh:
			if !ok {
				return
			}
			if err != nil {
				log.Fatal(err)
			}
		}
	}
}

Code generation

The gen/ package is auto-generated from the OpenAPI spec using oapi-codegen. See gen/README.md for the exact command.

AgentAPI

See the AgentAPI repository for the full API specification and server documentation.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentStatus

type AgentStatus = gen.AgentStatus

AgentStatus represents the current state of the agent

const (
	// StatusRunning indicates the agent is actively processing
	StatusRunning AgentStatus = gen.Running
	// StatusStable indicates the agent is idle
	StatusStable AgentStatus = gen.Stable
)

Constants for agent status

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

func (*Client) GetMessages

func (c *Client) GetMessages(ctx context.Context) (*GetMessagesResponse, error)

func (*Client) GetStatus

func (c *Client) GetStatus(ctx context.Context) (*GetStatusResponse, error)

func (*Client) PostMessage

func (c *Client) PostMessage(ctx context.Context, body PostMessageParams) (*PostMessageResponse, error)

func (*Client) SubscribeEvents

func (c *Client) SubscribeEvents(ctx context.Context) (chan Event, chan error, error)

type ClientOption

type ClientOption = gen.ClientOption

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the base URL for the client. This is useful when you want to use a different server than the one provided to NewClient.

func WithHTTPClient

func WithHTTPClient(client HTTPDoer) ClientOption

WithHTTPClient allows overriding the default HTTP client. This is useful for testing with mock clients.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn adds a function that will be called to modify each request before sending. This can be used to add headers, modify query parameters, etc.

type ConversationRole

type ConversationRole = gen.ConversationRole

ConversationRole defines the sender of a message (agent or user)

const (
	// RoleAgent is the role assigned to agent messages
	RoleAgent ConversationRole = gen.ConversationRoleAgent
	// RoleUser is the role assigned to user messages
	RoleUser ConversationRole = gen.ConversationRoleUser
)

Constants for conversation roles

type ErrorDetail

type ErrorDetail = gen.ErrorDetail

ErrorDetail provides additional information about an error

type ErrorModel

type ErrorModel = gen.ErrorModel

ErrorModel represents an error returned by the API

type Event

type Event = any

Event represents a server-sent event from the Agent API

type EventMessageUpdate

type EventMessageUpdate = gen.MessageUpdateBody

EventMessageUpdate represents a message update event

type EventStatusChange

type EventStatusChange = gen.StatusChangeBody

EventStatusChange represents a status change event

type EventType

type EventType = string
const (
	EventTypeMessageUpdate EventType = "message_update"
	EventTypeStatusChange  EventType = "status_change"
)

type GetMessagesResponse

type GetMessagesResponse = gen.MessagesResponseBody

type GetStatusResponse

type GetStatusResponse = gen.StatusResponseBody

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is an interface for performing HTTP requests. The standard http.Client implements this interface.

type Message

type Message = gen.Message

Message represents a single message in the conversation

type MessageType

type MessageType = gen.MessageType

MessageType defines the type of message being sent

const (
	// MessageTypeRaw represents raw keystrokes sent to the agent
	MessageTypeRaw MessageType = gen.MessageTypeRaw
	// MessageTypeUser represents a user message
	MessageTypeUser MessageType = gen.MessageTypeUser
)

Constants for message types

type PostMessageParams

type PostMessageParams = gen.PostMessageJSONRequestBody

type PostMessageResponse

type PostMessageResponse = gen.MessageResponseBody

type RequestEditorFn

type RequestEditorFn = gen.RequestEditorFn

RequestEditorFn is a function that modifies HTTP requests before they are sent.

type SubscribeEventsResponse

type SubscribeEventsResponse = gen.SubscribeEventsResponse

Directories

Path Synopsis
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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