chat

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 10 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 {
	// contains filtered or unexported fields
}

Agent represents a simplified chat agent that hides OpenAI SDK details

func NewAgent

func NewAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig models.Config,
	opts ...ChatAgentOption,
) (*Agent, error)

NewAgent creates a new simplified chat agent

func (*Agent) AddMessage

func (agent *Agent) AddMessage(role roles.Role, content string)

AddMessage adds a message to the conversation history

func (*Agent) AddMessages added in v1.0.4

func (agent *Agent) AddMessages(msgs []messages.Message)

AddMessages adds multiple messages to the conversation history

func (*Agent) ExportMessagesToJSON

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

ExportMessagesToJSON exports the conversation history to JSON

func (*Agent) GenerateCompletion

func (agent *Agent) GenerateCompletion(userMessages []messages.Message) (*CompletionResult, error)

GenerateCompletion sends messages and returns the completion result

func (*Agent) GenerateCompletionWithReasoning

func (agent *Agent) GenerateCompletionWithReasoning(userMessages []messages.Message) (*ReasoningResult, error)

GenerateCompletionWithReasoning sends messages and returns the completion result with reasoning

func (*Agent) GenerateStreamCompletion

func (agent *Agent) GenerateStreamCompletion(
	userMessages []messages.Message,
	callback StreamCallback,
) (*CompletionResult, error)

GenerateStreamCompletion sends messages and streams the response via callback

func (*Agent) GenerateStreamCompletionWithReasoning

func (agent *Agent) GenerateStreamCompletionWithReasoning(
	userMessages []messages.Message,
	reasoningCallback StreamCallback,
	responseCallback StreamCallback,
) (*ReasoningResult, error)

GenerateStreamCompletionWithReasoning sends messages and streams both reasoning and response

func (*Agent) GetConfig added in v1.0.8

func (agent *Agent) GetConfig() agents.Config

GetConfig returns the agent configuration

func (*Agent) GetContext added in v1.2.2

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

GetContext returns the agent's context

func (*Agent) GetContextSize

func (agent *Agent) GetContextSize() int

GetContextSize returns the approximate size of the current context

func (*Agent) GetLastRequestJSON added in v1.0.2

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

func (*Agent) GetLastRequestRawJSON added in v1.1.2

func (agent *Agent) GetLastRequestRawJSON() string

func (*Agent) GetLastResponseJSON added in v1.0.2

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() []messages.Message

GetMessages returns all conversation messages

func (*Agent) GetModelConfig added in v1.0.8

func (agent *Agent) GetModelConfig() models.Config

GetModelConfig returns the model configuration

func (*Agent) GetModelID added in v0.0.7

func (agent *Agent) GetModelID() string

func (*Agent) GetName added in v0.0.3

func (agent *Agent) GetName() string

func (*Agent) GetUserMessagePostDirectives added in v1.2.4

func (agent *Agent) GetUserMessagePostDirectives() string

GetUserMessagePostDirectives returns the user message post-directives

func (*Agent) GetUserMessagePreDirectives added in v1.2.4

func (agent *Agent) GetUserMessagePreDirectives() string

GetUserMessagePreDirectives returns the user message pre-directives

func (*Agent) Kind

func (agent *Agent) Kind() agents.Kind

Kind returns the agent type

func (*Agent) RemoveLastNMessages added in v1.0.2

func (agent *Agent) RemoveLastNMessages(n int)

RemoveLastNMessages removes the last N messages from the conversation history It will not remove the system message

func (*Agent) ResetMessages

func (agent *Agent) ResetMessages()

ResetMessages clears all messages except the system instruction

func (*Agent) SetConfig added in v1.0.8

func (agent *Agent) SetConfig(config agents.Config)

SetConfig updates the agent configuration

func (*Agent) SetContext added in v1.2.2

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

SetContext updates the agent's context

func (*Agent) SetModelConfig added in v1.0.8

func (agent *Agent) SetModelConfig(config models.Config)

SetModelConfig updates the model configuration Note: This updates the stored config but doesn't regenerate the internal OpenAI params For most parameters to take effect, create a new agent with the new config

func (*Agent) SetSystemInstructions added in v1.0.2

func (agent *Agent) SetSystemInstructions(instructions string)

SetSystemInstructions updates the system instructions for the agent

func (*Agent) SetUserMessagePostDirectives added in v1.2.4

func (agent *Agent) SetUserMessagePostDirectives(directives string)

SetUserMessagePostDirectives sets the user message post-directives

func (*Agent) SetUserMessagePreDirectives added in v1.2.4

func (agent *Agent) SetUserMessagePreDirectives(directives string)
IMPORTANT:

Why having user message pre and post directives? These directives can be used to consistently frame user messages, providing context or instructions that apply to every user input. This helps guide the agent's responses in a more controlled manner.

SetUserMessagePreDirectives sets the user message pre-directives

func (*Agent) StopStream

func (agent *Agent) StopStream()

StopStream interrupts the current streaming operation

type AgentOption

type AgentOption func(*BaseAgent)

type BaseAgent

type BaseAgent struct {
	*base.Agent
}

BaseAgent wraps the shared base.Agent for chat-specific functionality

func NewBaseAgent

func NewBaseAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig openai.ChatCompletionNewParams,
	options ...AgentOption,
) (chatAgent *BaseAgent, err error)

NewBaseAgent creates a new ChatAgent instance using the shared base agent

func (*BaseAgent) Kind

func (agent *BaseAgent) Kind() (kind agents.Kind)

type ChatAgentOption added in v1.2.9

type ChatAgentOption func(*Agent)

ChatAgentOption is a functional option for configuring an Agent during creation

func AfterCompletion added in v1.2.9

func AfterCompletion(fn func(*Agent)) ChatAgentOption

AfterCompletion sets a hook that is called after each completion (standard and streaming)

func BeforeCompletion added in v1.2.9

func BeforeCompletion(fn func(*Agent)) ChatAgentOption

BeforeCompletion sets a hook that is called before each completion (standard and streaming)

type CompletionResult

type CompletionResult struct {
	Response     string
	FinishReason string
}

CompletionResult represents the result of a chat completion

type ReasoningResult

type ReasoningResult struct {
	Response     string
	Reasoning    string
	FinishReason string
}

ReasoningResult represents the result of a chat completion with reasoning

type StreamCallback

type StreamCallback func(chunk string, finishReason string) error

StreamCallback is a function called for each chunk of streaming response

Jump to

Keyboard shortcuts

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