How AGENTASIAN Works
Status: Ready
Truth label: Current
Audience: New builder
Reader outcome: Follow how a request becomes a task, how a worker runs it, and how evidence comes back.
Last verified: 2026-09-13
AGENTASIAN has two main flows:
- Brain answers a chat request and can dispatch a task.
- Forge routes that task to a worker, which runs a coding CLI and reports the verified result.
Process map
+----------------+
| Cortex UI |
| static :3000 |
+-------+--------+
|
+-----------+-----------+
| |
v v
+-------------+ +-------------+
| Brain :8081 | | Forge :8080 |
+------+------+ +------+------+
| ^
| rules, learnings | tasks, leases, logs, results
+-----------------------+
|
v
+---------+
| Worker |
+----+----+
|
v
coding-agent CLI
Cortex never connects to workers. Workers do not accept inbound connections.
Chat flow
- Cortex loads usable providers from
GET /chat/providersand influence choices fromGET /chat/influences. - The browser sends
POST /chat/streamwith the message, history, selected provider and model, reasoning lens, voice register, and supported generation controls. - Brain assigns a conversation UUID and turn UUID.
- Brain resolves the requested influence selection and generation controls.
- Approved voice examples and relevant memory are retrieved.
- Brain builds trusted instructions and a separate untrusted evidence block.
- The LangGraph agent calls the selected provider. It may search knowledge, search CPMI, or call constrained Forge tools.
- SSE events return context, tool activity, and tokens to Cortex.
- Brain applies output linting and the optional local revision gate.
- The final
doneevent contains the authoritative response and generation settings report. - Brain records the turn manifest, retrieval provenance, usage, outcome, and raw local artifacts.
The dispatch tool can list registered projects and create a Forge task. It cannot edit a repository directly.
Project registration
POST /projects validates the submitted path before it is stored.
- Local paths are expanded and resolved.
- Foreign OS paths remain pure absolute paths and are stored verbatim.
- Remote requests are restricted by
SE_MANAGER_ALLOWED_PROJECT_ROOTS. - With API authentication enabled and no explicit allowlist, only
SE_MANAGER_PROJECTS_DIRis accepted.
The path is executed literally on the worker. Forge does not map a Windows path to a macOS or Linux clone.
Task creation and routing
A task can carry:
- project, title, description, and priority
- supervision mode
- engine and model
- requested permission
- worker persona and selected skills
- required capabilities
- explicit worker pin
- verification command and retry policy
- session and parent-task identifiers
An eligible worker must match the pin, requested engine, required capabilities, and completed parent dependency. The worker's startup engine is the fallback for tasks without an engine.
Worker enrollment
- The worker discovers installed backends from the executable path.
- It identifies itself by hostname plus
FORGE_WORKER_NAME. - On first registration, Central mints a random worker token and stores only its SHA-256 hash.
- The worker saves the cleartext token with restricted permissions under its local Forge data root.
- Later registration, heartbeat, poll, and claim requests present
X-Worker-Token.
A missing credential does not let another process take over an existing identity. An operator must remove that registration before re-enrollment.
Claim transaction
The worker first calls GET /tasks/next, then
POST /tasks/{task_id}/claim.
The claim is one BEGIN IMMEDIATE SQLite transaction:
- Revalidate the worker and route constraints.
- Change the task from
pendingtoassigned. - Assign the worker.
- Create a UUID run id.
- Increment the attempt number and fence.
- Create a lease with the server-owned TTL.
- Mark the worker busy.
- For a credentialed worker, mint a run token bound to task plus fence.
This prevents two Centrals or concurrent claimers from assigning the same task through split state updates.
Prompt assembly
Before launching a CLI, the worker builds bounded context:
- Task id, project name, and resolved engine
- Task title, description, and optional spec
- Persona hint
- Up to five selected skills and their supporting files
- Active Brain rules
- Session history and parent-task context
- Directly read target-repository controls
- Relevant CPMI history labeled as untrusted evidence
- Verification expectations
- Feedback from an automatic retry or checkpoint revision
The worker refreshes the target project's CPMI index before retrieval when Brain is available. Failure to reach Brain degrades context but does not stop a CLI-agent task.
CLI execution
The shared executor in forge/worker/executors/base.py:
- validates the project directory
- selects a backend adapter
- drops a model name the adapter does not own
- maps
safe,write, oryoloto backend-specific flags - launches the CLI with stdin closed
- captures stdout and stderr
- streams supported progress lines to Forge
- records git status before and after the run
- parses the backend's final result and usage
The adapter owns only command construction and output parsing. Current adapters are Claude Code, Codex, Codex OSS, and Antigravity.
Lease and cancellation loop
While the CLI runs, the worker periodically calls
POST /tasks/{id}/lease with worker id, fence, and run token.
The response carries:
lease_okcancel_requested- the server-owned TTL
If the lease is lost, the worker stops the CLI and treats the claim as
superseded. If cancellation is requested, it stops the CLI and reports
cancelled.
Central reaps leases every 15 seconds. Expired or over-wall-clock runs become
failed, release their worker, and may enter the configured automatic retry
path.
Verification
After a successful CLI exit, the worker runs the task's optional
verification_command. The command is parsed as argv and runs in the project
directory. Verification output becomes part of the result and trace.
A failed run with auto_retry_on_failure=true is requeued up to
max_verification_retries. Central pins the retry to the same worker and
uses the prior CLI session when the engine returned one.
Durable result delivery
Before the first result request, the worker writes a JSON entry to:
<data_root>/outbox/<worker_id>/<task_id>-<fence>.json
The entry includes the result payload and its run token. The worker drains pending entries on later polls and after restarts.
Central returns an explicit outcome:
| Outcome | Meaning |
|---|---|
accepted | Current result applied |
duplicate | The same task and fence was already recorded |
superseded | A newer claim owns the task |
| task gone | HTTP 404, so there is no target left |
All four remove the outbox entry. Network and authentication failures retain it. Other non-retryable client errors are quarantined as rejected evidence.
Checkpoint approval
Central applies supervision after authentication, fence checks, and result deduplication.
Checkpoint mode
- The worker runs with its resolved task permission.
- A successful result becomes
status: checkpoint, stagefinal. - The worker is released and the lease is cleared.
- An operator approves, requests revision, or fails it.
Supervised mode
- Central serves the first claim as
safe. - A successful planning result becomes a
plancheckpoint. - Approval requeues a write stage, pinned to the same worker.
- Central resumes the prior CLI session when available.
- The successful write result becomes a
finalcheckpoint. - Final approval marks the task complete.
Revision feedback is appended with a bounded history. Human rejection does not consume or trigger the automatic machine retry budget.
Sessions, dependencies, and schedules
- A session groups related tasks and provides aggregate context.
- A child task is not offered until its parent is complete.
- A failed or cancelled parent cascades cancellation to pending dependents.
- A schedule stores a task template and one cadence:
every 90m,daily 03:00, orweekly sun 03:00. - Central checks due schedules every 30 seconds.
Traces and ledgers
Each claim has a stable run id. Each chat response has a turn id.
| Store | Purpose |
|---|---|
traces.sqlite3 | Sanitized lineage index |
traces/raw/<run_id>/ | Raw prompts, CLI events, and stderr |
runs.jsonl | Finished and superseded run summaries |
chat_usage.jsonl | Chat usage |
decisions.jsonl | Checkpoint decisions and grades |
Chat traces return manifests and private artifact references. Task-run traces currently include full task result and error content inside the outcome object. Treat the task trace API as content-bearing and sensitive.
Security layers
- Loopback-only access is the default.
- A shared bearer token protects Brain and Forge when remote access is enabled.
- Browser origins are allowlisted.
- Project registration roots are allowlisted.
- Worker tokens bind worker identity.
- Run tokens bind writes to a specific claim and fence.
- Worker permission ceilings limit task authority.
- Provider-key distribution has a separate opt-in switch.
These controls do not provide per-human roles. Client-scope fields and filters exist on selected retrieval routes, but chat, direct tools, and direct record reads do not all pass through them. The current build is not a complete multi-client confidentiality boundary.
Failure behavior
| Failure | Result |
|---|---|
| Second Central uses the same data root | Process lock rejects startup |
| Central database is on WSL drvfs or 9P | Startup rejects the unsafe path |
| Worker dies during execution | Lease expires and task fails or retries |
| Central is down when a run finishes | Result remains in worker outbox |
| Old worker reports after a retry | Fence marks it superseded |
| Same result is delivered twice | Deduplication returns duplicate |
| Worker credential is lost | Identity re-registration returns 401 until operator reset |
| Run token is missing for a credentialed claim | Lease or result request returns 401 |
| Brain is unavailable during a CLI task | Rules, memory, and learning degrade, but execution can continue |
| Project path exists only on another OS | Execution fails unless routing is pinned correctly |
See Architecture, Brain, Forge, and Runbook for the operator view.