tools

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package tools provides tool execution for the laplaced Telegram bot.

It handles all tool execution for the Laplace agent: - Memory tools: add, update, delete facts - People tools: create, update, delete, merge people - Search tools: search history and people - Model tools: custom LLM calls

The ToolExecutor dispatches tool calls to appropriate handlers and manages access to repositories and services.

Package tools provides tool execution for the laplaced bot. It handles fact management, people management, and search tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFactID

func ParseFactID(v interface{}) (int64, error)

ParseFactID extracts fact ID from string "Fact:123" format or int. Prefers "Fact:123" format, falls back to numeric for backward compatibility.

func ParsePersonID

func ParsePersonID(v interface{}) (int64, error)

ParsePersonID extracts person ID from string "Person:123" format or int. Prefers "Person:123" format, falls back to numeric for backward compatibility.

func StripHandleSuffix added in v0.8.0

func StripHandleSuffix(name string) string

StripHandleSuffix removes a trailing " (@handle)" from a person name and returns the stripped name. Returns "" when nothing was stripped, so callers can tell whether a retry with the new value is worth making.

Types

type CallContext added in v0.8.0

type CallContext struct {
	UserID int64
	// CurrentMessageImages is the image FileParts attached to the current
	// user message. generate_image uses these as default input when the LLM
	// does not pass explicit artifact IDs.
	CurrentMessageImages []openrouter.FilePart
}

CallContext carries execution context needed by individual tool handlers. Some tools (generate_image) need the user's current-message image parts; all tools need UserID for data isolation.

type ImageGenImage added in v0.8.0

type ImageGenImage struct {
	MimeType string
	Data     []byte
}

ImageGenImage is a single generated image (mirrors imagegen.DecodedImage).

type ImageGenRequest added in v0.8.0

type ImageGenRequest struct {
	UserID      int64
	Prompt      string
	InputImages []openrouter.FilePart
	AspectRatio string
	ImageSize   string
}

ImageGenRequest mirrors imagegen.Request using types local to this package. The bot-level wiring adapts between this type and the agent's own Request type.

type ImageGenResponse added in v0.8.0

type ImageGenResponse struct {
	Images      []ImageGenImage
	TextContent string
}

ImageGenResponse mirrors imagegen.Response.

type ImageGenerator added in v0.8.0

type ImageGenerator interface {
	Generate(ctx context.Context, req ImageGenRequest) (*ImageGenResponse, error)
}

ImageGenerator is the narrow interface performImageGeneration needs from the imagegen agent. Kept internal here so tests can substitute without pulling the agent package.

type MemoryOpParams

type MemoryOpParams struct {
	Action     string
	Content    string
	Category   string
	FactType   string
	Reason     string
	Importance int
	FactID     int64
}

MemoryOpParams holds parsed parameters for a memory operation.

func ParseMemoryOpParams

func ParseMemoryOpParams(params map[string]interface{}) (MemoryOpParams, error)

ParseMemoryOpParams extracts operation parameters from a map. Returns error if fact_id is provided but invalid.

type Result added in v0.8.0

type Result struct {
	Content              string
	GeneratedArtifactIDs []int64
}

Result is the richer return type of tool execution. Content is what gets fed back to the LLM; GeneratedArtifactIDs are artifact IDs produced during the call (e.g. by generate_image) for the orchestrator to surface in the final user reply.

type ToolExecutor

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

ToolExecutor handles tool execution for the bot. It dispatches tool calls to appropriate handlers and manages access to repositories and services.

func NewToolExecutor

func NewToolExecutor(
	orClient openrouter.Client,
	factRepo storage.FactRepository,
	factHistoryRepo storage.FactHistoryRepository,
	cfg *config.Config,
	logger *slog.Logger,
) *ToolExecutor

NewToolExecutor creates a new ToolExecutor with required dependencies.

func (*ToolExecutor) ExecuteToolCall

func (e *ToolExecutor) ExecuteToolCall(ctx context.Context, cc CallContext, toolName string, arguments string) (*Result, error)

ExecuteToolCall dispatches tool execution by name. Returns a Result with Content (fed back to the LLM) and any generated artifact IDs (for media-producing tools like generate_image).

func (*ToolExecutor) SetAgentLogger

func (e *ToolExecutor) SetAgentLogger(logger *agentlog.Logger)

SetAgentLogger sets the optional agent logger for Scout logging.

func (*ToolExecutor) SetArtifactRepository added in v0.8.0

func (e *ToolExecutor) SetArtifactRepository(repo storage.ArtifactRepository)

SetArtifactRepository wires the artifact repository. Required for the generate_image tool (to persist generated images).

func (*ToolExecutor) SetFileStorage added in v0.8.0

func (e *ToolExecutor) SetFileStorage(fs *files.FileStorage)

SetFileStorage wires the file storage. Required for the generate_image tool (to save output PNGs to disk with hashing/dedup).

func (*ToolExecutor) SetImageGenerator added in v0.8.0

func (e *ToolExecutor) SetImageGenerator(gen ImageGenerator)

SetImageGenerator wires the image-generation agent. Required for the generate_image tool; without it the tool returns a configuration error.

func (*ToolExecutor) SetPeopleRepository

func (e *ToolExecutor) SetPeopleRepository(repo storage.PeopleRepository)

SetPeopleRepository sets the optional people repository.

func (*ToolExecutor) SetRAGService

func (e *ToolExecutor) SetRAGService(svc *rag.Service)

SetRAGService sets the optional RAG service for search tools.

Jump to

Keyboard shortcuts

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