12 minute read

WorkBuddy is a versatile agent. From its name it sounds as if it might be intended mainly for work and office stuff, but it can be used for almost arbitrary tasks, including programming. Here I present two dockerized images, one containing the plain agent and one with a computer science toolchain. Putting WorkBuddy into a Docker container has two advantages: (1) You can run it in isolation from your system, while still having full access to its features and GUI. (2) You can use a pre-defined setup with different pre-configured tool chains installed and ready-to-use in one container, without the need to do complex setup and installation processes on your own system. As proof of concept, below will show how we can use the container with the computer science tool chain to do a mathematical proof, write a Python programm showing a corresponding plot, then include the proof and the plot into a LaTeX document and compile it to PDF. It is surprising how much one can achieve with just a few instructions written in plain English. The only software you need to have installed in order to run this is an installation of Docker on a Ubuntu or Ubuntu-compatible  (other Debian derivatives should work, too, but I am not sure). You can then download and execute the container via the runner script, e.g., workbuddy_cs_run.sh for the computer science tool chain, and you are ready to go.

This project is not affiliated with or supported by Tencent or WorkBuddy. Unofficial Docker image; not endorsed or supported by Tencent or WorkBuddy.

1. Background

With WorkBuddy, Tencent offers a strong and versatile agent that can be used for many different tasks. I think it is quite cool that they also offer a Debian .deb package. With it, you can install WorkBuddy under different variants, including Ubuntu. It is a bit tricky to download and installation requires some prerequisites, but it works.

1.1. WorkBuddy under Linux

In Linux, WorkBuddy will then run in a Chrome sandbox. It can execute commands and perform tasks by launching more sandboxed processes. Depending on what tasks you want it to do, you would to install additional standard software packages. For example, if you want to compile LaTeX documents, you could install TeX Live. If you want it to run Java programs, you would install an OpenJDK and maybe Maven for package management.

1.2. WorkBuddy in a Docker Image: The Two Advantages

Here we choose a different way: We put WorkBuddy into a Docker container. We can then run this container, e.g., in rootless Docker. This has two advantages:

  1. The only data that the agent can see and change directly are what is on the screen (to which it needs access in order to show its own window) and what is in a single directory that we mount into the container. The agent runs in a sandbox executed by a non-root user inside a Docker container which runs in a (ideally non-root) Docker daemon. This offers multiple layers of protection against errors. (That being said, we had to weaken the inner sandbox a little bit as explained in the documentation to make it work in the graphics environment, but there should still be a strong isolation from your system.)
  2. We can provide a containerized installation with many tools in a consistent setup. This setup is separate from our original system. So if we need to install many things and link systems together in a complex way, this all is part of the image. Imagine that you need to set up maybe six or seven tools and then install packages for these tools via dedicated package managers, maybe configure mirrors, maybe set environment variables, maybe run activation scripts etc. All of this would normally happen on your productive system, cluttering your normal setup with lots of intertwined stuff. However, if we put all of this into an image, then you do not need to do any of that. The image is created via a GitHub action every time when I update it. All the software is inside and it is consistent. Even complex setups cannot soup over into your actual systems’ configuration.

Such an image only needs to be downloaded once. This happens automatically when you run it for the first time. After that, you have a complete WorkBuddy installation ready, isolated from your system and with many useful tools pre-installed.

This is even more useful if you are inside of Mainland China: Both images can be compiled in China without problems as well, because I am using official domestic mirrors wherever possible. …which may save more complex setup fiddling work. In other words, I already have pre-configured official domestic mirrors for the tools inside the image, at least as far as I deem appropriate or necessary.

1.3. Our Two Images

Here, I want to introduce two such WorkBuddy images:

The first one, workbuddy_plain, is just a plain WorkBuddy installation. It does not have additional tools, but it works. I mainly want to offer this as a base image. On top of this image, we can build images that offer extended setups and tools.

With workbuddy_cs, for example, I plugged together a setup that should be able to write code in different programming languages ranging from Python over C and Rust to Java. It also can create and prove theorems using Lean with a cached mathlib4. It also can write LaTeX documents and compile them to PDFs using its internal TeX Live. Finally, it has some additional tools just for good measures, such as some graphics programs and LibreOffice.

At least this is the current state, maybe some of these tools will actually be useless while others may be needed — in which case, I will simply adapt the image. The point is: With a single Docker pull, you get a self-contained setup of WorkBuddy with a wide range of tools for computer science. You do not need to work your way through setting them up by yourself.

2. Running the Containers

To run the containers, you need a Docker installation. I recommend going with rootless Docker. In the linked post, I describe how rootless Docker can be installed — in a China-compliant way, using domestic mirrors for repositories etc. In such a setup, the Docker daemon and hence the containers run directly under your (or even a dedicated, isolated) user account. They have no sudo privileges, i.e., errors at least should not affect the internal host system configuration. But a normal Docker installation would do just as well. (Notice that you may need to run some of the scripts as sudo then.)

2.1. Running via Scripts

After you have installed Docker, the easiest way to run the containers is via the provided scripts. For the plain WorkBuddy, you can download workbuddy_plain_run.sh. For the tool chain for computer science, you would use workbuddy_cs_run.sh instead. These two scripts download and run the containers in such a way that WorkBuddy’s persistent/session data is stored in auto-created Docker volumes.

Both scripts take three optional parameters: This script will take three optional parameters:

  • The directory to mount into WorkBuddy, by default "/tmp/workbuddy". This folder will be created if it does not exist. You can point this to some folder with data in it that you want to share. The default setting just uses a temporary folder, where nothing important should be in. But you may also choose to mount a folder of a permanent nature. This directory should have reading and writing permissions for the container. The easiest way to do this is to chmod 777 directory. The files created by WorkBuddy will have read permissions for you only, so you can tell it to give all files read/write permissions for everyone.
  • The version of the image to run, by default "latest"
  • The mode of the image to use. By default, this uses the corresponding image from the GitHub package registry. If you set this to "local", then you can also run a Docker image that you built locally.

2.2. Running by Hand

Alternatively, you can also run the containers by hand. Unlike using the script, this may not offer persistent storage of workspace/configuration data. In their core, both scripts of them have the following commands:

xhost +local:docker

docker run -it --rm \
  --name workbuddy \
  --network host \
  --cap-add SYS_ADMIN \
  -e DISPLAY=$DISPLAY \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  -v /path/to/folder/you/want/to/mount/into/image:/home/user/workbuddy-data \
  -v /etc/localtime:/etc/localtime:ro \
  -v /etc/timezone:/etc/timezone:ro \
  "ghcr.io/thomasweise/XXXIMAGEXXXX:latest"

Here, XXXIMAGEXXXX has to be replaced with either workbuddy_plain or workbuddy_cs . /path/to/folder/you/want/to/mount/into/image is a path to a directory that you want to mount into the image. This way, you can share data directly with the container. This directory should not point to anything important. Maybe it could be an empty temporary folder or something. Ideally, you should have done something like chmod 777 /path/to/folder/you/want/to/mount/into/image beforehand, to ensure that the container can also write this folder.

The command provides the Docker container with access to your screen, which is necessary because otherwise it cannot show its window. It also gives it your current system time.

Notice: This simple execution command does not take care of storing WorkBuddy’s session/history/configuration data in additional volumes. These data are stored a writable layer of the container. If you move to another version of our images, that data will be lost. The scripts should be able to save the data properly and consistently. They should enable to move to new versions of the image without problems.

3. Using the Containers

After you have started the container as described above, a WorkBuddy window will pop up. After a login, you can use it to execute tasks. It will automatically choose a suitable model running in the cloud for the language processing, while the actual tools used to execute the tasks are running on your computer, inside the container.

3.1. Logging In

When you start the container, you first need to log in. This works the same for both images. For this, you should ideally have a WeChat account. You would then follow the steps listed below.

The log in window appears. You click 'Sign in' in the login screen.
Figure 1. The log in window appears. You click 'Sign in' in the login screen.
After the click, it may take a second until the container-internal browser pops up.
Figure 2. After the click, it may take a second until the container-internal browser pops up.
It shows you a WeChat confirmation QR-code (here blotted out by the gray rectangle).
Figure 3. It shows you a WeChat confirmation QR-code (here blotted out by the gray rectangle).
Using WeChat on your phone, you scan this QR code…
Figure 4. Using WeChat on your phone, you scan this QR code…
…and allow it to use your information.
Figure 5. …and allow it to use your information.
The browser will change to a confirmation. After the browser content has changed, you can close it.
Figure 6. The browser will change to a confirmation. After the browser content has changed, you can close it.
You are now logged into WorkBuddy.
Figure 7. You are now logged into WorkBuddy.

If, for some reason, the login via the container-internal browser does not work, you can copy the login URL via the button in the WorkBuddy startup window. You can paste it into your system’s own web browser and complete the procedure. Either way, you may need to wait a few seconds to let the login complete.

3.2. Using WorkBuddy

After the login has been succeeded, you can now use WorkBuddy. This example works the same for both images.

Here I instruct WorkBuddy to create a simple Python file, run it, store its output in the mounted folder, and set all permissions to the generated files so that I can edit them.
Figure 8. Here I instruct WorkBuddy to create a simple Python file, run it, store its output in the mounted folder, and set all permissions to the generated files so that I can edit them.
WorkBuddy begins to work.
Figure 9. WorkBuddy begins to work.
It shows me the contents of the file it created.
Figure 10. It shows me the contents of the file it created.
And it explains what it did.
Figure 11. And it explains what it did.
And the files appear indeed in the mounted folder.
Figure 12. And the files appear indeed in the mounted folder.

3.3. Using the WorkBuddy CS Image

Now let’s do a more advanced example, for which you need the (bigger) workbuddy_cs image. Only this image has the full computer science toolchain installed. We will ask WorkBuddy to prove that $1+x \leq \exp{x}$ for all $x\in\mathbb{R}$. We will ask it to draw the two functions into a diagram next to each other. We will ask it put all the proof, description, maths, artifacts, and plots into one LaTeX document and compile it to PDF.

We tell WorkBuddy to store all the artifacts into the folder that we mounted into its container. Then we give it the task to do the proof. For this, we advise it to use <a href='https://lean-lang.org'>Lean</a>, which is pre-installed in the image.
Figure 13. We tell WorkBuddy to store all the artifacts into the folder that we mounted into its container. Then we give it the task to do the proof. For this, we advise it to use Lean, which is pre-installed in the image.
WorkBuddy does this quickly. The text on the right-hand side is the Lean output, telling us that everything is OK. The Lean proof is in file <a href='/workbuddy_cs/images/proof.lean'>proof.lean</a>.
Figure 14. WorkBuddy does this quickly. The text on the right-hand side is the Lean output, telling us that everything is OK. The Lean proof is in file proof.lean.
It has created both files.
Figure 15. It has created both files.
I can see both files in the mounted folder.
Figure 16. I can see both files in the mounted folder.
This is the content of the Lean file The Lean proof is in file <a href='/workbuddy_cs/images/proof.lean'>proof.lean</a>..
Figure 17. This is the content of the Lean file The Lean proof is in file proof.lean..
And here we have the output of the proof checker in file <a href='/workbuddy_cs/images/proof_results.txt'>proof_results.txt</a>.
Figure 18. And here we have the output of the proof checker in file proof_results.txt.
Now I instruct WorkBuddy to create a Python program plotting the two functions into one diagram. The diagram is to be stored as PDF file.
Figure 19. Now I instruct WorkBuddy to create a Python program plotting the two functions into one diagram. The diagram is to be stored as PDF file.
It completes the task and also presents me with the <a href='/workbuddy_cs/images/plot.pdf'>diagram</a>.
Figure 20. It completes the task and also presents me with the diagram.
Both the <a href='/workbuddy_cs/images/plot.py'>Python script</a> and the <a href='/workbuddy_cs/images/plot.pdf'>PDF</a> it generates appear inside the mounted folder.
Figure 21. Both the Python script and the PDF it generates appear inside the mounted folder.
The <a href='/workbuddy_cs/images/plot.py'>Python script</a> looks quite reasonable.
Figure 22. The Python script looks quite reasonable.
Now I ask WorkBuddy to write a summary document in LaTeX. I instruct it to include and explain everything that was done and to compile the LaTeX to PDF.
Figure 23. Now I ask WorkBuddy to write a summary document in LaTeX. I instruct it to include and explain everything that was done and to compile the LaTeX to PDF.
It even realizes the limitations of some LaTeX packages…
Figure 24. It even realizes the limitations of some LaTeX packages…
It creates the <a href='/workbuddy_cs/images/summary.tex'>LaTeX document</a> and presents me with the <a href='/workbuddy_cs/summary.pdf'>compiled result</a>.
Figure 25. It creates the LaTeX document and presents me with the compiled result.
Here are all the files that were generated during this session.
Figure 26. Here are all the files that were generated during this session.
This is the front page of the <a href='/workbuddy_cs/summary.pdf'>generated document</a>.
Figure 27. This is the front page of the generated document.
A part of page 2 of the <a href='/workbuddy_cs/summary.pdf'>generated document</a>.
Figure 28. A part of page 2 of the generated document.
A part of page 2 and 3 of the <a href='/workbuddy_cs/summary.pdf'>generated document</a>.
Figure 29. A part of page 2 and 3 of the generated document.
A part of page 3 of the <a href='/workbuddy_cs/summary.pdf'>generated document</a>.
Figure 30. A part of page 3 of the generated document.
The last page of the <a href='/workbuddy_cs/summary.pdf'>generated document</a>.
Figure 31. The last page of the generated document.

During the course of the example, WorkBuddy created the following files:

If you read summary.pdf, you will find that the proof that it created does make sense. All the files are of surprisingly high quality.

During creating these files, no additional tools needed to be installed. WorkBuddy found all the necessities on its system.

4. Summary

With workbuddy_plain, I created a Docker container with a plain WorkBuddy setup. With workbuddy_cs, I built a computer science pipeline on top of that. In our proof of concept example, we can see that quite a few things are already possible with this setup.

Both of these projects are still in an early stage. I have not really done anything with yet. In the future, tools may be added to or removed from workbuddy_cs. I will probably have to modify and improve the containers in many ways in the future.

Or maybe I will drop the project altogether if it does not turn out as useful as I think it will. Either way, we now have two working setups for WorkBuddy. And both of these projects are freely and openly available on GitHub. They can serve as blueprint for other projects. Nice.