DEV Community

shashank ms
shashank ms

Posted on

Building Complex Coding Systems: A Comprehensive Guide

We are going to build a multi-agent coding system that takes a plain-English task, designs a file structure, generates the implementation, and runs a self-review before writing anything to disk. It is useful for bootstrapping microservices, internal CLI tools, or prototype backends without starting from a blank file.

This system runs entirely on Oxlo.ai. Because Oxlo.ai charges a flat rate per request instead of per token, we can pass large prompts, full file contexts, and detailed review instructions without the cost ballooning on long-context passes.

What you'll need

  • Python 3.10 or newer
  • The OpenAI SDK: pip install openai
  • An Oxlo.ai API key from https://portal.oxlo.ai
  • A working directory where the agent can create files

Step 1: Set up the Oxlo.ai client

We will use three different models for three stages. Oxlo.ai exposes them all through the same OpenAI-compatible endpoint, so switching models is just changing a string.

from openai import OpenAI
import json
import os

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

PLANNER_MODEL = "qwen-3-32b"
CODER_MODEL = "deepseek-v3.2"
REVIEWER_MODEL = "llama-3.3-70b"

Step 2: Build the architecture planner

The planner turns a user request into a strict JSON blueprint: file names, dependencies, and function signatures. I use Qwen 3 32B here because it handles agentic workflow instructions reliably.

PLANNER_SYSTEM_PROMPT = """You are a senior software architect. 
Given a user request, output a JSON object with this exact schema:
{
  "project_name": "string",
  "files": [
    {
      "path": "string",
      "purpose": "string",
      "functions": ["string"]
    }
  ],
  "dependencies": ["string"]
}
Do not output markdown fences or explanations. Only raw JSON."""

def plan_architecture(task: str) -> dict:
    response = client.chat.completions.create(
        model=PLANNER_MODEL,
        response_format={"type": "json_object"},
        messages=[
            {"role": "system", "content": PLANNER_SYSTEM_PROMPT},
            {"role": "user", "content": task},
        ],
    )
    return json.loads(response.choices[0].message.content)

Step 3: Build the code generator

The generator receives the blueprint and writes actual file contents. I run one request per file so each context stays clean and easy to debug. DeepSeek V3.2 on Oxlo.ai is my default for this stage because it is tuned for coding and reasoning.

Here is the system prompt I feed to the coding agent:

GENERATOR_SYSTEM_PROMPT = """You are an expert Python developer.
You will receive a file path, its purpose, and a list of functions to implement.
Write complete, production-ready Python code for that file.
Include type hints, docstrings, and inline comments where logic is non-obvious.
Do not write a main block or test code unless explicitly requested.
Output only the raw code. No markdown fences."""
def generate_file(path: str, purpose: str, functions: list[str]) -> str:
    user_msg = f"File: {path}\nPurpose: {purpose}\nFunctions: {', '.join(functions)}"
    response = client.chat.completions.create(
        model=CODER_MODEL,
        messages=[
            {"role": "system", "content": GENERATOR_SYSTEM_PROMPT},
            {"role": "user", "content": user_msg},
        ],
    )
    return response.choices[0].message.content

Step 4: Add the automated code reviewer

Before we write to disk, we pass every generated file through a reviewer. Llama 3.3 70B catches missing imports, unsafe defaults, and style issues. Because Oxlo.ai does not charge by the token, I can stuff the entire file plus a long review rubric into a single request.

REVIEWER_SYSTEM_PROMPT = """You are a strict code reviewer.
Given a file path and its code, respond with a JSON object:
{
  "pass": true or false,
  "issues": ["string"],
  "fixed_code": "string"
}
If pass is true, fixed_code should be the original code unchanged.
If pass is false, fixed_code must contain the corrected implementation.
Output only raw JSON."""

def review_file(path: str, code: str) -> tuple[bool, str]:
    user_msg = f"File: {path}\n\n{code}"
    response = client.chat.completions.create(
        model=REVIEWER_MODEL,
        response_format={"type": "json_object"},
        messages=[
            {"role": "system", "content": REVIEWER_SYSTEM_PROMPT},
            {"role": "user", "content": user_msg},
        ],
    )
    result = json.loads(response.choices[0].message.content)
    return result["pass"], result["fixed_code"]

Step 5: Wire the pipeline and write files

This function orchestrates the three stages and persists the final code. It creates the project directory, loops over the blueprint, and only writes files that pass review or have been auto-fixed.

import pathlib

def build_project(task: str, out_dir: str = "./output"):
    blueprint = plan_architecture(task)
    project_path = pathlib.Path(out_dir) / blueprint["project_name"]
    project_path.mkdir(parents=True, exist_ok=True)

    for file_info in blueprint["files"]:
        raw_code = generate_file(
            file_info["path"],
            file_info["purpose"],
            file_info["functions"]
        )
        passed, final_code = review_file(file_info["path"], raw_code)
        
        target = project_path / file_info["path"]
        target.parent.mkdir(parents=True, exist_ok=True)
        target.write_text(final_code, encoding="utf-8")
        print(f"{'PASS' if passed else 'FIXED'}: {file_info['path']}")

    return project_path

Run it

Here is how I call the pipeline to build a small CLI tool. The request is intentionally vague to see how the planner interprets requirements.

if __name__ == "__main__":
    task = (
        "Build a Python CLI tool that reads a CSV file, "
        "validates email addresses in a chosen column, "
        "writes valid rows to a new CSV, and prints a summary report."
    )
    project_dir = build_project(task)
    print(f"\nProject written to: {project_dir}")

When I run this, the planner returns a blueprint with three files: validator.py, cli.py, and reporting.py. The generator writes typed Python with argparse, csv, and re logic. The reviewer flags that the regex was too permissive and patches it before disk write.

Typical console output looks like this:

PASS: validator.py
FIXED: cli.py
PASS: reporting.py

Project written to: output/csv_email_validator

Wrap-up and next steps

This pipeline is already useful for scaffolding microservices and repetitive boilerplate. Two concrete ways to extend it: add an execution stage that runs pytest on generated code and feeds failures back to the generator for a second pass, or replace the local file writer with a GitHub API integration so the agent opens pull requests instead of writing to your workstation.

Because Oxlo.ai offers flat per-request pricing across all these models, you can iterate on prompts and run large context windows through the planner and reviewer without watching token meters tick up. If you are currently on a token-based provider, the difference on a 50-file project is stark. You can compare plans at https://oxlo.ai/pricing.

Top comments (0)