Documentation
¶
Index ¶
- type CompletionRequest
- type MemoryResponse
- type OperationRequest
- type PendingOperation
- type ServerAgent
- func (agent *ServerAgent) AddMessage(role roles.Role, content string)
- func (agent *ServerAgent) CompressChatAgentContext() (int, error)
- func (agent *ServerAgent) CompressChatAgentContextIfOverLimit() (int, error)
- func (agent *ServerAgent) ExportMessagesToJSON() (string, error)
- func (agent *ServerAgent) GenerateCompletion(userMessages []messages.Message) (*chat.CompletionResult, error)
- func (agent *ServerAgent) GenerateCompletionWithReasoning(userMessages []messages.Message) (*chat.ReasoningResult, error)
- func (agent *ServerAgent) GenerateStreamCompletion(userMessages []messages.Message, callback chat.StreamCallback) (*chat.CompletionResult, error)
- func (agent *ServerAgent) GenerateStreamCompletionWithReasoning(userMessages []messages.Message, reasoningCallback chat.StreamCallback, ...) (*chat.ReasoningResult, error)
- func (agent *ServerAgent) GetContextSize() int
- func (agent *ServerAgent) GetMessages() []messages.Message
- func (agent *ServerAgent) GetModelID() string
- func (agent *ServerAgent) GetName() string
- func (agent *ServerAgent) GetPort() string
- func (agent *ServerAgent) GetTasksAgent() *tasks.Agent
- func (agent *ServerAgent) GetToolsAgent() *tools.Agent
- func (agent *ServerAgent) Kind() agents.Kind
- func (agent *ServerAgent) ResetMessages()
- func (agent *ServerAgent) SetConfirmationPromptFn(fn func(string, string) tools.ConfirmationResponse)
- func (agent *ServerAgent) SetConfirmationPromptFunction(fn func(string, string) tools.ConfirmationResponse)
- func (agent *ServerAgent) SetExecuteFunction(fn func(string, string) (string, error))
- func (agent *ServerAgent) SetPort(port string)
- func (agent *ServerAgent) SetTasksAgent(tasksAgent *tasks.Agent)
- func (agent *ServerAgent) SetToolsAgent(toolsAgent *tools.Agent)
- func (agent *ServerAgent) StartServer() error
- func (agent *ServerAgent) StopStream()
- func (agent *ServerAgent) StreamCompletion(question string, callback chat.StreamCallback) (*chat.CompletionResult, error)
- type ServerAgentOption
- func AfterCompletion(fn func(*ServerAgent)) ServerAgentOption
- func BeforeCompletion(fn func(*ServerAgent)) ServerAgentOption
- func WithCompressorAgent(compressorAgent *compressor.Agent) ServerAgentOption
- func WithCompressorAgentAndContextSize(compressorAgent *compressor.Agent, contextSizeLimit int) ServerAgentOption
- func WithConfirmationPromptFn(fn func(string, string) tools.ConfirmationResponse) ServerAgentOption
- func WithExecuteFn(fn func(string, string) (string, error)) ServerAgentOption
- func WithPort(port int) ServerAgentOption
- func WithRagAgent(ragAgent *rag.Agent) ServerAgentOption
- func WithRagAgentAndSimilarityConfig(ragAgent *rag.Agent, similarityLimit float64, maxSimilarities int) ServerAgentOption
- func WithTLSCert(certData, keyData []byte) ServerAgentOption
- func WithTLSCertFromFile(certPath, keyPath string) ServerAgentOption
- func WithTasksAgent(tasksAgent *tasks.Agent) ServerAgentOption
- func WithToolsAgent(toolsAgent *tools.Agent) ServerAgentOption
- type TokensResponse
- type ToolCallNotification
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompletionRequest ¶
type CompletionRequest = serverbase.CompletionRequest
Re-export types from serverbase for backward compatibility
type MemoryResponse ¶
type MemoryResponse = serverbase.MemoryResponse
Re-export types from serverbase for backward compatibility
type OperationRequest ¶
type OperationRequest = serverbase.OperationRequest
Re-export types from serverbase for backward compatibility
type PendingOperation ¶
type PendingOperation = serverbase.PendingOperation
Re-export types from serverbase for backward compatibility
type ServerAgent ¶
type ServerAgent struct {
*serverbase.BaseServerAgent
// HTTP server multiplexer for custom routes
Mux *http.ServeMux
// contains filtered or unexported fields
}
ServerAgent wraps BaseServerAgent with chat-specific functionality
func NewAgent ¶
func NewAgent( ctx context.Context, agentConfig agents.Config, modelConfig models.Config, options ...ServerAgentOption, ) (*ServerAgent, error)
NewAgent creates a new server agent with options
Available options:
- WithPort(port) - Sets the HTTP server port as int (default: 8080)
- WithExecuteFn(fn) - Sets the custom function executor for tool execution
- WithConfirmationPromptFn(fn) - Sets the confirmation prompt function for human-in-the-loop
- WithTLSCert(certData, keyData) - Enables HTTPS with PEM-encoded certificate and key data
- WithTLSCertFromFile(certPath, keyPath) - Enables HTTPS with certificate and key files
- WithToolsAgent(toolsAgent) - Attaches a tools agent for function calling capabilities
- WithTasksAgent(tasksAgent) - Attaches a tasks agent for task planning and orchestration
- WithCompressorAgent(compressorAgent) - Attaches a compressor agent for context compression
- WithCompressorAgentAndContextSize(compressorAgent, contextSizeLimit) - Attaches a compressor agent and sets the context size limit
- WithRagAgent(ragAgent) - Attaches a RAG agent for document retrieval
- WithRagAgentAndSimilarityConfig(ragAgent, similarityLimit, maxSimilarities) - Attaches a RAG agent and configures similarity settings
- BeforeCompletion(fn) - Sets a hook called before each completion (HTTP and CLI)
- AfterCompletion(fn) - Sets a hook called after each completion (HTTP and CLI)
Example:
agent, err := NewAgent(ctx, agentConfig, modelConfig,
WithPort(8080),
WithToolsAgent(toolsAgent),
WithRagAgent(ragAgent),
)
func (*ServerAgent) AddMessage ¶
func (agent *ServerAgent) AddMessage(role roles.Role, content string)
AddMessage adds a message to the conversation history
func (*ServerAgent) CompressChatAgentContext ¶ added in v0.0.8
func (agent *ServerAgent) CompressChatAgentContext() (int, error)
CompressChatAgentContext compresses the chat agent context unconditionally.
func (*ServerAgent) CompressChatAgentContextIfOverLimit ¶ added in v0.0.8
func (agent *ServerAgent) CompressChatAgentContextIfOverLimit() (int, error)
CompressChatAgentContextIfOverLimit compresses the chat agent context if it exceeds the size limit.
func (*ServerAgent) ExportMessagesToJSON ¶
func (agent *ServerAgent) ExportMessagesToJSON() (string, error)
ExportMessagesToJSON exports the conversation history to JSON
func (*ServerAgent) GenerateCompletion ¶
func (agent *ServerAgent) GenerateCompletion(userMessages []messages.Message) (*chat.CompletionResult, error)
GenerateCompletion sends messages and returns the completion result
func (*ServerAgent) GenerateCompletionWithReasoning ¶
func (agent *ServerAgent) GenerateCompletionWithReasoning(userMessages []messages.Message) (*chat.ReasoningResult, error)
GenerateCompletionWithReasoning sends messages and returns the completion result with reasoning
func (*ServerAgent) GenerateStreamCompletion ¶
func (agent *ServerAgent) GenerateStreamCompletion( userMessages []messages.Message, callback chat.StreamCallback, ) (*chat.CompletionResult, error)
GenerateStreamCompletion sends messages and streams the response via callback
func (*ServerAgent) GenerateStreamCompletionWithReasoning ¶
func (agent *ServerAgent) GenerateStreamCompletionWithReasoning( userMessages []messages.Message, reasoningCallback chat.StreamCallback, responseCallback chat.StreamCallback, ) (*chat.ReasoningResult, error)
GenerateStreamCompletionWithReasoning sends messages and streams both reasoning and response
func (*ServerAgent) GetContextSize ¶
func (agent *ServerAgent) GetContextSize() int
GetContextSize returns the approximate size of the current context
func (*ServerAgent) GetMessages ¶
func (agent *ServerAgent) GetMessages() []messages.Message
GetMessages returns all conversation messages
func (*ServerAgent) GetModelID ¶
func (agent *ServerAgent) GetModelID() string
GetModelID returns the model ID
func (*ServerAgent) GetName ¶
func (agent *ServerAgent) GetName() string
GetName returns the agent name
func (*ServerAgent) GetPort ¶
func (agent *ServerAgent) GetPort() string
GetPort returns the HTTP port
func (*ServerAgent) GetTasksAgent ¶ added in v1.3.7
func (agent *ServerAgent) GetTasksAgent() *tasks.Agent
GetTasksAgent returns the tasks agent
func (*ServerAgent) GetToolsAgent ¶
func (agent *ServerAgent) GetToolsAgent() *tools.Agent
GetToolsAgent returns the tools agent
func (*ServerAgent) ResetMessages ¶
func (agent *ServerAgent) ResetMessages()
ResetMessages clears all messages except the system instruction
func (*ServerAgent) SetConfirmationPromptFn ¶ added in v1.2.1
func (agent *ServerAgent) SetConfirmationPromptFn(fn func(string, string) tools.ConfirmationResponse)
SetConfirmationPromptFn sets the confirmation prompt function for CLI mode
func (*ServerAgent) SetConfirmationPromptFunction ¶ added in v1.2.1
func (agent *ServerAgent) SetConfirmationPromptFunction(fn func(string, string) tools.ConfirmationResponse)
SetConfirmationPromptFunction allows the user to set a custom confirmation prompt function
func (*ServerAgent) SetExecuteFunction ¶
func (agent *ServerAgent) SetExecuteFunction(fn func(string, string) (string, error))
SetExecuteFunction allows the user to set a custom execute function
func (*ServerAgent) SetPort ¶
func (agent *ServerAgent) SetPort(port string)
SetPort sets the HTTP port
func (*ServerAgent) SetTasksAgent ¶ added in v1.3.7
func (agent *ServerAgent) SetTasksAgent(tasksAgent *tasks.Agent)
SetTasksAgent sets the tasks agent
func (*ServerAgent) SetToolsAgent ¶
func (agent *ServerAgent) SetToolsAgent(toolsAgent *tools.Agent)
SetToolsAgent sets the tools agent
func (*ServerAgent) StartServer ¶
func (agent *ServerAgent) StartServer() error
StartServer starts the HTTP server with all routes
func (*ServerAgent) StopStream ¶
func (agent *ServerAgent) StopStream()
StopStream interrupts the current streaming operation
func (*ServerAgent) StreamCompletion ¶ added in v1.2.1
func (agent *ServerAgent) StreamCompletion( question string, callback chat.StreamCallback, ) (*chat.CompletionResult, error)
StreamCompletion processes a question through the server agent pipeline: 1. Compresses context if needed 2. Executes tool calls if detected 3. Adds RAG context if available 4. Generates streaming completion This method mirrors the crew agent's StreamCompletion for CLI usage
type ServerAgentOption ¶ added in v1.2.5
type ServerAgentOption func(*ServerAgent) error
ServerAgentOption is a function that configures a ServerAgent
func AfterCompletion ¶ added in v1.2.9
func AfterCompletion(fn func(*ServerAgent)) ServerAgentOption
AfterCompletion sets a hook that is called after each completion (HTTP and CLI)
func BeforeCompletion ¶ added in v1.2.9
func BeforeCompletion(fn func(*ServerAgent)) ServerAgentOption
BeforeCompletion sets a hook that is called before each completion (HTTP and CLI)
func WithCompressorAgent ¶ added in v1.2.5
func WithCompressorAgent(compressorAgent *compressor.Agent) ServerAgentOption
WithCompressorAgent sets the compressor agent
func WithCompressorAgentAndContextSize ¶ added in v1.2.5
func WithCompressorAgentAndContextSize(compressorAgent *compressor.Agent, contextSizeLimit int) ServerAgentOption
WithCompressorAgentAndContextSize sets the compressor agent and context size limit
func WithConfirmationPromptFn ¶ added in v1.2.5
func WithConfirmationPromptFn(fn func(string, string) tools.ConfirmationResponse) ServerAgentOption
WithConfirmationPromptFn sets the confirmation prompt function
func WithExecuteFn ¶ added in v1.2.5
func WithExecuteFn(fn func(string, string) (string, error)) ServerAgentOption
WithExecuteFn sets the custom function executor
func WithPort ¶ added in v1.2.5
func WithPort(port int) ServerAgentOption
WithPort sets the HTTP server port
func WithRagAgent ¶ added in v1.2.5
func WithRagAgent(ragAgent *rag.Agent) ServerAgentOption
WithRagAgent sets the RAG agent
func WithRagAgentAndSimilarityConfig ¶ added in v1.2.5
func WithRagAgentAndSimilarityConfig(ragAgent *rag.Agent, similarityLimit float64, maxSimilarities int) ServerAgentOption
WithRagAgentAndSimilarityConfig sets the RAG agent, similarity limit and max similarities
func WithTLSCert ¶ added in v1.3.1
func WithTLSCert(certData, keyData []byte) ServerAgentOption
WithTLSCert sets the TLS certificate and key data for HTTPS support. When provided, the server will use HTTPS instead of HTTP. certData and keyData should be PEM-encoded certificate and private key.
func WithTLSCertFromFile ¶ added in v1.3.1
func WithTLSCertFromFile(certPath, keyPath string) ServerAgentOption
WithTLSCertFromFile sets the TLS certificate and key file paths for HTTPS support. When provided, the server will use HTTPS instead of HTTP. certPath and keyPath should point to PEM-encoded certificate and private key files.
func WithTasksAgent ¶ added in v1.3.7
func WithTasksAgent(tasksAgent *tasks.Agent) ServerAgentOption
WithTasksAgent sets the tasks agent for task planning and orchestration. When configured, the agent will first analyze user requests to identify a plan of tasks, then execute each task using either the tools agent (for "tool" tasks) or the chat agent (for "completion"/"developer" tasks), passing results between steps.
func WithToolsAgent ¶ added in v1.2.5
func WithToolsAgent(toolsAgent *tools.Agent) ServerAgentOption
WithToolsAgent sets the tools agent
type TokensResponse ¶
type TokensResponse = serverbase.ContextSizeResponse
Re-export types from serverbase for backward compatibility
type ToolCallNotification ¶
type ToolCallNotification = serverbase.ToolCallNotification
Re-export types from serverbase for backward compatibility