Documentation
¶
Index ¶
- type Agent
- func (agent *Agent) AddMessage(message openai.ChatCompletionMessageParamUnion)
- func (agent *Agent) AddMessages(messages []openai.ChatCompletionMessageParamUnion)
- func (agent *Agent) GenerateCompletion(messages []openai.ChatCompletionMessageParamUnion) (response string, finishReason string, err error)
- func (agent *Agent) GenerateCompletionWithReasoning(messages []openai.ChatCompletionMessageParamUnion) (response string, reasoning string, finishReason string, err error)
- func (agent *Agent) GenerateStreamCompletion(messages []openai.ChatCompletionMessageParamUnion, ...) (response string, finishReason string, err error)
- func (agent *Agent) GenerateStreamCompletionWithReasoning(messages []openai.ChatCompletionMessageParamUnion, ...) (response string, reasoning string, finishReason string, err error)
- func (agent *Agent) GetContext() context.Context
- func (agent *Agent) GetCurrentContextSize() int
- func (agent *Agent) GetLastRequestRawJSON() string
- func (agent *Agent) GetLastRequestSON() (string, error)
- func (agent *Agent) GetLastResponseJSON() (string, error)
- func (agent *Agent) GetLastResponseRawJSON() string
- func (agent *Agent) GetMessages() []openai.ChatCompletionMessageParamUnion
- func (agent *Agent) GetStringMessages() []messages.Message
- func (agent *Agent) RemoveLastNMessages(n int)
- func (agent *Agent) ResetMessages()
- func (agent *Agent) SaveLastChunkResponse(completion *openai.ChatCompletionChunk) error
- func (agent *Agent) SaveLastRequest() error
- func (agent *Agent) SaveLastResponse(completion *openai.ChatCompletion) error
- func (agent *Agent) SetContext(ctx context.Context)
- func (agent *Agent) SetSystemInstructions(instructions string)
- func (agent *Agent) StopStream()
- type AgentOption
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
GetContext returns the agent's context
func (*Agent) GetCurrentContextSize ¶
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) GetLastRequestSON ¶ added in v1.1.2
func (*Agent) GetLastResponseJSON ¶
func (*Agent) GetLastResponseRawJSON ¶ added in v1.1.2
func (*Agent) GetMessages ¶
func (agent *Agent) GetMessages() []openai.ChatCompletionMessageParamUnion
GetMessages returns the current message history
func (*Agent) GetStringMessages ¶
GetStringMessages converts all messages to a slice of Message with role and content as strings
func (*Agent) RemoveLastNMessages ¶
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
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
SetContext updates the agent's context
func (*Agent) SetSystemInstructions ¶
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