agent

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSupported = errors.New("not supported")
)

Functions

func ContextClient

func ContextClient(ctx context.Context, defaultClient llm.ChatCompletionClient) llm.ChatCompletionClient

func ContextError

func ContextError(ctx context.Context) error

func ContextMessages

func ContextMessages(ctx context.Context, defaultMessages []llm.Message) []llm.Message

func ContextSeed

func ContextSeed(ctx context.Context, defaultSeed int) int

func ContextTemperature

func ContextTemperature(ctx context.Context, defaultTemperature float64) float64

func ContextTools

func ContextTools(ctx context.Context, defaultTools []llm.Tool) []llm.Tool

func ContextValue

func ContextValue[T any](ctx context.Context, key ContextKey, defaultValue T) T

func WithContextAgent

func WithContextAgent(ctx context.Context, agent *Agent) context.Context

func WithContextClient

func WithContextClient(ctx context.Context, client llm.ChatCompletionClient) context.Context

func WithContextError

func WithContextError(ctx context.Context, err error) context.Context

func WithContextMessages

func WithContextMessages(ctx context.Context, messages []llm.Message) context.Context

func WithContextSeed

func WithContextSeed(ctx context.Context, seed int) context.Context

func WithContextTemperature

func WithContextTemperature(ctx context.Context, temperature float64) context.Context

func WithContextTools

func WithContextTools(ctx context.Context, tools []llm.Tool) context.Context

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent is a thread-safe version of the Agent that eliminates race conditions

func ContextAgent

func ContextAgent(ctx context.Context) *Agent

func New

func New(handler Handler, opts ...Option) *Agent

New creates a new thread-safe agent

func (*Agent) Err

func (a *Agent) Err() <-chan error

Err returns a read-only channel for receiving agent errors.

func (*Agent) In

func (a *Agent) In(evt Event) error

In sends an event to the agent for processing

func (*Agent) IsRunning

func (a *Agent) IsRunning() bool

IsRunning returns true if the agent is currently running

func (*Agent) Output

func (a *Agent) Output() <-chan Event

Output returns a read-only channel for receiving agent outputs

func (*Agent) Start

func (a *Agent) Start(ctx context.Context) (<-chan Event, <-chan error, error)

Start starts the agent and processes events until the context is cancelled

func (*Agent) Stop

func (a *Agent) Stop() error

Stop gracefully stops the agent

type BaseMessageEvent

type BaseMessageEvent struct {
	// contains filtered or unexported fields
}

func NewMessageEvent

func NewMessageEvent(ctx context.Context, message string) *BaseMessageEvent

NewMessageEvent creates a new BaseMessageEvent.

func (*BaseMessageEvent) Context

func (e *BaseMessageEvent) Context() context.Context

Context implements MessageEvent.

func (*BaseMessageEvent) ID

func (e *BaseMessageEvent) ID() EventID

ID implements MessageEvent.

func (*BaseMessageEvent) Message

func (e *BaseMessageEvent) Message() string

Message implements the MessageEvent interface.

func (*BaseMessageEvent) WithContext

func (e *BaseMessageEvent) WithContext(ctx context.Context) Event

WithContext implements MessageEvent.

type ContextKey

type ContextKey string
const (
	ContextKeyAgent       ContextKey = "agent"
	ContextKeyClient      ContextKey = "client"
	ContextKeyTools       ContextKey = "tools"
	ContextKeyMessages    ContextKey = "messages"
	ContextKeyTemperature ContextKey = "temperature"
	ContextKeySeed        ContextKey = "seed"
	ContextKeyError       ContextKey = "error"
)

type Event

type Event interface {
	ID() EventID
	Context() context.Context
	WithContext(ctx context.Context) Event
}

type EventID

type EventID string

func NewEventID

func NewEventID() EventID

type Handler

type Handler interface {
	Handle(input Event, outputs chan Event) error
}

type HandlerFunc

type HandlerFunc func(input Event, outputs chan Event) error

func (HandlerFunc) Handle

func (fn HandlerFunc) Handle(input Event, outputs chan Event) error

type MessageEvent

type MessageEvent interface {
	Event
	Message() string
}

MessageEvent represents an event that carries a string message.

type Middleware

type Middleware func(next Handler) Handler

type Option

type Option func(*Options)

func WithConcurrentHandlers

func WithConcurrentHandlers(size int) Option

func WithErrorChanSize

func WithErrorChanSize(size int) Option

func WithHandlerContextCancelOnDone

func WithHandlerContextCancelOnDone(cancel bool) Option

func WithHandlerOutputChanSize

func WithHandlerOutputChanSize(size int) Option

func WithInputChanSize

func WithInputChanSize(size int) Option

func WithInputTimeout

func WithInputTimeout(timeout time.Duration) Option

func WithMiddlewares

func WithMiddlewares(middlewares ...Middleware) Option

func WithOutputChanSize

func WithOutputChanSize(size int) Option

func WithOutputChannelTicker

func WithOutputChannelTicker(ticker time.Duration) Option

func WithOutputChannelTimeout

func WithOutputChannelTimeout(timeout time.Duration) Option

type Options

type Options struct {
	InputChanSize              int
	OutputChanSize             int
	ErrorChanSize              int
	HandlerOutputChanSize      int
	ConcurrentHandlers         int
	OutputChannelTimeout       time.Duration
	OutputChannelTicker        time.Duration
	HandlerContextCancelOnDone bool
	InputTimeout               time.Duration
	Middlewares                []Middleware
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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