Skip to content

Latest commit

 

History

History
176 lines (138 loc) · 9.25 KB

getting-started.md

File metadata and controls

176 lines (138 loc) · 9.25 KB

Getting Started

Concept

Technical depth: Commands and code for building on Loopex.

This guide is the first stop for a developer building on Loopex: running it inside your own Elixir application, driving its sessions from a program in any language over the session protocol, or replacing one of its boundaries.

Everything starts from a source checkout, such as the v0.4.0 source release. Nothing is published as a binary or package, and no surface is stable yet: every API, option, record, and wire shape named here may change between revisions, so pin an exact revision and read Compatibility surfaces before depending on one. The guide routes to the pages that own each topic rather than repeating them. Changing Loopex itself — its toolchain, checks, milestones and commits — is covered by DEVELOPMENT.md and the development process.

What You Are Working With

Loopex is an OTP runtime for coding-agent sessions. A runtime is a supervised process tree a host starts explicitly and names by an opaque reference. A session is a conversation between an operator and a model, with its history written by exactly one process at a time. The durable profile keeps that history in an append-only local journal so a session can be resumed; the ephemeral profile keeps the same ordering in memory and loses the session when its VM ends.

A run is one task inside a session: the model is asked, may call tools, and is asked again until it stops, a declared bound is reached, or the run is stopped. Tools act on a workspace through an executor, and every tool call is decided by the host's policy — Loopex never grants itself authority.

A caller watches a session by attaching at a position in its committed event stream. Committed events are truth and arrive at least once, in order; progress — the model's text as it streams, a command's output as it runs — is a transient rendering aid that may be dropped.

Five replaceable boundaries, called ports, separate the kernel from everything concrete: the Store, the Model, the Executor, the ArtifactStore, and the Policy. The reference compositions select different Store and Model implementations; neither supplies a Policy, which every host must provide.

Technical depth: Building from source.

Building On: Embed a Runtime in an Elixir Host

An embedding host calls the Loopex facade in process. It starts a runtime, creates or resumes a session, attaches, submits commands, and reads events; the runtime runs the loop. For one answer or a multi-turn session without recovery, LoopexComposition.Ephemeral provides run/2 or a session handle. It uses an in-memory Store and calls a local Ollama model without a credential or provider companion. The same profile can use hosted models when their provider key is in the host environment. For retained sessions, LoopexComposition wires the local Store, the separate provider companion, and the local executor. A host that wants different edges composes the ports itself and starts the runtime directly. Both profiles use the same kernel and require a host policy; neither has a permissive policy default.

What the host must decide, and Loopex will not decide for it:

  • whether the session must survive the VM — choose the durable profile and a state root if it must;
  • which workspace the tools may touch;
  • who authorizes tool calls — a policy module, with a stable identity for durable interaction recovery; and
  • how much context one request may carry — a context token budget (the reference composition defaults it; a direct runtime requires it).

The durable reference stack needs a hosted provider credential and its private companion process, built once from the checkout. The ephemeral Ollama path needs a running local Ollama server and model, but no provider key, state root, or companion at runtime. Its hosted path reads the selected provider key in the host VM during each call; it is not a credential-isolation boundary from tools or trusted host code. A direct runtime can also start with no model or tools: given the host's captured session-creation settings, it creates, attaches to, and recovers durable sessions but runs no turns.

The full contract is Runtime and embedding; the turn machine behind it is Agent loop and tools.

Technical depth: A one-call host and durable embedded host.

Building On: Write the Host Policy

The policy is the one boundary every host implements. It receives a bounded description of one tool call — which tool, its arguments, its effect class, the workspace — and answers allow, deny, or defer. A well-formed defer pauses for a host decision. A policy that crashes, blocks, or answers malformed data denies. That denial is reported to the model and never retried.

Defer is how a host asks its operator: it poses one bounded multiple-choice question, and when an answer arrives the same policy is asked again with the answer attached. The answer never grants anything by itself. The durable profile retains a pending question across restarts; an ephemeral session can answer it only while its owner and VM remain live. A one-shot run/2 cannot answer a deferral, so use start_session/1, ask/3 and answer/3 for a policy that may defer.

Technical depth: A first policy.

Building On: Drive Sessions Over the Wire

A program in any language can drive a session over the experimental session protocol: one JSON object per line, with an exact generation negotiated first. The foreground app server speaks it over standard input and output for one client at a time, and a daemon speaks it over a Unix-domain socket for many clients that may observe one session while one controls it. Both are launched by a host that chooses the store, provider authority, defined tools, and policy. A client drives sessions and, within those host choices, may pick a new session's initial settings and tools or reconfigure a settled session, but never supplies those host inputs.

The protocol is strict on purpose — a client that relies on a lenient parser is not conformant — and it separates durable events, which advance a client's cursor, from progress, which does not. An independent client written in plain JavaScript ships in clients/node and is the best worked example.

The contract is the session protocol pair; the daemon's hosting model is the daemon pair; running either is covered by the operator pages for the app server and the daemon.

Technical depth: A first protocol client.

Technical depth: Against a daemon.

Building On: Replace a Port

A different store, model provider, or executor is an edge application that implements one behaviour and depends inward on core. It joins the port's shared conformance suite rather than writing its own, returns only bounded plain data across the boundary, and is wired by a composition — core never learns its name. The ports, their callbacks, and the suites are in the architecture pair.

Technical depth: Adding an adapter.

Where Things Live

The repository is one Elixir umbrella of eleven applications under apps/ and an independent client under clients/. Dependencies point inward to the kernel, apps/loopex; an edge or host you add depends on it the same way. Public modules and functions document a Concept section before a Technical depth section, so the generated documentation reads purpose first.

Technical depth: The repository map.

Diagnosing a Running Runtime

Loopex is diagnosed through its own observability rather than by adding print statements: a host starts a trace session through the runtime reference it holds, and telemetry spans arrive at every port call and transaction. Both are bounded, redacted, and never truth or authority. The contract is the observability pair; the levels an operator turns on are in the operator runbook.

Technical depth: A first trace session.

Related