Guaranteed 15% off your current AI inference bill for team spending up to $20000 / month.

Book a call →
Back to Blogs
Engineering

Building Complex Coding Systems: A Comprehensive Guide

I recently shipped an internal tool that turns a one-line feature request into a multi-file Python project. It uses three specialized agents: a planner that...

Building Complex Coding Systems: A Comprehensive Guide

I recently shipped an internal tool that turns a one-line feature request into a multi-file Python project. It uses three specialized agents: a planner that designs the file tree, an implementer that writes the code, and a reviewer that blocks bad output before it hits disk. In this guide, I will walk you through the exact version I built on Oxlo.ai so you can adapt it to your own codebase.

What you'll need

You need Python 3.10 or newer and the OpenAI SDK. Install it with pip install openai. Grab an Oxlo.ai API key from https://portal.oxlo.ai and export it as OXLO_API_KEY. You also need a local directory where the agent can write files. I keep mine at ./out.

I chose Oxlo.ai for this because its request-based pricing keeps costs flat even when I feed long file lists and previous outputs back into the context window. For agentic coding systems where context grows quickly, that predictability matters more than saving a few cents on short prompts.

Step 1: Bootstrap the Oxlo.ai client

Every agent hits the same Oxlo.ai endpoint, so I start with a thin wrapper around the OpenAI-compatible client. I set the base URL to https://api.oxlo.ai/v1 and read the key from the environment. This single function handles every call in the pipeline, which makes switching models or adding retries trivial later.

from openai import OpenAI
import os

client = OpenAI(
    base_url="https://api.oxlo.ai/v1",
    api_key=os.environ["OXLO_API_KEY"]
)

def run_agent(model, system_prompt, user_message, temperature=0.2):
    response = client.chat.completions.create(
        model=model,
        messages=[
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": user_message},
        ],
        temperature=temperature,
    )
    return response.choices[0].message.content

Step 2: Design the planner agent

The planner converts a raw requirement into a machine-readable manifest. I prompt for strict JSON and parse it downstream. I use Qwen 3 32B here because it handles structured agent workflows and multilingual reasoning reliably, which helps when specs contain mixed terminology. Keeping the temperature low prevents hallucinated file paths.

import json

PLANNER_PROMPT = """You are a senior software architect.
Given a feature description, output strict JSON with no markdown.
The schema is {"files": [{"path": "...", "purpose": "..."}]}.
Do not write anything outside the JSON object."""

def plan(requirement):
    raw = run_agent(
        model="qwen-3-32b",
        system_prompt=PLANNER_PROMPT,
        user_message=requirement,
        temperature=0.1,
    )
    return json.loads(raw)

Step 3: Build the implementer agent

For each file in the manifest, the implementer generates source code. I use DeepSeek V3.2 because it is tuned for coding and reasoning, and Oxlo.ai offers a free tier for this model. That makes iteration cheap while you tune the prompt. I force raw output without markdown fences so I can write the strings directly to .py files.

IMPLEMENTER_PROMPT = """You are an expert Python engineer.
Write clean, typed Python 3.10+ code for the requested file.
Output only raw code. Do not wrap it in markdown fences.
Include docstrings and type hints."""

def implement(file_path, purpose, spec):
    user_msg = f"Project spec: {spec}\nFile: {file_path}\nPurpose: {purpose}"
    return run_agent(
        model="deepseek-v3.2",
        system_prompt=IMPLEMENTER_PROMPT,
        user_message=user_msg,
        temperature=0.1,
    )

Step 4: Add the review loop

Before writing to disk, I run a reviewer agent to catch bugs. If the reviewer does not return exactly PASS, I feed the critique back to the implementer for a one-shot retry. I use Kimi K2.6 for its advanced reasoning and agentic coding capabilities. This loop adds a few extra requests, but because Oxlo.ai charges per request rather than per token, the cost stays predictable even when the code blocks are long.

REVIEWER_PROMPT = """You are a strict code reviewer.
Check the Python code for bugs, type errors, and security issues.
Respond with exactly PASS, or a single sentence describing the problem."""

def review(file_path, code):
    user_msg = f"Review {file_path}:\n\n{code}"
    result = run_agent(
        model="kimi-k2.6",
        system_prompt=REVIEWER_PROMPT,
        user_message=user_msg,
        temperature=0.1,
    )
    return result.strip()

def implement_with_retry(file_path, purpose, spec):
    code = implement(file_path, purpose, spec)
    feedback = review(file_path, code)
    if feedback != "PASS":
        code = implement(file_path, f"{purpose}. Fix: {feedback}", spec)
    return code

Step 5: Wire the orchestrator

The orchestrator chains the three stages and writes results to an output directory. It creates subdirectories as needed so the planner can request nested packages. I keep the orchestrator purely imperative. It does not need an LLM. It just coordinates the agents and handles filesystem state.

import os

def build(spec, out_dir="out"):
    os.makedirs(out_dir, exist_ok=True)
    manifest = plan(spec)

    for entry in manifest["files"]:
        path = os.path.join(out_dir, entry["path"])
        os.makedirs(os.path.dirname(path), exist_ok=True)
        code = implement_with_retry(entry["path"], entry["purpose"], spec)
        with open(path, "w") as fh:
            fh.write(code)
        print(f"Wrote {path}")

Run it

Here is a concrete test: a CLI task tracker split across three files. Because Oxlo.ai charges per request rather than per token, running this full planning, implementation, and review pipeline costs the same whether my prompt is fifty tokens or five thousand. That flat pricing is useful when you start passing entire existing modules into the context to maintain style consistency.

if __name__ == "__main__":
    requirement = (
        "Build a CLI task tracker in Python using argparse. "
        "Support adding, listing, and completing tasks. "
        "Store tasks in a local JSON file. "
        "Split the logic into models.py, storage.py, and cli.py."
    )
    build(requirement)

When I ran this, I got three files in the out/ directory. The planner created the manifest correctly. The implementer wrote typed Python with argparse subcommands. The reviewer caught a missing json import in storage.py on the first pass, which the retry fixed automatically. The final cli.py wired everything together with a main() entrypoint and proper type hints. I inspected the files, ran python -m py_compile out/*.py, and everything passed.

Wrap-up

This pattern scales beyond toy examples. You can add a fourth agent that generates pytest suites, or swap DeepSeek V3.2 for Llama 3.3 70B if you prefer a different coding style. Because Oxlo.ai uses request-based pricing, you can feed entire existing codebases into the planner context for refactoring without watching token meters spin up. Check the details at https://oxlo.ai/pricing and start prototyping.

Ready to build with Oxlo.ai?

Get started building high-performance AI inference applications today.

Get started
Ox Assistant
Online
OxBot
OxBot

Hi there! Try our cost calculator to see what you'd save with Oxlo.ai.