Skip to main content

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​

  1. Cortex loads usable providers from GET /chat/providers and influence choices from GET /chat/influences.
  2. The browser sends POST /chat/stream with the message, history, selected provider and model, reasoning lens, voice register, and supported generation controls.
  3. Brain assigns a conversation UUID and turn UUID.
  4. Brain resolves the requested influence selection and generation controls.
  5. Approved voice examples and relevant memory are retrieved.
  6. Brain builds trusted instructions and a separate untrusted evidence block.
  7. The LangGraph agent calls the selected provider. It may search knowledge, search CPMI, or call constrained Forge tools.
  8. SSE events return context, tool activity, and tokens to Cortex.
  9. Brain applies output linting and the optional local revision gate.
  10. The final done event contains the authoritative response and generation settings report.
  11. 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_DIR is 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​

  1. The worker discovers installed backends from the executable path.
  2. It identifies itself by hostname plus FORGE_WORKER_NAME.
  3. On first registration, Central mints a random worker token and stores only its SHA-256 hash.
  4. The worker saves the cleartext token with restricted permissions under its local Forge data root.
  5. 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:

  1. Revalidate the worker and route constraints.
  2. Change the task from pending to assigned.
  3. Assign the worker.
  4. Create a UUID run id.
  5. Increment the attempt number and fence.
  6. Create a lease with the server-owned TTL.
  7. Mark the worker busy.
  8. 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:

  1. Task id, project name, and resolved engine
  2. Task title, description, and optional spec
  3. Persona hint
  4. Up to five selected skills and their supporting files
  5. Active Brain rules
  6. Session history and parent-task context
  7. Directly read target-repository controls
  8. Relevant CPMI history labeled as untrusted evidence
  9. Verification expectations
  10. 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, or yolo to 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_ok
  • cancel_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:

OutcomeMeaning
acceptedCurrent result applied
duplicateThe same task and fence was already recorded
supersededA newer claim owns the task
task goneHTTP 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​

  1. The worker runs with its resolved task permission.
  2. A successful result becomes status: checkpoint, stage final.
  3. The worker is released and the lease is cleared.
  4. An operator approves, requests revision, or fails it.

Supervised mode​

  1. Central serves the first claim as safe.
  2. A successful planning result becomes a plan checkpoint.
  3. Approval requeues a write stage, pinned to the same worker.
  4. Central resumes the prior CLI session when available.
  5. The successful write result becomes a final checkpoint.
  6. 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, or weekly 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.

StorePurpose
traces.sqlite3Sanitized lineage index
traces/raw/<run_id>/Raw prompts, CLI events, and stderr
runs.jsonlFinished and superseded run summaries
chat_usage.jsonlChat usage
decisions.jsonlCheckpoint 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​

  1. Loopback-only access is the default.
  2. A shared bearer token protects Brain and Forge when remote access is enabled.
  3. Browser origins are allowlisted.
  4. Project registration roots are allowlisted.
  5. Worker tokens bind worker identity.
  6. Run tokens bind writes to a specific claim and fence.
  7. Worker permission ceilings limit task authority.
  8. 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​

FailureResult
Second Central uses the same data rootProcess lock rejects startup
Central database is on WSL drvfs or 9PStartup rejects the unsafe path
Worker dies during executionLease expires and task fails or retries
Central is down when a run finishesResult remains in worker outbox
Old worker reports after a retryFence marks it superseded
Same result is delivered twiceDeduplication returns duplicate
Worker credential is lostIdentity re-registration returns 401 until operator reset
Run token is missing for a credentialed claimLease or result request returns 401
Brain is unavailable during a CLI taskRules, memory, and learning degrade, but execution can continue
Project path exists only on another OSExecution fails unless routing is pinned correctly

See Architecture, Brain, Forge, and Runbook for the operator view.