Skip to content

Concepts

A Felix run takes one prompt, sends the conversation to a model, runs the tools the model asks for, and repeats until the model answers without asking for more. Every message is saved before the run moves on, so what is stored is always what happened. This page walks through the pieces in the order a run meets them.

An approval card in the web app, under the call's tool row, Write notes.txt (26 chars) for write_file, marked running. The card names the tool write_file and the rule workspace-write, quotes what Felix said before the call ('I'll create the notes.txt file with the exact content you specified.'), reads 'Confirm writes to the workspace.', titles the call 'Write notes.txt (26 chars)', and, opened, shows the change: before, 'No file there yet: approving creates it.'; after, 'Deploy checklist reviewed.'. It carries a deadline chip 'Auto-denies in 9:58', says 'Approving also allows every identical write_file call until the deadline, not just this one', and offers Approve write_file, Deny and Give a reason.

A run paused on a gated write_file, as the web app draws it: the file as it is and as it would be, the deadline after which the call is denied, and what approving grants. The rule is an agent’s (tools: [“write_file”], ttl_seconds: 600); the run’s frames were scripted for the capture. Full window.

  1. The session’s history is read and checked. History that ends with a tool call and no result is refused before anything else happens (see Interrupted calls).
  2. Your prompt is saved as a user message.
  3. The model streams its reply. Streamed text is for display; only the completed reply counts.
  4. The completed reply is saved. If it asks for tools, each call goes through the execution gate, runs, and has its result saved.
  5. If you steered the run, your text is saved as a user message.
  6. If the model called tools or you steered, the loop goes back to step 3. Otherwise the run ends.

A run also ends when it reaches its turn limit, exhausts a budget, is cancelled, or fails. The web app’s API and the terminal client both allow 20 model turns per prompt. On the last allowed turn the model is told that its tool calls will not run and is asked to answer, so a run that reaches the limit still ends with a reply when the model gives one.

Felix talks to every model through one interface: a model takes a system prompt, the conversation and the tool declarations, and streams back text followed by one completed message, with token usage when the provider reports it. The rest of Felix never sees which provider it is using.

Provider Used by
Workers AI (default) The API, through its AI binding. The terminal client, through the REST API with an account ID and token.
Anthropic, OpenAI, Google (Gemini), Vertex AI, Bedrock, Mistral The API and the terminal client, when the provider is set to anthropic, openai, google, vertex, bedrock or mistral.
Your own server The terminal client, when the provider names a server under providers in its settings.

A conversation is made of three kinds of message:

Message Holds
User Text you sent, a steering message, or a compaction summary.
Assistant The model’s text and the tool calls it made, each with an ID, a name and JSON arguments.
Tool The result of one call, matched to it by ID, and whether it is an error.

Messages are validated wherever they cross a boundary: from a provider, from storage and from HTTP. Tool arguments must be plain JSON. A result must answer a call that is still open, and no new message may come before every open call has a result.

Provider failures are classified. A rate limit, an overload, a 5xx status or a lost connection is retryable. A request the provider rejects as too large for the model’s context window is a context overflow, which has its own recovery (see Compaction). Error messages carry at most an HTTP status, never the provider’s response body.

A tool has a name, a description and a JSON parameter schema the model sees, plus two functions: parse, which validates the model’s arguments, and execute, which does the work and returns text. Two flags describe how it may run:

Flag Meaning
sequential Never run beside other calls. A batch that contains it runs one call at a time.
replaySafe Repeating the call has no further effect, as with a read. Felix uses this only to advise the model after an interruption; nothing is repeated automatically.

Each call goes through the same order: its start is announced, its arguments are parsed, the gate is consulted, it runs, and its result is saved. Cancellation is checked between each of these steps.

What happens Result the model sees Does the run continue?
Unknown tool or invalid arguments An error result with the reason, so the model can correct itself. Yes
The tool throws An error result with the message. Yes
The tool runs Its text. Yes

By default the calls in one reply run one after another. A run can opt into parallel execution: every call is announced, parsed and gated in order first, then the allowed calls run at the same time, and their results are saved in call order.

The terminal and hosted conversations opt in for the calls that can safely overlap: tools marked replaySafe (reads, searches, fetches) and tasks handed to child agents. A reply that includes any other call, such as a write or a command, runs its calls one after another.

Before a call runs, the application can decide whether it should. The gate, beforeTool, receives the call’s ID, name and parsed input, and the run’s cancellation signal. It can answer in five ways:

The gate Effect
Returns nothing The call runs.
Returns { input } The call runs with these arguments instead, for example ones an approver edited. They are validated like the originals; invalid ones become an error result.
Returns { block: true, reason } The call does not run. The reason is saved as an error result, the model reads it, and the run continues.
Returns { block: true, reason, stop: true } As above, but the run ends after this batch of calls. Calls in the batch that have not run are recorded as not run.
Throws The run stops. The call is left without a result, and no result is invented for it.

The gate is supplied by the application, never by a remote caller. The terminal client uses it to ask before each write: answering n blocks the call with the reason “refused by the user”, and the model carries on. The API accepts a gate from its own server-side configuration; an HTTP request cannot supply one or choose tools.

Each terminal extension sees its own copy of a tool call’s input. An approval gate can change the input by returning replacement arguments, which Felix validates before execution.

A second hook, afterTool, sees the approved arguments and can rewrite a call’s output before it is saved, for example to truncate or redact it. It cannot turn a failed call into a successful one.

A tool can end the run once its result is saved, when no further model turn is needed (for example, a tool that delivers the run’s final, structured answer): it calls context.endRun() before returning, and afterTool can ask for or withdraw the same by returning { endRun }. The run ends only when every result in the batch asks it to and none failed; otherwise the model reads the results as usual. On resume, Felix honors those requests even when the last result was saved just before the interruption. A message queued to steer the run during replay reaches the next model turn. If a tool result already records a gate’s Stop decision, recovery closes the remaining calls and ends the run. You can send a fresh prompt afterward.

On the API, the gate holds selected calls for a person’s decision: the stream sends approval_required, and the call runs, runs with edited arguments, or is refused once someone decides or the deadline passes. See Approvals in the web surface and the REST API.

A run can carry limits on tool calls, reported input and output tokens, and wall-clock time. They are checked before each inference and each tool call; work already running is not interrupted.

  • When the tool-call budget is spent, further calls get an error result telling the model to answer with what it has. The gate is not asked about them.
  • When the time or token budget is spent, waiting calls are refused the same way and the run ends before the next inference. Time spent waiting for approval counts toward the deadline, including approval of other tools in the same parallel batch. Context preparation and retry waits count too. Once the deadline passes, Felix skips further provider requests, including fallback requests.
  • Token budgets have no effect with a provider that reports no usage.

A run can also retry an inference after a retryable provider failure, as long as no text has streamed for it. Delays grow exponentially with jitter, respect a delay the provider asks for, and never pass the run’s deadline. The API and the terminal client retry twice. If you steer while a provider request is in flight, your message waits for the next model turn, even if a fallback model answers the current turn.

A session is where a conversation is kept. It has two operations, read and append, and may also store a compaction record. Felix appends each message and waits for the append to finish before the run takes its next step: the assistant’s reply is saved before any of its tools run, and a tool’s result is saved before the next call starts. If an append fails, the run stops rather than treating the failure as a tool error.

Session Where Who may write
Memory In the process; gone when it ends. The caller serializes access.
Session file .felix/sessions/ in the terminal client’s workspace by default. Replaced atomically, with private permissions. One felix process at a time, enforced by a lock file.
Hosted thread The API’s thread storage, one log per thread. One run at a time, enforced by a revision check and an expiring lease.

The session interface itself does not lock anything. Each kind of storage brings its own rule for who may write.

In the web app a thread is one conversation. There are two kinds (see Web surface):

  • Browser threads are kept in the browser. Each prompt sends the thread’s history along with it, and the API runs it against a memory session. Only completed replies join that history; a stopped or failed reply stays on screen but is not sent back to the model.
  • Server threads live on the API. A prompt names the thread and the revision you last saw, and the API reads its own copy of the history. If the thread has changed since, or another run holds it, the request is refused with HTTP 409 and you reload.
States a hosted thread run moves through on the RUNS Durable ObjectWith the RUNS binding, a hosted conversation run executes in the thread's Durable Object rather than in the request that started it. The host first records the run as in flight, then the run route takes the thread's lease; a lease another run holds or a revision that moved refuses the start with 409 run_in_progress or stale_revision, and no run exists. Otherwise the run streams. A tool call that an approval rule covers waits for a decision, polling the approval row until it is approved, denied or times out; a denial or a timeout reaches the model as a blocked result. A client tool, ask_user among them, waits until the client posts its result or five minutes pass, when the call fails. A steer posted to the thread is taken before the next model turn. The run ends complete, at its limit, failed when it errors or its stream breaks, or stopped when POST /v1/threads/ID/stop aborts it, from any waiting state too. A complete run leaves the thread idle; every other ending leaves it interrupted. A restart that ends the host mid-run leaves the in-flight record, and the next alarm or request finds it: with FELIX_RESUME_RUNS=on the host continues the thread from its committed history, taking over the lost run's lease, at most twice in a row without progress; otherwise the lease is released and the thread reads as interrupted. Closing a stream only detaches that client: GET /v1/threads/ID/events replays the run's kept frames after a position and then follows it live, kept in memory only.POST /v1/runs/stream with athreadId, in-flight record savedacquire, 409 run_in_progressor stale_revisionlease taken, status runninga queued steer is taken beforethe next model turnapproval_requiredapproval_resolved, approved,denied or timeoutclient_tool_callthe client posts a result, or 5minutes passend, completeend, limiterror or broken stream,run_failedPOST stop, run_stoppedPOST stop closes the requestas abortedPOST stopthe host restarted mid-runFELIX_RESUME_RUNS=on,continue on the lost lease, atmost 2 in a row withoutprogressresuming off, past the bound,or nothing to continueStartingRefusedStreamingAwaitingApprovalAwaitingClientCompleteLimitFailedStoppedLostReleasedGET/v1/threads/ID/events?after=run.seqreplays keptframes, thenfollows live.Closing a streamdetaches; the rungoes on.Hosted run lifecycle
Which states does a hosted run move through, from start to rejoin?Drawn from docs/diagrams/durable-run.mmd, which follows apps/api/src/runs/run-host.ts:createRunHost (start, pump, events, stop), apps/api/src/runs/recovery.ts:recoverRun, apps/api/src/routes/chat.ts (client tools, steering, finish), apps/api/src/approvals/gate.ts:approvalGate.

A hosted thread holds up to 1,000 messages and 1 MiB, with each message up to 128 KiB. A run has a ten-minute budget and its lease lasts fifteen minutes.

In the terminal client each conversation is a session file, and the picker switches between the files in the session’s directory (see Terminal client).

Steering adds to a run that is already going. If you steer while Felix prepares the first request, your message can reach the model on its first turn. Once the request is in flight, steering waits until the current model turn and its tool calls finish, is saved as a user message, and is read by the model on its next turn. Calls the model already asked for still run.

Steering is accepted only while another model turn remains, so a run never takes text it cannot answer. Text that was not delivered before the run ended is refused, not carried into the next prompt. In the terminal client, pressing Enter during a run steers it. In the web app a new message waits in a queue until the reply finishes or is stopped; on a server thread, a queued message of text alone can steer the running reply instead (POST /v1/threads/{id}/steer), and a steer the run ended without taking goes back to the queue.

Prompts sent to one session are queued and run one at a time. The queue lives in memory and holds eight waiting prompts by default. If the active prompt fails, the queue cancels its waiting prompts. If a turn limit, deadline, or token budget ends the run, the active prompt and its waiting follow-ups report which limit stopped it.

A long conversation can outgrow the model’s context window. With compaction on, Felix estimates the size of the context before each inference. When it would leave less than a reserve free (16,384 tokens by default), Felix first replaces large tool results (over 2,000 characters) from before the most recent messages with a one-line note saying which tool returned how much, in what the model sees only. If that is not enough, it asks the model to summarize the older messages and sends the summary in their place, followed by the most recent messages verbatim (about 20,000 tokens’ worth by default). Loaded skill instructions are never cleared. Both budgets shrink to a quarter of the window for small windows.

  • The stored transcript is never rewritten. A compaction is a separate record: the summary and the position of the first message kept. Session files and hosted threads store it beside the conversation.
  • A cut never separates a tool call from its result.
  • The summarizer treats the old messages as data, not instructions, and gets no tools. Its summary reaches the model framed as reference material.
  • If summarizing fails, the run continues uncompacted. If the provider still rejects the context as too large, Felix compacts once more and retries that inference; a second rejection fails the run.

On the API, each model compacts for its own context window, at most FELIX_MAX_CONTEXT_TOKENS (200,000 by default). The terminal client compacts when it knows the window: --context-window, FELIX_CONTEXT_WINDOW, the contextWindow setting, the model’s entry under models in settings, or the model catalog.

The terminal client’s /compact compacts on demand, and so does POST /v1/threads/{id}/compact on the API.

Memories are separate from compaction: the model proposes them with remember, a person keeps or drops each one, and recall reads the kept ones in later conversations. See Memory in the web app and /memory in the terminal.

A run can stop after the model asked for a tool but before its result was saved: the process was killed, the run was cancelled, the gate threw, or storage failed. The call may or may not have taken effect, and Felix cannot tell which. Such a session is refused by default.

Recovery is explicit. With it switched on, the next prompt first gives each open call of the last reply an error result saying its outcome is unknown. For a replaySafe tool the result says repeating it is safe; for any other it asks the model to check the call’s effects first. No tool is run again. Only the last reply’s calls can be closed this way; any other inconsistency in the history is refused, not repaired.

The terminal client always recovers this way, so a session cut off by Ctrl+C continues. Its read and list tools are replaySafe; its write and edit tools are not. The API recovers server threads the same way.

Every step of a run takes a cancellation signal, and tools receive it too. Cancelling stops the run at the next check. It cannot undo work that already finished: a message that was saved stays saved, and a file a tool already wrote stays written.

  • In the web app, Stop generating cancels the request. For a browser thread, or on a deployment without the RUNS binding, the API cancels the run when the connection closes. With RUNS, a server thread’s run keeps going after the connection closes, so the web app also stops it with POST /v1/threads/<id>/stop.
  • In the terminal client, Esc or Ctrl+C stops the run, and a write prompt left unanswered is refused.
Web app and API Terminal client
Model Configured on the API Worker. Chosen with --provider and --model.
Tools fetch_url and run_script when their bindings are configured, the time tools and calculate unless FELIX_TIME_TOOLS=off, web_search and the lookups the deployment turns on, tools from FELIX_MCP_SERVERS (with tool_search when their tools are deferred), the skill library tools, search_documents, generate_image and the Files image tools when configured, and in a conversation the plan tools, the workspace file tools, the memory tools, the sandbox tools when the sandbox is on, the GitHub and Google tools of a connected account, and, while its owner is the one talking, tools to schedule follow-up work and start workflows, each approved by a person; FELIX_DEFAULT_TOOLS can leave built-ins out. The plan tools; the time tools and calculate; web_search and the lookups your settings turn on; by default list_files, read_file, find_files, grep_files, write_file, edit_file and run_command (--read-only keeps only the first four; the defaultTools setting and --tools change the selection); read_skill when skills are found; tools from personal MCP servers.
Child agents delegate with FELIX_DELEGATE=on. delegate with --delegate.
Gate Server-side only, when configured. Asks before each write unless --yes is given.
History Sent by the browser, or read from a server thread. A session file in the workspace.
Steering On a server thread, a queued text message. Enter during a run.
Interrupted calls Closed as unknown on server threads. Always closed as unknown.
Compaction For each model’s window, at most FELIX_MAX_CONTEXT_TOKENS. For the window from --context-window, FELIX_CONTEXT_WINDOW, settings or the model catalog.

The plan tools let the model lay out work with three or more steps and keep its progress visible: plan_create (a title, an optional goal and the steps), plan_update_step (a step’s status: pending, in_progress, done, failed or skipped, with an optional note) and plan_get. Each answers with the whole plan, and both transcripts draw a plan where it was made. In the terminal the conversation is where plans live, so forking or rewinding takes its plans with it. A server conversation also stores them, so a person can edit or delete one in the web app’s inspector; the agent’s next run is told which plans changed and reads them again. A forked server conversation starts from the plans its conversation holds. Plans touch only the conversation, so they run in plan mode too. Server conversations get them; one-shot requests without a conversation do not.

For the screens themselves, see Web surface and Terminal client.

With delegation on, the model can hand a subtask to a child agent through the delegate tool. Each child gets its own session and a limited set of tools (the read-only workspace tools in the terminal; on the API fetch_url, the time tools, while scripts only compute run_script, and the workspace’s read and search tools when the run has them, never a tool that needs approval), with limits: at most 3 at a time and 8 per run, 10 model turns each. On the API, the model can also hand the task to one of the deployment’s named agents, whose model, instructions and tools the child then runs with. The child’s reply comes back to the model as untrusted data, and its messages are not added to the conversation.