Skip to content

Architecture

Athena’s public API is a single HTTP server. Requests pass through three layers — auth, rate limiting, and the workflow engine — before producing a response.


System Components

ComponentRole
API ServerHTTP server — auth, rate limiting, routing, request validation
Workflow EngineBFS state-graph executor — drives every agent execution
Intelligence ServiceLLM dispatch — 15 providers, circuit breaker, fallback, prompt caching
Credit SystemThree-bucket ledger (active / frozen / inactive) — pre-deduct before LLM calls, reconcile after
File StorageS3-compatible — signed URLs, multipart uploads, thumbnails
WorkerBackground jobs — media generation recovery, stale execution cleanup
Primary datastoreDurable storage for agents, executions, conversations, knowledge embeddings, and cold checkpoints
Cache layerHot path — auth tokens, rate-limit counters, execution checkpoints, pub/sub for streaming

Request Pipeline

Every agent execution passes through three layers:

API Handler
→ rate_limit_middleware (per-agent / per-customer / per-workspace)
→ auth_middleware (JWT / API key → workspace context)
→ workspace_middleware (workspace resolution + capabilities)
ExecutionService
→ credit pre-check
→ execution record created
WorkflowEngine (BFS loop over node queue)
→ enforce_budget (token + cost caps)
→ credit_pre_deduct per AI node
→ execute_node (dispatches to node type handler)
→ credit_reconcile after AI node
→ checkpoint after every node
IntelligenceService (per AI node)
→ CircuitBreaker.should_allow(provider)
→ LLM call
→ hooks: tracing, cost tracking, rate-limit check, tool policy
→ fallback if 429 / 5xx and node has fallback configured

Execution States

StateTrigger
QueuedRecord created before engine starts
RunningEngine loop started
CompletedBFS queue drained
FailedTimeout, budget exceeded, or unrecoverable error
AwaitingApprovalHumanGate node paused — waiting for a human decision
WaitingForExternalEventMediaGeneration node submitted — waiting for Fal.ai webhook
AwaitingClientToolLLM emitted a client tool call — waiting for your app to fulfil
CancelledCancelled via API

Workflow Node Types

The engine supports 11 node types:

NodePurpose
TriggerEntry point — emits initial parameters
Ai (LLM)LLM call — streaming or sync, with output-schema validation retry
RouterBranch selection — rules, round-robin, random, or LLM-based
ParallelFan-out — run sub-graphs concurrently under a semaphore
JoinMerge parallel results — concat, select_best, aggregate, llm_judge
MemoryRecall (hybrid retrieval) or Learn (async episode queue)
HumanGateHuman-in-the-Loop pause — execution resumes on decision
ActionHTTP / webhook call with SSRF protection
AgentInvocationNested agent execution (max depth 3)
LogicConditionals, loops, variable mutation, schema validation
MediaGenerationFal.ai image/video generation — async, resumes via webhook

LLM Providers

All 15 providers are routed through a single dispatch layer with per-provider circuit breaking and per-node fallback.

ProviderModalities
OpenAIchat, vision, tools, streaming
Anthropicchat, vision, tools, streaming, prompt caching
Google (Gemini)chat, vision, tools, streaming
Groqchat, tools, streaming
Coherechat, tools, streaming
Perplexitychat, streaming
xAI (Grok)chat, tools, streaming
OpenRouterchat, tools, streaming (model-dependent)
DeepSeekchat, reasoning, tools, streaming
Mistralchat, tools, streaming
MiniMaxchat, tools, streaming
Moonshot (Kimi)chat, tools, streaming
ZAi (GLM)chat, tools, streaming
XiaomiMimochat, tools, streaming
Fal.aimedia generation only

Auth Model

Token typePrefixLifetimeUse
Access token— (JWT)1 hourBrowser sessions
Refresh token— (JWT)30 daysSingle-use rotation
Workspace API keywak_Long-livedServer-to-server
Ephemeral API keyeak_1 min – 24 hClient-side, agent-scoped

Key lookup order in middleware:

  1. Authorization: Bearer <JWT> — user session
  2. X-API-Key: wak_... or X-API-Key: eak_... — API key path

SHA-256 hashes are stored. The raw key is returned once at creation.


Data Model

TableTenantKey relationship
workspaceroot tenant
userplatform account
agentworkspacehas inline workflow JSON
executionworkspacebelongs to agent + optional external customer
conversationworkspaceoptional scope for executions
external_customerworkspaceyour end-user, owns credit ledger
credit_transactionworkspaceper-deduct / reconcile / grant rows

The workspace is the isolation boundary. Nearly every table carries workspace_id. Soft-deletes use deleted_at.


Checkpointing

TierStoreTTLCompression
HotCache layer24 hourszstd-3
ColdPrimary datastore30 days

On resume, the hot checkpoint is tried first. Cold is the fallback.


  • Workflows — BFS loop, node types, and execution limits
  • Intelligence — provider matrix, circuit breaker, fallback
  • Credits — three-bucket ledger, RevenueCat integration, plan-change proration
  • Integrate: Execute — execution endpoints for client apps