serverbase

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONEscape

func JSONEscape(s string) string

JSONEscape escapes a string for safe JSON embedding

Types

type BaseServerAgent

type BaseServerAgent struct {
	ChatAgent        ChatAgent
	ToolsAgent       *tools.Agent
	RagAgent         *rag.Agent
	SimilarityLimit  float64
	MaxSimilarities  int
	ContextSizeLimit int
	CompressorAgent  *compressor.Agent
	Port             string
	Ctx              context.Context
	Log              logger.Logger

	// Pending operations management
	PendingOperations       map[string]*PendingOperation
	OperationsMutex         sync.RWMutex
	StopStreamChan          chan bool
	CurrentNotificationChan chan ToolCallNotification
	NotificationChanMutex   sync.Mutex

	// Custom function executor
	ExecuteFn func(string, string) (string, error)

	// Custom confirmation prompt function (for CLI mode)
	ConfirmationPromptFn func(string, string) tools.ConfirmationResponse
}

BaseServerAgent contains common server agent functionality

func NewBaseServerAgent

func NewBaseServerAgent(ctx context.Context, port string, chatAgent ChatAgent, executeFn func(string, string) (string, error)) *BaseServerAgent

NewBaseServerAgent creates a new base server agent

func (*BaseServerAgent) GetContext added in v1.2.2

func (agent *BaseServerAgent) GetContext() context.Context

GetContext returns the base server agent's context

func (*BaseServerAgent) HandleContextSize added in v1.1.8

func (agent *BaseServerAgent) HandleContextSize(w http.ResponseWriter, r *http.Request)

HandleContextSize handles the tokens count endpoint

func (*BaseServerAgent) HandleHealth

func (agent *BaseServerAgent) HandleHealth(w http.ResponseWriter, r *http.Request)

HandleHealth handles the health check endpoint

func (*BaseServerAgent) HandleMemoryReset

func (agent *BaseServerAgent) HandleMemoryReset(w http.ResponseWriter, r *http.Request)

HandleMemoryReset handles the memory reset endpoint

func (*BaseServerAgent) HandleMessagesList

func (agent *BaseServerAgent) HandleMessagesList(w http.ResponseWriter, r *http.Request)

HandleMessagesList handles the messages list endpoint

func (*BaseServerAgent) HandleModelsInformation

func (agent *BaseServerAgent) HandleModelsInformation(w http.ResponseWriter, r *http.Request)

HandleModelsInformation handles the models information endpoint

func (*BaseServerAgent) HandleOperationCancel

func (agent *BaseServerAgent) HandleOperationCancel(w http.ResponseWriter, r *http.Request)

HandleOperationCancel handles the operation cancellation endpoint

func (*BaseServerAgent) HandleOperationReset

func (agent *BaseServerAgent) HandleOperationReset(w http.ResponseWriter, r *http.Request)

HandleOperationReset handles the operation reset endpoint

func (*BaseServerAgent) HandleOperationValidate

func (agent *BaseServerAgent) HandleOperationValidate(w http.ResponseWriter, r *http.Request)

HandleOperationValidate handles the operation validation endpoint

func (*BaseServerAgent) SetContext added in v1.2.2

func (agent *BaseServerAgent) SetContext(ctx context.Context)

SetContext updates the base server agent's context

type ChatAgent

type ChatAgent interface {
	Kind() agents.Kind
	GetName() string
	GetModelID() string
	GetMessages() []messages.Message
	GetContextSize() int
	StopStream()
	ResetMessages()
	AddMessage(role roles.Role, content string)
	GenerateCompletion(userMessages []messages.Message) (*chat.CompletionResult, error)
	GenerateCompletionWithReasoning(userMessages []messages.Message) (*chat.ReasoningResult, error)
	GenerateStreamCompletion(userMessages []messages.Message, callback chat.StreamCallback) (*chat.CompletionResult, error)
	GenerateStreamCompletionWithReasoning(userMessages []messages.Message, reasoningCallback chat.StreamCallback, responseCallback chat.StreamCallback) (*chat.ReasoningResult, error)
	ExportMessagesToJSON() (string, error)
}

ChatAgent defines the interface for the underlying agent (chat or crew) that will handle the actual message processing

type CompletionRequest

type CompletionRequest struct {
	Data struct {
		Message string `json:"message"`
	} `json:"data"`
}

CompletionRequest represents an HTTP request for chat completion

type ContextSizeResponse added in v1.1.8

type ContextSizeResponse struct {
	MessagesCount   int `json:"messages_count"`
	CharactersCount int `json:"characters_count"`
	Limit           int `json:"limit"`
}

ContextSizeResponse represents the response containing token count information

type MemoryResponse

type MemoryResponse struct {
	Messages []messages.Message `json:"messages"`
}

MemoryResponse represents the response containing conversation history

type OperationRequest

type OperationRequest struct {
	OperationID string `json:"operation_id"`
}

OperationRequest represents an HTTP request for operation management

type PendingOperation

type PendingOperation struct {
	ID           string
	FunctionName string
	Arguments    string
	Response     chan tools.ConfirmationResponse
}

PendingOperation represents a tool call operation awaiting user confirmation

type ServerAgentConfig

type ServerAgentConfig struct {
	ChatAgent        ChatAgent
	ToolsAgent       *tools.Agent
	RagAgent         *rag.Agent
	SimilarityLimit  float64
	MaxSimilarities  int
	ContextSizeLimit int
	CompressorAgent  *compressor.Agent
	ExecuteFn        func(string, string) (string, error)
}

ServerAgentConfig contains common configuration for server agents

type ToolCallNotification

type ToolCallNotification struct {
	OperationID  string
	FunctionName string
	Arguments    string
	Message      string
}

ToolCallNotification represents a notification about a pending tool call

Jump to

Keyboard shortcuts

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