Skip to main content


CodeZero

Every great idea starts at zero.
Start with CodeZero.

The open-source platform for building automations visually.
Powered by AI, running wherever you want.

Website Docs Discord YouTube Instagram



What is CADTopo?

CADTopo (Cost-Aware Dynamic-Topology) is a framework for orchestrating teams of LLM agents that collaborate to solve a task. Instead of a fixed pipeline, the agents that participate — and how they pass information to each other — are decided fresh every round, and each agent runs on the cheapest model that the current risk justifies.

It is an implementation of the DyTopo protocol, extended with cost-aware model routing. In short:

  • Per-round agent selection — only the agents relevant to the current goal are activated (no LLM calls wasted on the rest).
  • Dynamic topology — the agents describe what they can offer and what they need, and the router builds the round's communication graph from those descriptors.
  • A manager (meta-agent) — reads each round's output, picks the deliverable, scores it, and decides whether to stop or set a new goal.
  • Cost-aware routing — every agent and the manager carry a ladder of models (cheap → expensive) and climb it only when the signal (low confidence, low score, running out of rounds) warrants it.

In one sentence: the right agents, wired the right way, on the cheapest model that gets the job done — decided anew each round.


How it works

Each round runs in two phases so information can flow within the round:

                    ┌─────────────────────────────────────────┐
   user task  ──▶   │ 1. COARSE SELECT   which agents run?     │  (embedding match, no LLM)
                    │ 2. DESCRIBE        what do they offer /   │  (cheap LLM pass)
                    │                    need this round?       │
                    │ 3. TOPOLOGY        build the round graph  │  (router, no LLM)
                    │ 4. WORK            run agents in order,    │  (the real work)
                    │                    routing hand-offs      │
                    │ 5. REVIEW          manager scores & picks │  (manager LLM pass)
                    └─────────────────────────────────────────┘
                                     │
                       halt?  ──▶ return best deliverable
                       else   ──▶ next round with a new goal

The manager halts as soon as the deliverable's score Φ crosses the success threshold; otherwise it keeps steering until the round cap is reached. The final answer is the highest-scoring round's deliverable.

Core building blocks

Component What it does
Agent A specialised worker (a role + a model ladder + optional tools).
Router Coarse-selects agents and induces the per-round topology.
Manager The meta-agent: scores each round, picks the deliverable, decides when to stop.
CostAwareSelector Picks which model rung each component runs on this round.
CadTopoAI The orchestrator that ties it all together and runs the rounds.

Installation

CADTopo targets Python ≥ 3.10. We recommend uv:

git clone https://github.com/code0-tech/cadtopo.git
cd cadtopo
uv sync            # install dependencies into a local .venv

Or with plain pip:

pip install -e .

Models are called through LiteLLM, so you can use OpenAI, Anthropic, OpenRouter, local models, and more — just by changing the model string.


Quickstart

from cadtopo import Agent, Backbone, Router, Manager, EmbeddingModel, CadTopoAI

# 1. Define your agents (each with a role and a model).
agents = [
    Agent(
        name="Developer",
        skill_definition="Writes the Python implementation.",
        system_prompt="You are a senior Python developer. Return only the function.",
        api_provider="openrouter/meta-llama/llama-3.1-8b-instruct",
        api_key="sk-...",
    ),
    Agent(
        name="Tester",
        skill_definition="Reviews and validates the implementation.",
        system_prompt="You are a QA engineer. Point out any bugs.",
        api_provider="openrouter/meta-llama/llama-3.1-8b-instruct",
        api_key="sk-...",
    ),
]

# 2. Wire the router and manager.
router = Router(agents=agents, embedding_model=EmbeddingModel())
manager = Manager(api_provider="openrouter/meta-llama/llama-3.1-8b-instruct", api_key="sk-...")

# 3. Build the system and run it.
system = CadTopoAI(manager=manager, router=router, max_rounds=5)
answer = system.run("Implement a function that reverses a string.")
print(answer)

Giving an agent a cost-aware model ladder

Pass multiple Backbones instead of a single model, cheapest first. The selector climbs the ladder only when an agent is unsure or the round budget runs low:

Agent(
    name="Developer",
    skill_definition="Writes the Python implementation.",
    backbones=[
        Backbone(model="openrouter/meta-llama/llama-3.1-8b-instruct", cost=0.06, api_key="sk-..."),
        Backbone(model="openrouter/anthropic/claude-3.5-sonnet",      cost=0.20, api_key="sk-..."),
        Backbone(model="openrouter/openai/gpt-5",                     cost=30.0, api_key="sk-..."),
    ],
)

Only the relative order of the cost values matters to the selector.


Example: HumanEval

A complete, runnable example lives in examples/humaneval/. It runs a four-role team (Researcher, Designer, Developer, Tester) over the HumanEval coding benchmark and reports pass@1 plus a per-model cost breakdown.

cd examples/humaneval
cp .env.example .env          # then fill in PROVIDER and AUTH
uv run humaneval.py

The agents' roles and prompts are plain Markdown under agents/<role>/ — edit them to change behaviour, no Python needed. Set BASELINE=1 to bypass CADTopo and get a single-pass reference number on the same tasks.


Project layout

src/cadtopo/
  orchestrator.py   # CadTopoAI — runs the rounds
  router.py         # coarse selection + topology induction
  manager.py        # the meta-agent (scoring, halting, next goal)
  agent.py          # the worker agent
  selection.py      # cost-aware model-ladder selection
  backbone.py       # a single model + its cost
  embedding.py      # skill/goal/query/key matching
  tools.py          # native tool-calling support
  schema/           # pydantic schemas for structured LLM output
examples/humaneval/ # end-to-end benchmark example
tests/              # test suite

Run the tests with:

uv run pytest

License

Licensing varies per component. See the LICENSE file in this repository and in each subproject for details.


CodeZero icon

Made with ❤️ by the CodeZero community

Metadata

Release files for cadtopo 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cadtopo 0.0.1
File Size Uploaded Provenance Actions
cadtopo-0.0.1.tar.gz 43.7 kB Without provenance Details for cadtopo-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cadtopo 0.0.1
File Interpreter ABI Platform Actions
cadtopo-0.0.1-py3-none-any.whl Python 3 none any Details for cadtopo-0.0.1-py3-none-any.whl

Total release size: 96.8 kB

Release files / cadtopo-0.0.1.tar.gz

Download URL cadtopo-0.0.1.tar.gz
Size 43.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e5c458378190598538faef0d934ca0c8ffa29853bb530cf616aa3af39ba9691b
BLAKE2b-256 checksum
How to use checksums
94f23cf7c2ca6a9ef9bff7fd0c6a8ae1d28d065926749d9200daecd188215312
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / cadtopo-0.0.1-py3-none-any.whl

Download URL cadtopo-0.0.1-py3-none-any.whl
Size 53.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec3682509b2b88e8294a0352777f7e5b78d6049bdf213457b78bf181cad2062e
BLAKE2b-256 checksum
How to use checksums
92f8a1ccdff82b29c94e8e0028e7d76904f308683db58ac4c93c0c1b1303cd03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for cadtopo 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page