Skip to main content

Using Slash Commands and Chat Participants

1. Using Built-In Slash Commands

Command Description Usage Notes
/help Displays a list of available slash commands /help Useful for discovering available commands in a chat interface
/reset Resets the conversation context and clears history /reset Starts a fresh session without previous context
/save Saves the current conversation to a file or cloud storage /save Supports saving in Markdown or JSON formats
/share Generates a shareable link to the current conversation /share Allows collaboration and sharing of AI-assisted development sessions
/explain Requests an explanation of a selected code snippet or concept /explain <code> Helps understand complex logic or code patterns
/generate Generates code based on a description or prompt /generate <description> Can generate code in multiple languages (JS, Python, Go, etc.)

Example: Using /generate to create a React component

/generate a React component that displays a list of users with their names and avatars

Example: Using /explain to understand a function

/explain function debounce(func, wait) {
  let timeout;
  return function executedFunction(...args) {
    const later = () => {
      clearTimeout(timeout);
      func(...args);
    };
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
  };
}
Note: Slash commands are context-aware and can be used in any chat interface that supports AI-assisted development tools.

2. Creating Custom Slash Commands

Property Description Example
command The slash command identifier (e.g., /mycommand) /customTool
description Short description of what the command does Runs a custom AI tool
parameters Object defining input parameters for the command { input: { type: 'string', required: true } }

Example: Define a slash command

const slashCommand = {
  command: "/aiTool",
  description: "Runs an AI-assisted code review",
  parameters: {
    file: {
      type: "string",
      required: true
    },
    mode: {
      type: "string",
      required: false,
      default: "full"
    }
  }
};

Example: Register slash command with AI agent

aiAgent.registerCommand(slashCommand);

// Usage in chat:
// /aiTool file="src/main.js" mode="quick"
Note: Slash commands are defined once and can be reused across multiple AI-assisted development sessions.

3. Using Chat Participants

Example: Setting up a chat participant

// Define a chat participant with custom behavior
const participant = {
  name: "CodeAssistant",
  role: "assistant",
  capabilities: ["code_generation", "debugging"],
  context: {
    language: "javascript",
    framework: "react"
  }
};

// Register the participant in a chat session
const session = createChatSession({ participants: [participant] });
Property Description Usage
name Unique identifier for the chat participant Used to reference the participant in interactions
role Role of the participant (e.g., assistant, user) Determines how the system treats messages from this participant
capabilities List of supported actions or features Defines what the participant can do in a session
context Configuration object for the participant's environment Provides runtime context like language or framework preferences
Note: Chat participants can be configured to respond to specific triggers or commands within a session.

Key Features of Chat Participants

  • Customizable roles allow for flexible interaction models
  • Capabilities-based design enables modular extension of chat features
  • Context-aware behavior adapts responses based on session state

4. Registering Custom Chat Participants

Custom chat participants can be registered to extend AI-assisted development environments with domain-specific capabilities.

Property Description Example
name Unique identifier for the participant "sql-assistant"
description Short description of the participant's purpose "Helps with SQL query generation and optimization"
capabilities List of supported actions or tasks ["generate", "explain", "optimize"]

Example: Registering a Custom Chat Participant

const participant = {
  name: "sql-assistant",
  description: "Helps with SQL query generation and optimization",
  capabilities: ["generate", "explain", "optimize"],
  handleRequest: (request) => {
    // Implementation logic here
  }
};

// Register the participant with the AI system
aiSystem.registerParticipant(participant);
Note: The handleRequest function must be implemented to process incoming chat requests and return appropriate responses.

5. Using Variables in Chat Commands

Variable Type Format Description Usage Example
User Input ${input} Represents the user's input in a chat command /process ${input}
Context Variable ${context.variableName} Accesses a variable from the current chat context /generate ${context.projectName}
System Variable ${system.currentTime} Provides system-level information like time or session ID /log ${system.currentTime}

Example: Using Variables in a Command

const command = "/generate ${context.projectName} with ${input}";
console.log(command); // /generate MyProject with user input
Note: Variables are resolved at runtime and must be enclosed in curly braces to be interpreted correctly.

6. Chaining Slash Commands

Slash commands can be chained together to perform sequential operations or pass data between commands. This is particularly useful in AI-assisted development environments where multiple steps are required to achieve a desired outcome.

Command Description Usage Example Notes
/generate Generates code or documentation based on a prompt. /generate api endpoint for user login Can be chained with other commands to refine output.
/fix Fixes issues in generated or existing code. /fix linting errors in /generate output Useful for iterative improvements.
/explain Provides explanations for code or concepts. /explain /fix output Helps understand the reasoning behind fixes.

Example: Chaining Commands for Code Generation and Fixing

/generate api endpoint for user login
/fix linting errors in /generate output
/explain /fix output
Note: Chaining slash commands allows for rapid iteration and refinement of AI-generated content. It's particularly effective in environments where developers can quickly test and improve upon AI suggestions.

7. Discovering Available Commands

Command Description Usage Notes
/help Lists all available slash commands /help Useful for discovering new features
/commands Displays a searchable list of commands /commands Supports filtering by keyword
/chat Starts a new chat session with a participant /chat @assistant Participant must be added to the workspace
/list Lists all active chat participants /list Shows roles and availability status
/info Provides details about a specific command or participant /info /help Useful for understanding command parameters

Example: Using /help to explore commands


<code>/help
Available commands:
/help - Show this help message
/commands - List all available commands
/chat <participant> - Start a new chat session
/list - List all active participants
/info <command> - Show detailed info about a command</code>
</pre>
</div>
</div>
<div class="note"><strong>Note:</strong> The <code>/help</code> command dynamically updates as new features are added to the AI assistant.</div>
<h2 id="8-scoping-commands-to-a-workspace">8. Scoping Commands to a Workspace<a href="#8-scoping-commands-to-a-workspace" class="toc__headingLink" aria-label="Link to this section"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<table>
<tbody>
<tr>
<th>Command</th>
<th>Description</th>
<th>Scope</th>
<th>Notes</th>
</tr>
<tr>
<td class="property">/workspace</td>
<td>Lists available workspaces</td>
<td>Global</td>
<td>Can be used in any context</td>
</tr>
<tr>
<td class="property">/workspace switch <name></td>
<td>Switches to a specific workspace</td>
<td>Current session</td>
<td>Changes context for all subsequent commands</td>
</tr>
<tr>
<td class="property">/workspace create <name></td>
<td>Creates a new workspace</td>
<td>Global</td>
<td>Requires admin privileges in some systems</td>
</tr>
<tr>
<td class="property">/workspace delete <name></td>
<td>Deletes a workspace</td>
<td>Global</td>
<td>Permanently removes all data in the workspace</td>
</tr>
</tbody>
</table>
<div class="example">
<h2 id="example-switching-workspaces">Example: Switching Workspaces<a href="#example-switching-workspaces" class="toc__headingLink" aria-label="Link to this section"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<div class="codeBlock" data-language="bash"><pre><code>/workspace switch my-project
Note: Workspace scoping is essential for managing multiple projects or teams within a single AI-assisted development environment.

Was this article helpful?