As a simple example, let’s build an agent that can print hello world to a file use using a tool.
For brevity, this expects you have a working rust project with all dependencies configured.
-
First, lets add a tool that prints hello world. With the macro, the implementation is straightforward:
-
Let’s also add a tool that can read the last printed hello file. Just for the example, we will use the struct
variant of the macro instead.
Note that the format for the #[tool]
attributes is exactly the same for both macros.
-
Let’s set up the context. We don’t have to if we just want to use the default, but for the example it illustrates how everything fits together nicely.
If you’re executing code, sandboxing is a good idea. We also have a docker executor.
-
Finally, we can set up the agent with our context and tools:
-
And now we can give it a whirl:
That concludes a very brief introduction to Swiftide agents. A lot more is possible, and this is just a trivial example.
For a full blown example of what agents can do, check out kwaak.