Create Your First Microbot Project¶
In this short walkthrough, you'll build your first Microbot end-to-end. You'll:
- Create a tiny C program with a deliberate bug.
- Compile it and capture the build error in a log file.
- Run a
LogAnalysisBotthat reads the log and explains the root cause for you.
By the end, you'll have a working Microbot script you can adapt to your own logs.
Before you begin
You'll need gcc to compile the sample C file. It's preinstalled on most Linux distributions — if not, run sudo apt install build-essential.
Step 1 — Create the Sample Project¶
From the root of your microbots-introduction project, create a code/ folder:
Next, add a small C file with a deliberate syntax error — this is what we'll ask the bot to analyze:
| code/app.c | |
|---|---|
Notice line 5: it's missing the trailing ; after return a + b. That's the bug — gcc will refuse to compile it, and we'll capture that error in the next step.
Step 2 — Generate the Build Log¶
Now let's compile the file and redirect both standard output and standard error into a log file the bot can read:
The compilation will fail (as expected), and code/build.log will contain the compiler's complaint:
| code/build.log | |
|---|---|
Once you complete the next step, your project layout will look like this:
microbots-introduction/
├── .venv
├── .env
├── log_analysis_bot.py
└── code/
├── app.c
└── build.log
Step 3 — Write the Bot Script¶
Time to wire up the bot. Create log_analysis_bot.py at the project root:
| log_analysis_bot.py | |
|---|---|
This short script does three things: it imports LogAnalysisBot, creates an instance of it, and invokes its run() method on the build log. Let's walk through each piece.
Constructing the bot¶
Here, LogAnalysisBot(...) takes two arguments:
model— the LLM that powers the bot, in<provider>/<deployment-or-model-name>format. Using a different provider? See the Authentication Setup guide.folder_to_mount— the host folder the bot can access from inside its Docker sandbox. It's mounted read-only at/workdir/<folder-name>/, so the bot can inspect your source code but can't change it.
Running the bot¶
my_bot.run(...) takes two arguments:
file_name— path to the log file you want analyzed. The file is copied into the container at/var/log/so the bot can read it.timeout_in_seconds— a safety net: the maximum time the bot is allowed to run before being terminated.600gives it up to 10 minutes.
Reading the result¶
my_bot.run() returns a BotRunResult object with three fields:
status(bool) —Trueif the bot completed its task successfully,Falseotherwise.result(str | None) — the bot's final output (the root-cause analysis, in our case).Noneif the run fails before producing a result.error(str | None) — error details whenstatusisFalse;Noneon success.
So print(result.result) simply prints the root-cause analysis the bot came up with.
Step 4 — Run the Bot¶
You're all set. From the project root, with your virtual environment activated, run:
Give it a few seconds — the bot spins up its sandbox, inspects the log and the source, and then prints its analysis. You should see something like this:
Root cause identified: The build failed due to a syntax error in
//workdir/code/app.c at line 5. The function add(int a, int b) has
a missing semicolon after the return statement (`return a + b`).
This matches the compiler error in /var/log/build.log: "error:
expected ';' before '}' token". Fix by adding a semicolon: `return a + b;`.
And that's it — you've just run your first Microbot. With only a handful of lines of code, LogAnalysisBot pinpointed the bug in our C file and even suggested the fix.
Curious about what happened under the hood? The next article walks through the execution flow and shows you how to use logs to debug your own Microbots. Continue with Microbots Execution Flow.