agent

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIClient

type AIClient interface {
	CreateChatCompletion(ctx context.Context, req openai.ChatCompletionRequest) (openai.ChatCompletionResponse, error)
}

AIClient is the AI client interface for the tool-calling loop.

type Agent

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

Agent processes DM/GroupDirect messages through a tool-calling loop.

func New

func New(client AIClient, tools []Tool, cfg Config, logger *slog.Logger) (*Agent, error)

New creates a new Agent.

func (*Agent) Handle

func (a *Agent) Handle(ctx context.Context, msg model.Message) (string, error)

Handle processes an incoming message through the tool-calling loop. Returns the text reply for the user.

type Config

type Config struct {
	// SystemPrompt is a custom system prompt. Empty string = built-in default.
	SystemPrompt string
	// Language is the prompt language ("ru" or "en"). Empty string defaults to "ru".
	Language string
	// Now is the function for obtaining the current time. If nil — time.Now is used.
	Now func() time.Time
	// ListProjects is an optional function that fetches the project list for injection
	// into the system prompt. Lets the model recognise project names even in
	// non-standard phrasing without a mandatory list_projects call.
	// nil — the projects block is not added to the prompt. Errors are logged
	// but do not interrupt processing.
	ListProjects func(ctx context.Context) ([]model.Project, error)
}

Config holds agent parameters.

type Tool

type Tool interface {
	// Name returns the tool name (used in function calling).
	Name() string
	// Description describes the tool's purpose for the model.
	Description() string
	// Parameters returns the JSON schema for the tool parameters.
	Parameters() map[string]any
	// DMOnly returns true if the tool is only available in DM mode (full access).
	// In GroupDirect mode such tools are excluded from the tools set.
	DMOnly() bool
	// Execute runs the tool with the given arguments (JSON string) and returns the result.
	Execute(ctx context.Context, args string) (string, error)
}

Tool describes a single agent tool.

func NewAddProjectAliasTool added in v0.3.0

func NewAddProjectAliasTool(projects model.ProjectService, loc *goI18n.Localizer) Tool

NewAddProjectAliasTool creates the add_project_alias tool.

func NewCancelTaskTool added in v0.3.0

func NewCancelTaskTool(tasks model.TaskService, loc *goI18n.Localizer) Tool

NewCancelTaskTool creates the cancel_task tool.

func NewCompleteTaskTool

func NewCompleteTaskTool(tasks model.TaskService, loc *goI18n.Localizer) Tool

NewCompleteTaskTool creates the complete_task tool.

func NewCreateProjectTool

func NewCreateProjectTool(projects model.ProjectService, loc *goI18n.Localizer) Tool

NewCreateProjectTool creates the create_project tool.

func NewCreateTaskTool

func NewCreateTaskTool(tasks model.TaskService, projects model.ProjectService, dp *dateparse.Dateparser, loc *goI18n.Localizer) Tool

NewCreateTaskTool creates the create_task tool.

func NewGetProjectTool added in v0.3.0

func NewGetProjectTool(projects model.ProjectService, loc *goI18n.Localizer) Tool

NewGetProjectTool creates the get_project tool.

func NewGetTaskTool added in v0.3.0

func NewGetTaskTool(tasks model.TaskService, loc *goI18n.Localizer) Tool

NewGetTaskTool creates the get_task tool.

func NewListProjectsTool

func NewListProjectsTool(projects model.ProjectService, loc *goI18n.Localizer) Tool

NewListProjectsTool creates the list_projects tool.

func NewListTasksTool

func NewListTasksTool(tasks model.TaskService, loc *goI18n.Localizer) Tool

NewListTasksTool creates the list_tasks tool.

func NewMoveTaskTool

func NewMoveTaskTool(tasks model.TaskService, projects model.ProjectService, loc *goI18n.Localizer) Tool

NewMoveTaskTool creates the move_task tool.

func NewRemoveProjectAliasTool added in v0.3.0

func NewRemoveProjectAliasTool(projects model.ProjectService, loc *goI18n.Localizer) Tool

NewRemoveProjectAliasTool creates the remove_project_alias tool.

func NewReopenTaskTool added in v0.3.0

func NewReopenTaskTool(tasks model.TaskService, loc *goI18n.Localizer) Tool

NewReopenTaskTool creates the reopen_task tool.

func NewSearchTasksTool added in v0.3.0

func NewSearchTasksTool(tasks model.TaskService, projects model.ProjectService, dp *dateparse.Dateparser, loc *goI18n.Localizer) Tool

NewSearchTasksTool creates the search_tasks tool.

func NewSetProjectTool

func NewSetProjectTool(projects model.ProjectService, loc *goI18n.Localizer) Tool

NewSetProjectTool creates the set_project tool.

func NewSnoozeTaskTool added in v0.3.0

func NewSnoozeTaskTool(tasks model.TaskService, dp *dateparse.Dateparser, loc *goI18n.Localizer) Tool

NewSnoozeTaskTool creates the snooze_task tool.

func NewUpdateProjectTool added in v0.3.0

func NewUpdateProjectTool(projects model.ProjectService, loc *goI18n.Localizer) Tool

NewUpdateProjectTool creates the update_project tool.

func NewUpdateTaskTool added in v0.3.0

func NewUpdateTaskTool(tasks model.TaskService, dp *dateparse.Dateparser, loc *goI18n.Localizer) Tool

NewUpdateTaskTool creates the update_task tool.

Jump to

Keyboard shortcuts

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