Class Shell

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class Shell extends AnahataToolkit
A tool provider that allows the AI model to execute commands in the local shell. It supports Bash (Unix), CMD (Windows), and PowerShell (Windows).

This tool is powerful and should be used with caution. It captures standard output, standard error, and execution metadata.

Author:
anahata
  • Constructor Details

    • Shell

      public Shell()
  • Method Details

    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Populates the given RagMessage with dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).
      Parameters:
      ragMessage - The message to be augmented with context.
      Throws:
      Exception - if an error occurs during context generation.
    • runAndWait

      public ShellExecutionResult runAndWait(String command, Shell.ShellType type, String workingDirectory) throws Exception
      Executes a shell command using the appropriate system shell.
      Parameters:
      command - The shell command to execute.
      type - The type of shell to use. If null, it
      workingDirectory - the directory in which the shell command will be executed.
      Returns:
      A ShellExecutionResult containing the exit code and output.
      Throws:
      Exception - if the command fails to start or execution is interrupted.