Documentation
¶
Index ¶
- Constants
- Variables
- func AttachSandboxOutputFiles(ctx context.Context, client mmapi.Client, ...)
- func ConsumeCreatedFiles(ctx *llm.Context) []llm.CreatedFile
- func CreateFileContentLimit(cfg *model.Config) int64
- func DecorateStreamWithAnnotations(result *llm.TextStreamResult, searchData []WebSearchContextValue, ...) *llm.TextStreamResult
- func NewAskUserQuestionTool() llm.Tool
- func NewCreateFileTool(client mmapi.Client, htmlArtifacts bool) llm.Tool
- func NewWaitForAsyncWorkTool(schedule ScheduleWake) llm.Tool
- func ResolveUserInteractionAnswer(kind string, input json.RawMessage, answer UserInteractionAnswer) (string, error)
- type AskUserQuestionArgs
- type AskUserQuestionOption
- type AskUserQuestionResult
- type CreateFileArgs
- type CreateFileResult
- type MMToolProvider
- type ScheduleWake
- type ToolProvider
- type UserInteractionAnswer
- type WaitForAsyncWorkArgs
- type WebSearchContextValue
- type WebSearchLog
- type WebSearchResult
- type WebSearchService
- type WebSearchSourceArgs
- type WebSearchToolArgs
Constants ¶
const ( // WebSearchContextKey is the key used within llm.Context.Parameters to store web search results WebSearchContextKey = "mm_web_search_results" // WebSearchAllowedURLsKey is the key used to store whitelisted URLs for source fetching WebSearchAllowedURLsKey = "mm_web_search_allowed_urls" // WebSearchExecutedQueriesKey is the key used to track which queries have been executed WebSearchExecutedQueriesKey = "mm_web_search_executed_queries" // WebSearchCountKey is the key used to track the number of searches executed WebSearchCountKey = "mm_web_search_count" WebSearchDescription = "" /* 680-byte string literal not displayed */ // WebSearchSourceFetchDescription describes the page retrieval tool. WebSearchSourceFetchDescription = "" /* 425-byte string literal not displayed */ )
const (
// AskUserQuestionToolName is the runtime name of the built-in question tool.
AskUserQuestionToolName = "AskUserQuestion"
)
const (
// CreateFileToolName is the runtime name of the built-in file creation tool.
CreateFileToolName = "CreateFile"
)
const (
// WaitForAsyncWorkToolName is the runtime name of the built-in wait tool.
WaitForAsyncWorkToolName = "wait_for_async_work"
)
const WakeCanceledUserMessage = "" /* 332-byte string literal not displayed */
WakeCanceledUserMessage is the synthetic user-turn text recorded when a new message cancels a pending wait. It is written to the invoking conversation, which may not be the one that scheduled the wait, so it stays generic. Like WakeUserMessage it is fixed text.
const WakeUserMessage = "" /* 398-byte string literal not displayed */
WakeUserMessage is the synthetic user-turn text injected when a wait fires. It is a fixed string: the model-supplied reason must never be voiced as the user, so the model recovers it from its own earlier tool result.
Variables ¶
var ErrWaitAlreadyScheduled = errors.New("a wait is already pending in this thread")
ErrWaitAlreadyScheduled is returned by a ScheduleWake when the thread already has a pending wait for this bot.
Functions ¶
func AttachSandboxOutputFiles ¶ added in v2.7.0
func AttachSandboxOutputFiles(ctx context.Context, client mmapi.Client, downloader llm.ProviderFileDownloader, llmCtx *llm.Context)
AttachSandboxOutputFiles uploads sandbox output files captured this turn onto llmCtx for the reply. There is no attach tool: Anthropic reports ids only for files left in $OUTPUT_DIR, which is the model's share gesture, and those ids are never shown to the model. Failures are skipped so a bad file cannot fail the reply. ConsumeSandboxFiles makes a repeat call a no-op.
func ConsumeCreatedFiles ¶ added in v2.6.0
func ConsumeCreatedFiles(ctx *llm.Context) []llm.CreatedFile
ConsumeCreatedFiles returns the files created during this request without removing them (mirrors ConsumeWebSearchContexts).
func CreateFileContentLimit ¶ added in v2.11.0
CreateFileContentLimit returns the server's max file size, falling back to the package constant when the config does not provide one.
func DecorateStreamWithAnnotations ¶
func DecorateStreamWithAnnotations(result *llm.TextStreamResult, searchData []WebSearchContextValue, logger WebSearchLog) *llm.TextStreamResult
DecorateStreamWithAnnotations attaches annotation events based on search results to the provided stream.
func NewAskUserQuestionTool ¶
NewAskUserQuestionTool returns the built-in question tool. The resolver is an error backstop: the call is answered through the tool-approval flow (Conversations.HandleToolCall), never executed server-side.
func NewCreateFileTool ¶ added in v2.6.0
NewCreateFileTool returns the built-in CreateFile tool. It uploads text content to the conversation channel so the response flow can attach it to the bot's reply post. AutoExecute is set because the tool's only side effect is scoped to the assistant's own response. When htmlArtifacts is true the description tells the model how HTML files are rendered.
func NewWaitForAsyncWorkTool ¶ added in v2.11.0
func NewWaitForAsyncWorkTool(schedule ScheduleWake) llm.Tool
NewWaitForAsyncWorkTool returns the built-in wait tool. The resolver schedules a later resume and returns immediately; it never blocks.
func ResolveUserInteractionAnswer ¶
func ResolveUserInteractionAnswer(kind string, input json.RawMessage, answer UserInteractionAnswer) (string, error)
ResolveUserInteractionAnswer turns a user's answer to a pending interaction tool call into the tool result content. kind is the block's UserInteraction value, input the tool_use block's original arguments, and answer the structured selection (predefined labels plus optional free-form text).
Types ¶
type AskUserQuestionArgs ¶
type AskUserQuestionArgs struct {
Question string `` /* 128-byte string literal not displayed */
Options []AskUserQuestionOption `json:"options" jsonschema_description:"The choices to present. Provide 2 to 5 distinct options."`
MultiSelect bool `` /* 138-byte string literal not displayed */
AllowFreeForm *bool `` /* 241-byte string literal not displayed */
}
AskUserQuestionArgs is the LLM-visible input schema for the question tool.
type AskUserQuestionOption ¶
type AskUserQuestionOption struct {
Label string `json:"label" jsonschema_description:"Short label for the option (1-5 words). Labels must be unique within the question."`
Description string `json:"description,omitempty" jsonschema_description:"Optional one-line explanation of what choosing this option means."`
}
AskUserQuestionOption is a single choice presented to the user.
type AskUserQuestionResult ¶
type AskUserQuestionResult struct {
Selected []string `json:"selected"`
Custom string `json:"custom,omitempty"`
}
AskUserQuestionResult is the tool result content written after the user answers. It is JSON so both the LLM and the webapp can consume it.
type CreateFileArgs ¶ added in v2.6.0
type CreateFileArgs struct {
FileName string `` /* 148-byte string literal not displayed */
Content string `json:"content" jsonschema_description:"The complete text content of the file"`
}
CreateFileArgs is the LLM-visible input schema for the CreateFile tool.
type CreateFileResult ¶ added in v2.6.0
type CreateFileResult struct {
FileID string `json:"file_id"`
FileName string `json:"file_name"`
Note string `json:"note"`
}
CreateFileResult is the tool result content. It is JSON so both the LLM and the response-attachment flow (which re-parses persisted tool results) can consume it.
func ParseCreateFileResult ¶ added in v2.6.0
func ParseCreateFileResult(content string) (CreateFileResult, bool)
ParseCreateFileResult parses a persisted CreateFile tool result. ok is false when content is not a valid CreateFileResult with a file ID.
type MMToolProvider ¶
type MMToolProvider struct {
// contains filtered or unexported fields
}
MMToolProvider implements ToolProvider with all built-in Mattermost tools
func NewMMToolProvider ¶
func NewMMToolProvider(pluginAPI mmapi.Client, webSearch WebSearchService, htmlArtifacts func() bool) *MMToolProvider
NewMMToolProvider creates a new tool provider. htmlArtifacts reports whether HTML artifacts are enabled (read on every GetTools call so config changes apply without a restart); nil means disabled.
func (*MMToolProvider) GetTools ¶
GetTools returns all available tools. Tool execution is restricted at runtime via WithToolsDisabled() based on context (e.g., DM vs channel). This allows LLMs to be aware of tool capabilities even when they can't be executed in the current context.
The exceptions are context-dependent tools: user-interaction tools are only cataloged when the context says an interactive user is present (advertising them where nobody can answer would strand the conversation), and response-file tools are only cataloged when the flow can attach files to the response post.
func (*MMToolProvider) SetScheduleWake ¶ added in v2.11.0
func (p *MMToolProvider) SetScheduleWake(schedule ScheduleWake)
SetScheduleWake installs the wake scheduler used by wait_for_async_work. Called after conversations are wired because the wake handler resumes them.
type ScheduleWake ¶ added in v2.11.0
ScheduleWake schedules a conversation resume onto the given bot response post after the wait elapses. The wake runs as userID, the user whose turn requested the wait.
type ToolProvider ¶
ToolProvider provides built-in tools for the AI assistant. The context is consulted for catalog inputs such as whether the requesting user is interactively present (llm.ToolCatalogContext).
type UserInteractionAnswer ¶
type UserInteractionAnswer struct {
Selected []string `json:"selected"`
Custom string `json:"custom,omitempty"`
}
UserInteractionAnswer is a user's answer to a pending user-interaction tool call: the predefined option labels picked, plus optional free-form text.
type WaitForAsyncWorkArgs ¶ added in v2.11.0
type WaitForAsyncWorkArgs struct {
Minutes int `` /* 140-byte string literal not displayed */
Reason string `json:"reason" jsonschema_description:"Short note about what you are waiting for. Echoed back when you are re-invoked."`
}
WaitForAsyncWorkArgs is the LLM-visible input schema for wait_for_async_work.
type WebSearchContextValue ¶
type WebSearchContextValue struct {
Query string `json:"query"`
Results []WebSearchResult `json:"results"`
}
WebSearchContextValue stores the results produced by a single tool invocation.
func ConsumeWebSearchContexts ¶
func ConsumeWebSearchContexts(ctx *llm.Context) []WebSearchContextValue
ConsumeWebSearchContexts extracts the stored search context values without removing them. The data persists in the context for the duration of the request to support multiple reads.
type WebSearchLog ¶
type WebSearchLog interface {
Debug(message string, keyValuePairs ...any)
Info(message string, keyValuePairs ...any)
Warn(message string, keyValuePairs ...any)
Error(message string, keyValuePairs ...any)
}
WebSearchLog abstracts the logging interface used by the service.
type WebSearchResult ¶
type WebSearchResult struct {
Index int `json:"index"`
Title string `json:"title"`
URL string `json:"url"`
Snippet string `json:"snippet"`
Query string `json:"query"`
}
WebSearchResult represents a single web search result consumed by downstream components.
func FlattenWebSearchResults ¶
func FlattenWebSearchResults(values []WebSearchContextValue) []WebSearchResult
FlattenWebSearchResults flattens the result sets from multiple tool executions into a single slice.
type WebSearchService ¶
WebSearchService exposes the built-in web search tool if configured.
func NewWebSearchService ¶
func NewWebSearchService(cfgGetter func() *config.Config, logger WebSearchLog, httpClient *http.Client, licenseChecker *enterprise.LicenseChecker) WebSearchService
NewWebSearchService constructs a new WebSearchService implementation. A nil license checker fails closed so the tools are not cataloged or executed.
type WebSearchSourceArgs ¶
type WebSearchSourceArgs struct {
URL string `jsonschema_description:"The absolute URL of the web page to retrieve."`
}
WebSearchSourceArgs represents the input to fetch a single web page.
type WebSearchToolArgs ¶
type WebSearchToolArgs struct {
Query string `jsonschema_description:"The web search query to execute."`
}
WebSearchToolArgs represents the JSON schema for the web search tool input.