Architecture
Let's take a look how SWE-ReX works:
- Your central entry point is one of the
Deploymentclasses, depending on where your code should run. - Your
Deploymentinstances allows your to start your docker container, AWS instance, or whatever at the push of a button. That's right, no more fiddling with the AWS console! - After the
Deploymenthas started your container somewhere, you are handed aRemoteRuntimeinstance. This is your main interface for interacting with the environment. You can use it start new shell or interactive sessions, read and write files, execute one-off commands, etc.
Looking closer at the internals:
-
Within the container, we have a fastapi Server that transfers all request from the
RemoteRuntimeto theLocalRuntime. TheLocalRuntimehas the exact same interface as theRemoteRuntimeclass and it is what actually executes the commands. In fact, if you want to run something locally (or your whole codebase runs in a sandboxed environment), you can just use theLocalRuntimedirectly! Both classes are absolutely interchangeable, in fact we even transfer any exceptions happening in theLocalRuntimeto theRemoteRuntimetransparently, so you can easily catch and ignore certain errors. -
The
Runtimeclass provides several methods for reading/writing files, anexecutemethod for running arbitrary commands, but the most important one isrun_in_session. This method allows you to run a command in an existing shell session (or an interactive tool running inside of it) and return the output. In fact, you can have multiple sessions open at the same time, running different commands and tools in parallel!