Deterministic task classification, routing, and validation for multi-agent systems. Zero LLM calls, file-based state, git-friendly audit trail.
Project description
cervellaswarm-task-orchestration
Deterministic task classification, routing, and validation for multi-agent systems.
Zero LLM calls. File-based state. Git-friendly audit trail.
Task Description ──> Classifier ──> Router ──> Workers
(rule-based) (deterministic) │
▼
Output Validator
(score 0-100)
Why This Exists
Every multi-agent framework routes tasks using LLM calls. That means:
- Non-deterministic results (same input, different routing)
- API costs for every routing decision
- Latency before any real work starts
- No way to unit-test routing logic
This package takes a different approach: rule-based classification with zero LLM calls. The classifier uses keyword scoring, file count estimation, and pattern matching to produce a deterministic complexity score. Same input always produces the same routing decision.
Installation
pip install cervellaswarm-task-orchestration
Requirements: Python 3.10+ | Dependencies: None (zero external deps!)
Quick Start
Classify a Task
from cervellaswarm_task_orchestration import classify_task, TaskComplexity
result = classify_task("refactor the authentication module across 5 files")
print(result.complexity) # TaskComplexity.CRITICAL
print(result.should_architect) # True
print(result.confidence) # 1.0
print(result.triggers) # ['refactor', 'files>5 (5)']
Route to Architect or Workers
from cervellaswarm_task_orchestration import route_task
decision = route_task("fix typo in README")
print(decision.use_architect) # False
print(decision.suggested_workers) # [WorkerType.DOCS]
decision = route_task("redesign the entire API layer")
print(decision.use_architect) # True
print(decision.reason) # "Task critical: Detailed planning required"
Validate an Architect Plan
from cervellaswarm_task_orchestration import validate_plan
result = validate_plan(plan_markdown)
print(result.is_valid) # True/False
print(result.score) # 0.0 - 10.0
print(result.errors) # ['Missing section: ## Phase 2: Design']
print(result.warnings) # ['Plan too short (< 500 chars)']
Manage Task State (File-Based)
from cervellaswarm_task_orchestration import (
create_task, mark_ready, mark_working, mark_done, get_task_status
)
# Create a task (writes .swarm/tasks/TASK_001.md)
create_task("TASK_001", "backend-worker", "Implement user auth endpoint", risk_level=2)
# State machine: created -> ready -> working -> done
mark_ready("TASK_001")
mark_working("TASK_001") # ATOMIC: only one worker can claim!
mark_done("TASK_001")
print(get_task_status("TASK_001")) # "done"
Validate Worker Output
from cervellaswarm_task_orchestration import validate_output
from pathlib import Path
result = validate_output(Path(".swarm/tasks/TASK_001_output.md"))
print(result.valid) # True/False
print(result.score) # 0-100
print(result.retry_needed) # True if score < 50
print(result.errors) # ['Error markers found: Traceback, ERROR:']
CLI Tools
# Classify task complexity
cervella-classify "refactor the database layer"
# Route task to architect or workers
cervella-route "add pagination to the API" --json
# Validate an architect plan
cervella-validate-plan .swarm/plans/PLAN_001.md
# Validate worker output
cervella-validate-output --file output.md
# Manage tasks
cervella-task create TASK_001 backend-worker "Implement auth" --risk 2
cervella-task list
cervella-task status TASK_001
# Unified CLI
cervella-orchestrate classify "migrate to PostgreSQL"
cervella-orchestrate route "fix typo in docs"
cervella-orchestrate task list
Architecture
Task Classifier (task_classifier.py)
Rule-based complexity scoring with zero LLM calls:
| Input | Method | Output |
|---|---|---|
| "fix typo" | Simple keyword fast-path | SIMPLE (confidence: 0.9) |
| "add new endpoint" | Keyword scoring | MEDIUM (confidence: 0.27) |
| "refactor auth module" | Keyword scoring | COMPLEX (confidence: 0.53) |
| "redesign entire API across 10 files" | Keyword + file count | CRITICAL (confidence: 1.0) |
Complexity levels: SIMPLE < MEDIUM < COMPLEX < CRITICAL
Architect Flow (architect_flow.py)
Routing + plan validation + fallback logic:
classify_task() ──> should_architect?
│
┌─────┴─────┐
No Yes
│ │
Direct to Architect
Workers Planning
│ │
│ validate_plan()
│ │
│ ┌─────┴─────┐
│ Valid Invalid
│ │ │
│ Approve Reject (max 2x)
│ │
│ FALLBACK_TO_WORKER
▼ │
Output Validator <─────┘
Task Manager (task_manager.py)
File-based state machine with atomic operations:
created ──> ready ──> working ──> done
│
ATOMIC CLAIM
(exclusive create)
- Race condition protection via
open(file, 'x')exclusive create - Path traversal prevention with strict ID validation
- All state visible in the filesystem (git-friendly audit trail)
Output Validator (output_validator.py)
Reflection pattern with cumulative scoring:
| Check | Impact | Example |
|---|---|---|
| File missing | score = 0 | Output file not created |
| Empty file | score = 0 | Worker created but didn't write |
| Error markers | -40 points | Traceback, ERROR:, FAILED |
| Incomplete markers | -15 points | TODO:, FIXME: (outside code blocks) |
| Too short | -10 points | Less than 100 characters |
| Log errors | -10 points | Corresponding worker log has errors |
| Success indicators | +5 points | DONE, Completed, PASSED |
Score < 50 triggers retry_needed = True
Comparison with Other Frameworks
| Feature | CervellaSwarm | CrewAI | AutoGen | LangGraph | OpenAI SDK |
|---|---|---|---|---|---|
| Task Classification | Rule-based | LLM | LLM | Manual | LLM |
| Complexity Scoring | 0.0-1.0 | No | No | No | No |
| Deterministic Routing | Yes | No | No | Partial | No |
| Output Validation | Score 0-100 | Guardrails | Manual | Manual | Tripwire |
| Fallback Escalation | 3-level | Same agent | max_turns | Checkpoint | Exception |
| File-based State | Yes | No | No | No | No |
| Atomic Race Protection | Yes | No | No | No | No |
| Zero LLM Calls | Yes | No | No | No | No |
| Zero Dependencies | Yes | No | No | No | No |
Honest note: CrewAI and AutoGen have larger ecosystems and multi-LLM support. LangGraph offers more flexible graph-based workflows. This package focuses on deterministic, testable orchestration with zero external dependencies.
Customization
Custom Tasks Directory
from cervellaswarm_task_orchestration.task_manager import create_task
create_task("TASK_001", "worker", "My task", tasks_dir="my_project/.tasks")
Plan Validation Sections
The plan validator checks for these required sections:
## Metadata(with Task ID, Complexity, Files Affected)## Phase 1: Understanding## Phase 2: Design## Phase 3: Review## Phase 4: Final Plan(with### Success Criteria)
Worker Type Routing
The router maps keywords to worker types:
| Keywords | Worker Type |
|---|---|
| api, endpoint, database, python, fastapi | BACKEND |
| ui, frontend, react, css, component | FRONTEND |
| test, verify, bug, fix, debug | TESTER |
| deploy, docker, ci, cd, infra | DEVOPS |
| doc, readme, guide, tutorial | DOCS |
| data, analytics, report, etl | DATA |
| research, investigate, compare | RESEARCHER |
| security, auth, vulnerability | SECURITY |
API Reference
task_classifier
classify_task(description, estimated_files?, has_breaking_changes?, force_architect?) -> ClassificationResultshould_use_architect(description) -> boolestimate_files_affected(description) -> intcalculate_keyword_score(description) -> tuple[float, list[str]]is_simple_task(description) -> boolhas_multifile_pattern(description) -> bool
architect_flow
route_task(description, task_id?, force_architect?, force_direct?) -> RoutingDecisionvalidate_plan(content) -> PlanValidationResultvalidate_plan_file(path) -> PlanValidationResultcreate_session(task_id, description) -> ArchitectSessionapprove_plan(session, approved_by?) -> ArchitectSessionhandle_plan_rejection(session, reason) -> tuple[ArchitectSession, str]should_fallback(session) -> boolcreate_fallback_instruction(session) -> strsave_session_state(session, output_dir?) -> Path
task_manager
create_task(task_id, agent, description, risk_level?, tasks_dir?) -> strlist_tasks(tasks_dir?) -> list[dict]mark_ready(task_id, tasks_dir?) -> boolmark_working(task_id, tasks_dir?) -> bool(atomic!)mark_done(task_id, tasks_dir?) -> boolack_received(task_id, tasks_dir?) -> boolack_understood(task_id, tasks_dir?) -> boolget_task_status(task_id, tasks_dir?) -> strget_ack_status(task_id, tasks_dir?) -> strcleanup_task(task_id, tasks_dir?) -> boolvalidate_task_id(task_id) -> bool
output_validator
validate_output(output_file, logs_dir?) -> ValidationResultfind_last_output(tasks_dir?) -> Path | Nonefind_task_output(task_id, tasks_dir?) -> Path | None
Development
git clone https://github.com/rafapra3008/cervellaswarm.git
cd cervellaswarm/packages/task-orchestration
pip install -e ".[dev]"
pytest
License
Apache-2.0 - see LICENSE for details.
Part of CervellaSwarm - Build AI agent teams that remember.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cervellaswarm_task_orchestration-0.1.0.tar.gz.
File metadata
- Download URL: cervellaswarm_task_orchestration-0.1.0.tar.gz
- Upload date:
- Size: 37.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4b5903c63d2b2bedbff659d2b6f6d272707ff36604b9235cf24b205911ad7a6
|
|
| MD5 |
5a2d079759ccde4f9e55b741886a3448
|
|
| BLAKE2b-256 |
a90c394513612e2638a563c4566ea6466d11dace38c8984be0930f6bd39aab96
|
Provenance
The following attestation bundles were made for cervellaswarm_task_orchestration-0.1.0.tar.gz:
Publisher:
publish-task-orchestration.yml on rafapra3008/cervellaswarm-internal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cervellaswarm_task_orchestration-0.1.0.tar.gz -
Subject digest:
a4b5903c63d2b2bedbff659d2b6f6d272707ff36604b9235cf24b205911ad7a6 - Sigstore transparency entry: 989402326
- Sigstore integration time:
-
Permalink:
rafapra3008/cervellaswarm-internal@748e07119d50af2e35a393ecd40a2ab9e327c95a -
Branch / Tag:
refs/tags/task-orchestration-v0.1.0 - Owner: https://github.com/rafapra3008
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-task-orchestration.yml@748e07119d50af2e35a393ecd40a2ab9e327c95a -
Trigger Event:
push
-
Statement type:
File details
Details for the file cervellaswarm_task_orchestration-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cervellaswarm_task_orchestration-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c0d15c9c89d834e0b90dd46fdea0dd31a8b00a89a284fde93a0eca92bb572a6
|
|
| MD5 |
256d31578aee9bbd5691bae2836a9fb0
|
|
| BLAKE2b-256 |
d1d544a7a21efc4c15aee35ae074c680e7c4b1190820e149a5bd8ebabe7e9e6d
|
Provenance
The following attestation bundles were made for cervellaswarm_task_orchestration-0.1.0-py3-none-any.whl:
Publisher:
publish-task-orchestration.yml on rafapra3008/cervellaswarm-internal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cervellaswarm_task_orchestration-0.1.0-py3-none-any.whl -
Subject digest:
5c0d15c9c89d834e0b90dd46fdea0dd31a8b00a89a284fde93a0eca92bb572a6 - Sigstore transparency entry: 989402376
- Sigstore integration time:
-
Permalink:
rafapra3008/cervellaswarm-internal@748e07119d50af2e35a393ecd40a2ab9e327c95a -
Branch / Tag:
refs/tags/task-orchestration-v0.1.0 - Owner: https://github.com/rafapra3008
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-task-orchestration.yml@748e07119d50af2e35a393ecd40a2ab9e327c95a -
Trigger Event:
push
-
Statement type: