OpenCog shell

From OpenCog
(Redirected from The OpenCog Shell)

This page describes how to run the OpenCog shell. Examples on how to use subsystems, including the scheme shell, and a python shell, can be found in their respective pages.

The OpenCog shell is provided by the CogServer. it can be used without any configuration; however, there is a configuration file that does have some useful parameters.

Starting the CogServer

The CogServer can be started in three different ways: from the scheme command line, from the python command line, and from the bash (unix) shell.


It is assumed that you have already compiled and installed the CogServer. If not, this must be done first. Very briefly, this consists of the steps:

git clone
cd cogserver; mkdir build; cd build
cmake ..; make -j
sudo make install

From the bash prompt

The cogserver binary usually installs in /usr/local/bin; make sure this is in your path. Then just say

$ cogserver

or, optionally, specify a config file:

$ cogserver -c cogserver.conf

You should see the following output:

Listening on port 17001

From the guile prompt

To run it from guile, the cogserver module must be loaded:

guile> (use-modules (opencog) (opencog cogserver))
guile> (start-cogserver)

or, with a config file:

guile> (start-cogserver "/etc/coserver.conf")

Note you can also stop it with (stop-cogserver). You can access documentation as:

guile> ,d start-cogserver 

From the python prompt

Yes, this works. Someone should document it.

Connecting to the CogServer

The CogServer, by default, listens for telnet connections on port 17001. After starting the CogServer, use telnet to connect to it. From from a separate terminal window, run

telnet localhost 17001

Optionally, enable readline, which enables you to edit the shell's history run:

rlwrap telnet localhost 17001

This assumes that rlwrap is installed on your machine.

You should be presented with:

Connected to localhost.
Escape character is '^]'.

Run "help"<enter> to get a list of commands. After additional modules are loaded, additional commands will appear.

Available commands:                                        
  help:           List the available commands or print the help for a  specific command
  list:           List atoms in the atomtable 
  listmodules:    List the currently loaded modules  
  loadmodule:     Load an opencog module
  py:             Enter the python shell 
  py-eval:        Run some python code  
  quit:           Close the shell connection 
  scm:            Enter the scheme shell
  sexpr:          Enter the s-expression shell
  shutdown:       Shut down the cogserver
  stats:          Print some diagnostic statistics about the server.
  unloadmodule:   Unload an opencog module                         

To get information about any of the commands, use "help <name of command>". For example

opencog> help scm                                                              
Usage: scm [hush|quiet|sync]                                                   
Enter the scheme interpreter shell. This shell provides a rich                 
and easy-to-use environment for creating, deleting and manipulating            
OpenCog atoms and truth values. It provides a full R5RS-compliant              
interactive scheme shell, based on the GNU Guile extension language.           
If 'hush' or 'quiet' is specified after the command, then the prompt           
will not be returned.  This is nice when catting large scripts using           
netcat, as it avoids printing garbage when the scripts work well.              
If 'sync' is specified after the command, then the output is sync,             
instead of async.

Monitoring the CogServer

The CogServer will write log entries from various subsystems to the file /tmp/cogserver.log. Some subsystems may have their own log files; refer to their respective documentations for details.

To keep an eye on the log file, start a new Terminal window and run

tail -f /tmp/cogserver.log

You should see some output similar to the following:

opencog@locahost:/opencog/build$ tail -f /tmp/cogserver.log 
[2016-02-23 09:16:27:289] [INFO] Loaded /usr/local/share/opencog/scm/utilities.scm
[2016-02-23 09:16:27:295] [INFO] Loaded /usr/local/share/opencog/scm/apply.scm
[2016-02-23 09:16:27:300] [INFO] Loaded /usr/local/share/opencog/scm/file-utils.scm
[2016-02-23 09:16:27:300] [WARN] Failed to load file scm/persistence.scm: 2 No such file or directory
[2016-02-23 09:16:27:305] [INFO] Loaded /usr/local/share/opencog/scm/config.scm
[2016-02-23 09:16:27:317] [INFO] Loaded /usr/local/share/opencog/scm/repl-shell.scm
[2016-02-23 09:16:27:323] [INFO] Loaded /usr/local/share/opencog/scm/av-tv.scm
[2016-02-23 09:16:27:329] [INFO] Loaded /usr/local/share/opencog/scm/rule-engine-utils.scm
[2016-02-23 09:16:27:335] [INFO] Loaded ..//opencog/cogserver/scm/config.scm
[2016-02-23 09:16:27:336] [INFO] Starting CogServer loop.