Files
goclaw/internal/tools/result.go
T
viettranx 0f2737ce53 feat(media): persistent media storage, read_document tool, and pipeline refactor
- Add persistent media storage (internal/media/) replacing temp file deletion
- Add MediaRef type for lightweight media references in session messages
- Refactor media pipeline to use bus.MediaFile{Path, MimeType} across all channels
- Add read_document builtin tool for PDF/DOCX/XLSX analysis via Gemini native API
- Move image sanitization from Telegram to shared agent/media layer
- Add media reload for multi-turn conversations (images from last 5 messages)
- Add reply-to-message media resolution for Telegram (re-download on reply)
- Add media inventory to compaction summary to preserve awareness after truncation
- Fix coreToolSummaries for read_image, read_document, create_image tools
- Add real-time trace update events via WebSocket broadcast
- Improve trace detail UI with media refs and tool result display
2026-03-08 14:00:34 +07:00

56 lines
1.8 KiB
Go

package tools
import (
"github.com/nextlevelbuilder/goclaw/internal/bus"
"github.com/nextlevelbuilder/goclaw/internal/providers"
)
// Result is the unified return type from tool execution.
type Result struct {
ForLLM string `json:"for_llm"` // content sent to the LLM
ForUser string `json:"for_user,omitempty"` // content shown to the user
Silent bool `json:"silent"` // suppress user message
IsError bool `json:"is_error"` // marks error
Async bool `json:"async"` // running asynchronously
Err error `json:"-"` // internal error (not serialized)
// Media holds media files to forward as output (e.g. images from delegation).
Media []bus.MediaFile `json:"-"`
// Deliverable holds the primary work output from this tool execution.
// Used to capture actual content (e.g. written file text, image prompt) for team
// task results instead of relying on the LLM's summary response.
Deliverable string `json:"-"`
// Usage holds token usage from tools that make internal LLM calls (e.g. read_image).
// When set, the agent loop records these on the tool span for tracing.
Usage *providers.Usage `json:"-"`
Provider string `json:"-"` // provider name (for tool span metadata)
Model string `json:"-"` // model used (for tool span metadata)
}
func NewResult(forLLM string) *Result {
return &Result{ForLLM: forLLM}
}
func SilentResult(forLLM string) *Result {
return &Result{ForLLM: forLLM, Silent: true}
}
func ErrorResult(message string) *Result {
return &Result{ForLLM: message, IsError: true}
}
func UserResult(content string) *Result {
return &Result{ForLLM: content, ForUser: content}
}
func AsyncResult(message string) *Result {
return &Result{ForLLM: message, Async: true}
}
func (r *Result) WithError(err error) *Result {
r.Err = err
return r
}