agent

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package agent provides the AI agent runtime for omniagent.

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 is the AI agent that processes messages.

func New

func New(config Config) (*Agent, error)

New creates a new agent.

func (*Agent) Close

func (a *Agent) Close() error

Close closes the agent and releases resources.

func (*Agent) GetSkills added in v0.3.0

func (a *Agent) GetSkills() []*skills.Skill

GetSkills returns the loaded skills.

func (*Agent) LoadSkills added in v0.3.0

func (a *Agent) LoadSkills(dirs []string) error

LoadSkills loads skills from the given directories.

func (*Agent) Process

func (a *Agent) Process(ctx context.Context, sessionID, content string) (string, error)

Process processes a message and returns a response.

func (*Agent) ProcessWithMemory

func (a *Agent) ProcessWithMemory(ctx context.Context, sessionID, content string) (string, error)

ProcessWithMemory processes a message using conversation memory.

func (*Agent) RegisterTool

func (a *Agent) RegisterTool(tool Tool)

RegisterTool registers a tool with the agent.

type BaseTool

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

BaseTool provides a base implementation for tools.

func NewBaseTool

func NewBaseTool(name, description string, parameters map[string]interface{}, handler func(ctx context.Context, args json.RawMessage) (string, error)) *BaseTool

NewBaseTool creates a new base tool.

func (*BaseTool) Description

func (t *BaseTool) Description() string

func (*BaseTool) Execute

func (t *BaseTool) Execute(ctx context.Context, args json.RawMessage) (string, error)

func (*BaseTool) Name

func (t *BaseTool) Name() string

func (*BaseTool) Parameters

func (t *BaseTool) Parameters() map[string]interface{}

type Config

type Config struct {
	Provider          string
	Model             string
	APIKey            string //nolint:gosec // G117: APIKey is intentionally stored for provider authentication
	BaseURL           string
	Temperature       float64
	MaxTokens         int
	SystemPrompt      string
	Logger            *slog.Logger
	ObservabilityHook omnillm.ObservabilityHook
}

Config configures the agent.

type SearchArgs

type SearchArgs struct {
	Query string `json:"query"`
	Type  string `json:"type,omitempty"` // "web", "news", "images" (default: "web")
}

SearchArgs are the arguments for the search tool.

type SearchTool

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

SearchTool provides web search capabilities via omniserp.

func NewSearchTool

func NewSearchTool() (*SearchTool, error)

NewSearchTool creates a new search tool.

func (*SearchTool) Description

func (t *SearchTool) Description() string

func (*SearchTool) Execute

func (t *SearchTool) Execute(ctx context.Context, argsJSON json.RawMessage) (string, error)

func (*SearchTool) Name

func (t *SearchTool) Name() string

func (*SearchTool) Parameters

func (t *SearchTool) Parameters() map[string]interface{}

type Session

type Session struct {
	ID        string
	Messages  []provider.Message
	CreatedAt time.Time
	UpdatedAt time.Time
	Metadata  map[string]interface{}
	// contains filtered or unexported fields
}

Session represents a conversation session.

func (*Session) AddMessage

func (sess *Session) AddMessage(role provider.Role, content string)

AddMessage adds a message to the session.

func (*Session) Clear

func (sess *Session) Clear()

Clear removes all messages from the session.

func (*Session) GetMessages

func (sess *Session) GetMessages() []provider.Message

GetMessages returns all messages in the session.

func (*Session) GetMetadata

func (sess *Session) GetMetadata(key string) (interface{}, bool)

GetMetadata gets a metadata value.

func (*Session) SetMetadata

func (sess *Session) SetMetadata(key string, value interface{})

SetMetadata sets a metadata value.

func (*Session) Trim

func (sess *Session) Trim(n int)

Trim keeps only the last n messages.

type SessionStore

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

SessionStore manages conversation sessions.

func NewSessionStore

func NewSessionStore() *SessionStore

NewSessionStore creates a new session store.

func (*SessionStore) Delete

func (s *SessionStore) Delete(id string)

Delete removes a session.

func (*SessionStore) Get

func (s *SessionStore) Get(id string) *Session

Get retrieves a session by ID, creating one if it doesn't exist.

func (*SessionStore) List

func (s *SessionStore) List() []string

List returns all session IDs.

type Tool

type Tool interface {
	// Name returns the tool name.
	Name() string
	// Description returns a description of what the tool does.
	Description() string
	// Parameters returns the JSON schema for the tool parameters.
	Parameters() map[string]interface{}
	// Execute runs the tool with the given arguments.
	Execute(ctx context.Context, args json.RawMessage) (string, error)
}

Tool represents an agent tool that can be invoked.

type ToolNotFoundError

type ToolNotFoundError struct {
	Name string
}

ToolNotFoundError is returned when a tool is not found.

func (*ToolNotFoundError) Error

func (e *ToolNotFoundError) Error() string

type ToolRegistry

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

ToolRegistry manages available tools.

func NewToolRegistry

func NewToolRegistry() *ToolRegistry

NewToolRegistry creates a new tool registry.

func (*ToolRegistry) Execute

func (r *ToolRegistry) Execute(ctx context.Context, name string, args json.RawMessage) (string, error)

Execute runs a tool by name with the given arguments.

func (*ToolRegistry) Get

func (r *ToolRegistry) Get(name string) (Tool, bool)

Get retrieves a tool by name.

func (*ToolRegistry) GetTools

func (r *ToolRegistry) GetTools() []provider.Tool

GetTools returns tool definitions for the LLM.

func (*ToolRegistry) List

func (r *ToolRegistry) List() []string

List returns all registered tool names.

func (*ToolRegistry) Register

func (r *ToolRegistry) Register(tool Tool)

Register adds a tool to the registry.

func (*ToolRegistry) Unregister

func (r *ToolRegistry) Unregister(name string)

Unregister removes a tool from the registry.

Jump to

Keyboard shortcuts

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