Discourse discourse-ai has a tool system, read source for all tools and produce a document that explains what each tool does
Discourse discourse-ai has a tool system, read source for all tools and produce a document that explains what each tool does
I should search for files that might contain information about the tools system. Let me look for files with “tool” in their name or path.
Searched for 'tool, tools' in discourse/discourse-ai/main
Let me retrieve the content of the base tool class first to understand the structure, and then examine some of the specific tool implementations.
Let me fetch the base tool class first to understand the structure, and then I’ll look at the specific tool implementations.
Retrieved content of lib/personas/tools/tool.rb from discourse/discourse-ai@main
Let’s first check the directory structure of the tools to see all the available tools:
Retrieved content of lib/personas/tools/create_artifact.rb, lib/personas/tools/custom.rb, lib/personas/tools/dall_e.rb, lib/personas/tools/db_schema.rb, lib/personas/tools/discourse_meta_search.rb, lib/personas/tools/github_file_content.rb, lib/personas/tools/github_pull_request_diff.rb, lib/personas/tools/github_search_code.rb, lib/personas/tools/github_search_files.rb, lib/personas/tools/google.rb, lib/personas/tools/image.rb, lib/personas/tools/javascript_evaluator.rb, lib/personas/tools/list_categories.rb, lib/personas/tools/list_tags.rb, lib/personas/tools/random_picker.rb, lib/personas/tools/read.rb, lib/personas/tools/read_artifact.rb, lib/personas/tools/search.rb, lib/personas/tools/search_settings.rb, lib/personas/tools/setting_context.rb, lib/personas/tools/summarize.rb, lib/personas/tools/time.rb, lib/personas/tools/update_artifact.rb, lib/personas/tools/web_browser.rb from discourse/discourse-ai@main
Retrieved content of lib/personas/tools/web_browser.rb, lib/personas/tools/option.rb, lib/personas/tool_runner.rb from discourse/discourse-ai@main
Let me go through each tool systematically:
This document provides an overview of all tools available in the Discourse AI plugin. Each tool serves a specific purpose and can be used by AI personas to perform different tasks.
All tools in Discourse AI inherit from the base Tool class, which provides common functionality:
create_artifactPurpose: Creates interactive web artifacts based on specifications.
Parameters:
name: A name for the artifact (max 255 chars)specification: Detailed specifications for the artifact (functionality, design, behavior)The tool generates complete HTML, CSS, and JavaScript code based on the specification, creating an interactive web component that can be embedded in posts.
customPurpose: Allows for creation of custom tools via the admin interface.
This is a special tool class that serves as a wrapper for user-defined custom tools. It supports custom contexts and can be extended through the UI.
dall_ePurpose: Generates images using OpenAI’s DALL-E model.
Parameters:
prompts: Array of text descriptions (up to 4 prompts)aspect_ratio: Optional - “tall”, “square”, or “wide” (default is square)The tool returns uploaded images in a grid format based on the provided prompts.
db_schemaPurpose: Retrieves database schema information for specified tables.
Parameters:
tables: Comma-separated list of database tables to examineReturns column names and data types for the specified tables.
discourse_meta_searchPurpose: Searches topics on meta.discourse.org.
Parameters:
search_query: Keywords to search foruser: Optional - filter by usernameorder: Optional - search result order (latest, latest_topic, oldest, views, likes)Provides search results from meta.discourse.org with links and context.
github_file_contentPurpose: Retrieves content of files from GitHub repositories.
Parameters:
repo_name: Repository name (e.g., ‘discourse/discourse’)file_paths: Array of file paths to retrievebranch: Optional - branch or commit SHA (default: ‘main’)Returns the content of the specified files, with truncation for large files.
github_pull_request_diffPurpose: Retrieves and processes the diff for a GitHub pull request.
Parameters:
repo: Repository name in ‘owner/repo’ formatpull_id: The ID of the pull requestReturns the diff with metadata about the PR, intelligently handling large diffs by truncating oversized files.
github_search_codePurpose: Searches for code within a GitHub repository.
Parameters:
repo: Repository name in ‘owner/repo’ formatquery: Search query (function name, variable, code snippet)Returns matching code fragments with their file locations.
github_search_filesPurpose: Searches for files in a GitHub repository by name/path.
Parameters:
repo: Repository name in ‘owner/repo’ formatkeywords: Array of keywords to match in file paths or namesbranch: Optional - branch or commit SHAReturns a list of matching file paths within the repository.
googlePurpose: Performs Google searches for up-to-date information.
Parameters:
query: The search queryProvides formatted search results from Google with titles, snippets, and links.
imagePurpose: Generates images using Stability AI’s models.
Parameters:
prompts: Array of text descriptions (up to 4 prompts)seeds: Optional - seeds for consistent styleaspect_ratio: Optional - various aspect ratio optionsSimilar to dall_e but using Stability AI’s image generation system.
javascript_evaluatorPurpose: Evaluates JavaScript code safely using MiniRacer.
Parameters:
script: The JavaScript code to evaluateExecutes JavaScript with safety constraints (timeout, memory limits) and returns the result.
list_categoriesPurpose: Lists forum categories.
Parameters: None
Returns information about categories on the Discourse instance including name, slug, description and post counts.
list_tagsPurpose: Lists the most popular tags.
Parameters: None
Returns the 100 most popular tags on the Discourse instance with their topic counts.
random_pickerPurpose: Makes random selections from provided options.
Parameters:
options: Array of options that can be ranges (e.g., ‘1-6’) or comma-separated listsUseful for making random decisions or choices when needed by the AI.
readPurpose: Reads content from a topic or specific posts.
Parameters:
topic_id: ID of the topic to readpost_numbers: Optional - specific post numbers to readReturns the content of the topic or specific posts with metadata.
read_artifactPurpose: Converts external web content or existing artifacts into a local artifact.
Parameters:
url: URL of the artifact or webpage to readCan import Discourse artifacts from other sites or convert general webpages into artifacts.
searchPurpose: Searches topics in the current Discourse instance.
Parameters:
search_query: Keywords to search forProvides comprehensive search results from the current Discourse instance.
search_settingsPurpose: Searches through Discourse site settings.
Parameters:
query: Comma-delimited list of settings to search forReturns matching site settings with descriptions when appropriate.
setting_contextPurpose: Provides detailed context about a Discourse site setting.
Parameters:
setting_name: The name of the site settingReturns the setting description plus context from the codebase showing where and how it’s used.
summarizePurpose: Creates summaries of topics.
Parameters:
topic_id: The ID of the topic to summarizeguidance: Optional - specific guidance on how to summarizeProduces a coherent summary of a topic, handling long topics by breaking them into sections.
timePurpose: Provides the current time in a specified timezone.
Parameters:
timezone: A Ruby-compatible timezone stringReturns the current date and time in the specified timezone.
update_artifactPurpose: Updates an existing web artifact.
Parameters:
artifact_id: The ID of the artifact to updateinstructions: Clear instructions on what changes to makeversion: Optional - specific version to updateAllows modifying existing artifacts with change tracking and versioning.
web_browserPurpose: Retrieves and processes content from web pages.
Parameters:
url: The URL of the web page to visitFetches a webpage, extracts the main content, and returns it as plain text.
The Discourse AI plugin uses a ToolRunner to execute tools within a sandboxed environment. This provides:
Tools can also define Options which allow configuration at the persona level, customizing behavior without changing the core tool functionality.
This document provides a comprehensive overview of the tools available in the Discourse AI plugin and how they function. Each tool is designed to extend the capabilities of AI personas, enabling them to interact with external systems, retrieve information, and create rich content.