5 ms·
I built an AI agent in Zig that runs on Windows XP with 64 MB RAM
- bcorp 7mo agoI wanted to see how far back I could push an AI agent — not the LLM itself, but the client that talks to it, parses tool calls, and acts on the results. retro-agent is a terminal-based AI agent written in Zig 0.15. It connects to Ollama (or any OpenAI-compatible API) over local HTTP, supports function calling, and provides built-in tools for system diagnostics: processes, network, disk, services, memory, and arbitrary command execution. The target is Windows XP SP3 x86 on hardware as old as a Pentium III with 64 MB RAM. The binary is ~750 KB, single-threaded, no dependencies, no UCRT/MSVC runtime. It also cross-compiles to Linux x86/x64/ARM. Some things I had to deal with: - Win32 Console API for the TUI (CP437 box-drawing, colored output) - Automatic CP850 → UTF-8 conversion for localized Windows command output - UTF-8 → ASCII sanitization for console display - A compatibility shim for RtlGetSystemTimePrecise (doesn't exist on XP) - Conversation history with a sliding window to stay within memory limits - Command whitelist and approval mode for security The LLM runs on a separate machine on the network — Ollama can't run on XP. The agent is just the thin client: parse, call tools, feed results back, loop until you get a text response (max 10 iterations). Tested with llama3, qwen2, mistral, and command-r. Any model with function calling support works. MIT licensed. Would love feedback, especially from anyone still managing legacy Windows systems or working with Zig's cross-compilation story. https://github.com/benmaster82/retro-agent https://github.com/benmaster82/retro-agent
- fithisux 7mo agoIs zig able to target WindowsXP?
- bcorp 7mo agoYes! Zig's cross-compilation story is one of the reasons I chose it for this project. Zig can target x86-windows-gnu and lets you set os_version_min to .xp in the build config. This tells the linker to use only APIs available on XP SP3. In practice there were a few things I had to deal with: - RtlGetSystemTimePrecise doesn't exist on XP, so I wrote a compatibility shim that redirects to GetSystemTimeAsFileTime at startup - The build uses -OReleaseSmall, strips symbols, and is single-threaded to keep the binary small (~750 KB) and compatible with XP's threading model - There's a dedicated build-xp.zig that sets all the right flags, but you can also just do: zig build -Dtarget=x86-windows-gnu - No UCRT or MSVC runtime dependency — this was critical because XP doesn't ship with the Universal CRT, and you can't install it reliably on minimal XP systems The same codebase cross-compiles to Linux x86/x64/ARM with "zig build cross" — that's where Zig really shines compared to writing this in C with manual cross-compilation toolchains. One thing I should mention: Zig 0.15 (currently in use) dropped some older target support, but x86-windows with XP compat still works. I'd recommend testing with the exact version in the repo if you want to reproduce it.
- fithisux 7mo agoValuable information. Thanks!