mmtools

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 20 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"
)

Variables

This section is empty.

Functions

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 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 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 exception is user-interaction tools: advertising them where nobody can answer would strand the conversation, so they are only cataloged when the context says an interactive user is present.

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