Safe Terminal#
The LLM can be prone to messing things up. If you want to manually review the LLM’s commands before they get executed, you can do so with the SafeTerminalChain.
[1]:
from langchain_contrib.llms.testing import FakeLLM
from langchain_contrib.tools import SafeTerminalChain
llm = FakeLLM(sequenced_responses=["date"])
safe_terminal = SafeTerminalChain()
safe_terminal(llm("Tell me what day it is."))
The LLM would like to run the command `date`. You can choose to Proceed or Edit command.
Your choice:
Proceed
[1]:
{'command': 'date',
'choice': 'Proceed',
'output': 'Fri Mar 24 16:35:33 AEDT 2023\n'}
In this case the command run was rather innocuous. However, if the LLM is coming up with the completely wrong command to use, you also have the choice to edit it for the LLM:
[2]:
llm = FakeLLM(sequenced_responses=["rm important.txt"])
safe_terminal(llm("Tell me if important.txt exists."))
The LLM would like to run the command `rm important.txt`. You can choose to Proceed or Edit command.
Your choice:
Edit command
Replace it with: ls important.txt
[2]:
{'command': 'ls important.txt',
'choice': 'Edit command',
'output': "ls: cannot access 'important.txt': No such file or directory\n"}
Note that the output dict includes the command key that indicates the actual command being run in the end. This allows you to maintain an accurate agent scratchpad when editing commands run by the agent.