mmtools

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
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 = "" /* 684-byte string literal not displayed */
	// WebSearchSourceFetchDescription describes the page retrieval tool.
	WebSearchSourceFetchDescription = "" /* 425-byte string literal not displayed */
)
View Source
const (
	// AskUserQuestionToolName is the runtime name of the built-in question tool.
	AskUserQuestionToolName = "AskUserQuestion"
)
View Source
const (
	// CreateFileToolName is the runtime name of the built-in file creation tool.
	CreateFileToolName = "CreateFile"
)

Variables

This section is empty.

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 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

func NewAskUserQuestionTool() llm.Tool

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

func NewCreateFileTool(client mmapi.Client) llm.Tool

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.

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) *MMToolProvider

NewMMToolProvider creates a new tool provider

func (*MMToolProvider) GetTools

func (p *MMToolProvider) GetTools(bot *bots.Bot, llmContext *llm.Context) []llm.Tool

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.

type ToolProvider

type ToolProvider interface {
	GetTools(bot *bots.Bot, llmContext *llm.Context) []llm.Tool
}

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 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

type WebSearchService interface {
	Tool() *llm.Tool
	SourceTool(bot *bots.Bot) *llm.Tool
}

WebSearchService exposes the built-in web search tool if configured.

func NewWebSearchService

func NewWebSearchService(cfgGetter func() *config.Config, logger WebSearchLog, httpClient *http.Client) WebSearchService

NewWebSearchService constructs a new WebSearchService implementation.

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.

Jump to

Keyboard shortcuts

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