base

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: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Ctx                  context.Context
	Config               agents.Config
	ChatCompletionParams openai.ChatCompletionNewParams
	OpenaiClient         openai.Client
	Log                  logger.Logger
	StreamCanceled       bool
	// contains filtered or unexported fields
}

Agent is the shared base agent structure that contains common fields used by all agent types (chat, tools, compressor, structured, etc.)

func NewAgent

func NewAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig openai.ChatCompletionNewParams,
	options ...AgentOption,
) (*Agent, error)

NewAgent creates a new base Agent instance with common initialization logic This function handles the connection initialization and basic setup that all agents need

func (*Agent) AddMessage

func (agent *Agent) AddMessage(message openai.ChatCompletionMessageParamUnion)

AddMessage adds a new message to the agent's message history

func (*Agent) AddMessages added in v1.0.4

func (agent *Agent) AddMessages(messages []openai.ChatCompletionMessageParamUnion)

AddMessages adds multiple messages to the agent's message history

func (*Agent) GenerateCompletion

func (agent *Agent) GenerateCompletion(messages []openai.ChatCompletionMessageParamUnion) (response string, finishReason string, err error)

GenerateCompletion executes a chat completion with the provided messages and returns the response, finish reason, and any error

func (*Agent) GenerateCompletionWithReasoning

func (agent *Agent) GenerateCompletionWithReasoning(messages []openai.ChatCompletionMessageParamUnion) (response string, reasoning string, finishReason string, err error)

GenerateCompletionWithReasoning executes a chat completion with the provided messages and returns both the response and reasoning content

func (*Agent) GenerateStreamCompletion

func (agent *Agent) GenerateStreamCompletion(
	messages []openai.ChatCompletionMessageParamUnion,
	callBack func(partialResponse string, finishReason string) error,
) (response string, finishReason string, err error)

GenerateStreamCompletion executes a streaming chat completion with the provided messages The callback is called for each chunk of the response

func (*Agent) GenerateStreamCompletionWithReasoning

func (agent *Agent) GenerateStreamCompletionWithReasoning(
	messages []openai.ChatCompletionMessageParamUnion,
	reasoningCallback func(partialReasoning string, finishReason string) error,
	responseCallback func(partialResponse string, finishReason string) error,
) (response string, reasoning string, finishReason string, err error)

GenerateStreamCompletionWithReasoning executes a streaming chat completion with reasoning support It calls reasoningCallback for reasoning chunks and responseCallback for response chunks

func (*Agent) GetContext added in v1.2.2

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

GetContext returns the agent's context

func (*Agent) GetCurrentContextSize

func (agent *Agent) GetCurrentContextSize() int

GetCurrentContextSize calculates the total size of the current context by summing the length of all message contents plus the system instructions

func (*Agent) GetLastRequestRawJSON added in v1.1.2

func (agent *Agent) GetLastRequestRawJSON() string

func (*Agent) GetLastRequestSON added in v1.1.2

func (agent *Agent) GetLastRequestSON() (string, error)

func (*Agent) GetLastResponseJSON

func (agent *Agent) GetLastResponseJSON() (string, error)

func (*Agent) GetLastResponseRawJSON added in v1.1.2

func (agent *Agent) GetLastResponseRawJSON() string

func (*Agent) GetMessages

func (agent *Agent) GetMessages() []openai.ChatCompletionMessageParamUnion

GetMessages returns the current message history

func (*Agent) GetStringMessages

func (agent *Agent) GetStringMessages() []messages.Message

GetStringMessages converts all messages to a slice of Message with role and content as strings

func (*Agent) RemoveLastNMessages

func (agent *Agent) RemoveLastNMessages(n int)

RemoveLastNMessages removes the last N messages from the agent's message history It will not remove the system message (first message) if it exists

func (*Agent) ResetMessages

func (agent *Agent) ResetMessages()

ResetMessages clears the agent's message history except for the initial system message

func (*Agent) SaveLastChunkResponse added in v1.1.2

func (agent *Agent) SaveLastChunkResponse(completion *openai.ChatCompletionChunk) error

SaveLastChunkResponse stores the last chunk response JSON for telemetry or debugging

func (*Agent) SaveLastRequest added in v1.1.2

func (agent *Agent) SaveLastRequest() error

SaveLastRequest stores the last request JSON for telemetry or debugging

func (*Agent) SaveLastResponse added in v1.1.2

func (agent *Agent) SaveLastResponse(completion *openai.ChatCompletion) error

SaveLastResponse stores the last response JSON for telemetry or debugging

func (*Agent) SetContext added in v1.2.2

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

SetContext updates the agent's context

func (*Agent) SetSystemInstructions

func (agent *Agent) SetSystemInstructions(instructions string)

SetSystemInstructions updates the system instructions for the agent If a system message already exists as the first message, it will be replaced Otherwise, a new system message will be prepended to the message list

func (*Agent) StopStream

func (agent *Agent) StopStream()

StopStream interrupts the current streaming operation

type AgentOption

type AgentOption func(*Agent)

AgentOption is a functional option for configuring an Agent

Jump to

Keyboard shortcuts

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