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 ¶
- func ParseFactID(v interface{}) (int64, error)
- func ParsePersonID(v interface{}) (int64, error)
- func StripHandleSuffix(name string) string
- type CallContext
- type ImageGenFailure
- type ImageGenFailureKind
- type ImageGenImage
- type ImageGenRequest
- type ImageGenResponse
- type ImageGenerator
- type MemoryOpParams
- type Result
- type ToolExecutor
- func (e *ToolExecutor) ExecuteToolCall(ctx context.Context, cc CallContext, toolName string, arguments string) (result *Result, err error)
- func (e *ToolExecutor) SetAgentLogger(logger *agentlog.Logger)
- func (e *ToolExecutor) SetArtifactRepository(repo storage.ArtifactRepository)
- func (e *ToolExecutor) SetFileStorage(fs *files.FileStorage)
- func (e *ToolExecutor) SetImageGenerator(gen ImageGenerator)
- func (e *ToolExecutor) SetPeopleRepository(repo storage.PeopleRepository)
- func (e *ToolExecutor) SetRAGService(svc *rag.Service)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseFactID ¶
ParseFactID extracts fact ID from string "Fact:123" format or int. Prefers "Fact:123" format, falls back to numeric for backward compatibility.
func ParsePersonID ¶
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
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
// Iteration is the 1-based laplace tool-loop iteration. Recorded on the
// tool_executor span as tool.iteration; zero is acceptable for callers
// outside the laplace loop (none today).
Iteration int
}
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 ImageGenFailure ¶ added in v0.9.0
type ImageGenFailure struct {
Kind ImageGenFailureKind
Text string
Provider string
Cause error
}
ImageGenFailure is the typed error performImageGeneration recovers via errors.As. The agent-side adapter populates Kind/Text/Provider; Cause is the underlying network or context error if any.
func (*ImageGenFailure) Error ¶ added in v0.9.0
func (f *ImageGenFailure) Error() string
func (*ImageGenFailure) Unwrap ¶ added in v0.9.0
func (f *ImageGenFailure) Unwrap() error
type ImageGenFailureKind ¶ added in v0.9.0
type ImageGenFailureKind int
ImageGenFailureKind classifies why an image-generation call did not produce an image. Mirror of imagegen.FailureKind.
const ( // ImageGenKindUnknown is the zero value — never set by a real failure. ImageGenKindUnknown ImageGenFailureKind = iota ImageGenKindTimeout ImageGenKindUpstreamError ImageGenKindTextRefusal ImageGenKindSilentBlockOAI ImageGenKindUnknownNoImages )
func (ImageGenFailureKind) String ¶ added in v0.9.0
func (k ImageGenFailureKind) String() string
String returns the same lower_snake identifiers as imagegen.FailureKind so logs and dashboards line up across the layer boundary.
type ImageGenImage ¶ added in v0.8.0
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
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 *Result, err 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.