agents

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package agents defines the provider interface SuperPlane uses to talk to managed-agent backends, and a service layer that persists sessions and routes streamed events through the event distributor.

Index

Constants

This section is empty.

Variables

View Source
var ErrProviderSessionUnavailable = errors.New("provider session is unavailable")
View Source
var ErrSessionAlreadyTerminated = errors.New("agent session already terminated")
View Source
var ErrSessionBusy = errors.New("agent session is still processing")
View Source
var ErrSessionForbidden = errors.New("agent session is owned by another user")

Functions

func AgentTokenPermissions added in v0.26.0

func AgentTokenPermissions(canvasID string) []jwt.Permission

func AgentTokenScopes added in v0.26.0

func AgentTokenScopes(canvasID string) []string

Types

type AgentSessionContext added in v0.26.0

type AgentSessionContext struct {
	SessionID         string
	ProviderSessionID string
	OrganizationID    string
	UserID            string
	CanvasID          string
}

type CreateSessionOptions

type CreateSessionOptions struct {
	InitialContext string
	Title          string
	VaultIDs       []string
	Resources      []FileResource
}

type CreateSessionResult

type CreateSessionResult struct {
	ProviderSessionID string
}

type CustomToolExecutor added in v0.26.0

type CustomToolExecutor interface {
	ExecuteCustomTool(ctx context.Context, session AgentSessionContext, toolUse CustomToolUse) CustomToolResult
}

type CustomToolInputSchema added in v0.26.0

type CustomToolInputSchema struct {
	Type        string                           `json:"type"`
	Description string                           `json:"description,omitempty"`
	Enum        []string                         `json:"enum,omitempty"`
	Properties  map[string]CustomToolInputSchema `json:"properties,omitempty"`
	Items       *CustomToolInputSchema           `json:"items,omitempty"`
	Required    []string                         `json:"required,omitempty"`
}

func (CustomToolInputSchema) Map added in v0.26.0

func (s CustomToolInputSchema) Map() map[string]any

type CustomToolResult added in v0.26.0

type CustomToolResult struct {
	CustomToolUseID string
	Content         string
	IsError         bool
}

type CustomToolResultSender added in v0.26.0

type CustomToolResultSender interface {
	SendCustomToolResults(ctx context.Context, providerSessionID string, results []CustomToolResult) error
}

type CustomToolUse added in v0.26.0

type CustomToolUse struct {
	ID    string
	Name  string
	Input string
}

type DefineOutcomeOptions added in v0.22.0

type DefineOutcomeOptions struct {
	// Description is the user-visible goal the provider should work toward.
	Description string
	// Rubric is the grader-facing checklist evaluated after each iteration.
	Rubric string
	// MaxIterations caps the provider's autonomous build/evaluate loop.
	MaxIterations int
	// ContextPreamble is prepended to the description so provider-managed
	// autonomous loops get the same refreshed session context as normal turns.
	ContextPreamble string
}

type FileResource added in v0.22.0

type FileResource struct {
	FileID    string
	MountPath string
}

type MessageImage added in v0.26.0

type MessageImage struct {
	MediaType string
	Data      string
}

type Mode added in v0.22.0

type Mode string
const (
	ModeBuilder  Mode = "builder"
	ModeOperator Mode = "operator"
)

func NormalizeMode added in v0.22.0

func NormalizeMode(raw string) Mode

type OutcomeEvaluation added in v0.22.0

type OutcomeEvaluation struct {
	Iteration   int
	Result      string // "satisfied", "needs_revision", "max_iterations_reached", "failed", "interrupted"
	Explanation string // grader's prose verdict
}

type Provider

type Provider interface {
	Name() string
	CreateSession(ctx context.Context, opts CreateSessionOptions) (*CreateSessionResult, error)
	SendMessage(ctx context.Context, providerSessionID, message string, opts SendMessageOptions) error
	InterruptSession(ctx context.Context, providerSessionID string) error
	// DefineOutcome starts a rubric-driven execution loop on the provider side.
	DefineOutcome(ctx context.Context, providerSessionID string, opts DefineOutcomeOptions) error
	// StreamEvents blocks until the provider closes the stream, ctx is
	// cancelled, or onEvent errors. Implementations must not call onEvent
	// after returning.
	StreamEvents(ctx context.Context, providerSessionID string, onEvent func(ProviderEvent) error) error
}

type ProviderEvent

type ProviderEvent struct {
	ProviderEventID string
	Type            ProviderEventType
	Text            string
	Model           string
	ToolName        string
	ToolCallID      string
	// ToolInput is a human-readable rendering of the tool's invocation
	// (e.g. the shell command for bash, or compact JSON for other tools).
	ToolInput          string
	ErrorMessage       string
	OutcomeResult      *OutcomeEvaluation
	CustomToolUse      *CustomToolUse
	CustomToolEventIDs []string

	// Multi-agent thread fields
	AgentName string
	ThreadID  string

	Usage *TokenUsage
}

type ProviderEventType

type ProviderEventType string
const (
	ProviderEventAssistantMessage          ProviderEventType = "assistant_message"
	ProviderEventToolUseStarted            ProviderEventType = "tool_use_started"
	ProviderEventToolUseFinished           ProviderEventType = "tool_use_finished"
	ProviderEventCustomToolUseStarted      ProviderEventType = "custom_tool_use_started"
	ProviderEventCustomToolResultsRequired ProviderEventType = "custom_tool_results_required"
	ProviderEventTurnCompleted             ProviderEventType = "turn_completed"
	ProviderEventSessionFailed             ProviderEventType = "session_failed"
	// Recoverable provider error; the session keeps running.
	ProviderEventSessionNotice          ProviderEventType = "session_notice"
	ProviderEventOutcomeEvaluation      ProviderEventType = "outcome_evaluation"
	ProviderEventOutcomeEvaluationStart ProviderEventType = "outcome_evaluation_start"
	ProviderEventThreadMessageSent      ProviderEventType = "thread_message_sent"
	ProviderEventThreadMessageReceived  ProviderEventType = "thread_message_received"
)

type ProviderSessionArchiver added in v0.26.0

type ProviderSessionArchiver interface {
	Name() string
	ArchiveSession(ctx context.Context, providerSessionID string) error
}

type ProviderSessionCleaner

type ProviderSessionCleaner interface {
	Name() string
	DeleteSession(ctx context.Context, providerSessionID string) error
}

type ProviderSessionUsageRetriever added in v0.27.0

type ProviderSessionUsageRetriever interface {
	RetrieveSessionUsage(ctx context.Context, providerSessionID string) (*TokenUsage, error)
}

type ProviderToolSchemaRevisioner added in v0.26.0

type ProviderToolSchemaRevisioner interface {
	Name() string
	ToolSchemaRevision() string
}

type SendMessageOptions

type SendMessageOptions struct {
	ContextPreamble string
	Images          []MessageImage
}

SendMessageOptions.ContextPreamble is prepended to the user's message so providers that need caller context inline (e.g. the canvas/session identifiers) receive it without a separate system message.

type Service

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

func NewService

func NewService(provider Provider, auth authorization.Authorization) *Service

func (*Service) DefineOutcome added in v0.22.0

func (s *Service) DefineOutcome(ctx context.Context, organizationID, userID, sessionID uuid.UUID, description, rubric string, maxIterations int) error

func (*Service) EnsureSession

func (s *Service) EnsureSession(ctx context.Context, organizationID, userID, canvasID uuid.UUID) (*models.AgentSession, error)

EnsureSession returns the user's single chat session for the given canvas, provisioning it on the upstream provider on first call.

func (*Service) GetSession

func (s *Service) GetSession(organizationID, userID, sessionID uuid.UUID) (*models.AgentSession, error)

func (*Service) InterruptSession added in v0.22.0

func (s *Service) InterruptSession(ctx context.Context, organizationID, userID, sessionID uuid.UUID) error

InterruptSession resets local state first and treats the provider call as best-effort: the worker checks status per event, so flipping to idle before the provider HTTP roundtrip lets late SSE events get dropped during the network wait instead of after.

func (*Service) ListMessages

func (s *Service) ListMessages(sessionID, beforeID uuid.UUID, limit int) ([]models.AgentSessionMessage, error)

func (*Service) ProviderName

func (s *Service) ProviderName() string

func (*Service) ResetSession added in v0.28.0

func (s *Service) ResetSession(ctx context.Context, organizationID, userID, canvasID uuid.UUID) (*models.AgentSession, error)

ResetSession replaces the user's canvas session with a fresh one, used by the `/clear` UX to give the user a new chat with no rewind.

func (*Service) SendMessage

func (s *Service) SendMessage(ctx context.Context, organizationID, userID, sessionID uuid.UUID, content string, images []MessageImage, mode ...string) (*models.AgentSessionMessage, error)

type TokenUsage added in v0.27.0

type TokenUsage struct {
	InputTokens      int64
	OutputTokens     int64
	TotalTokens      int64
	CacheReadTokens  int64
	CacheWriteTokens int64
}

func (TokenUsage) HasUsage added in v0.27.0

func (u TokenUsage) HasUsage() bool

Directories

Path Synopsis
Package anthropic implements agents.Provider against Anthropic's managed-agents API.
Package anthropic implements agents.Provider against Anthropic's managed-agents API.

Jump to

Keyboard shortcuts

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