SuperAPI AI Directory

theloop

theloop is an open-source project that encapsulates the AI agent loop as a stateless HTTP service. Each POST /runs request is one complete run: model→tools→model, supporting streaming output and per-attempt billing, and the engine retains no state after the run ends. Requests must carry all information (provider, model, key, prompt, full history, tool URLs and schemas, limits, etc.), making it suitable for multi-tenant scenarios; it supports write operations as intents approved and executed by the caller, and provides usage records, fallback chains, skills, and deferred tools.

Open website

About this tool

theloop is an open-source project that implements the AI agent loop as a stateless HTTP service, with code hosted on GitHub (https://github.com/paveler/theloop),采用 Apache License 2.0 license. Its core design is: one POST /runs request is one complete run, with the flow "model→tools→model", supporting streaming output, billing per provider attempt, and the engine retaining no state after the run ends.

Purpose and Positioning

This project is aimed at multi-tenant teams that need to deliver an assistant to a large number of users. The request carries all necessary information: provider, model, key, prompt, full history, tools (URL + schema), limits, etc. The engine itself has no database, no configuration, and no tenant registry; the caller's backend decides the assistant's behavior on each call.

Main Capabilities

  • Complete lifecycle of a single run: supports synchronous runs (wait: true) that directly return results and usage; asynchronous runs return stream_url (SSE) and cancel_url, results are delivered via callback.url, with retries, deduplication by run_id, and results can be read via GET /runs/{id} for recovery.
  • Write operations as intents: tools marked with effect: "write" return deferred and an operation id; actual changes are executed by the caller's system after approval, and the engine itself never executes changes.
  • Billable usage: records every provider attempt (including failures and interruptions), including uncached input, cache reads/writes, and estimation flags, with optional cost calculation based on a price table, and support for token and cost budgets.
  • Controlled egress: HTTPS only, host allowlist, private IPs and redirects prohibited, request headers filtered, and provider keys never appear in logs, SSE, callbacks, or error responses.
  • Multi-provider support: Anthropic, OpenAI, DeepSeek, GLM (z.ai), GigaChat, MiniMax, Kimi, and any OpenAI-compatible endpoint, with per-key queues and AIMD rate limiting.
  • Fallback chains: llm can accept an array, automatically switching to the next model when a provider fails, and the result states which model responded and the reasons for skips.
  • Mid-run message injection: POST /runs/{id}/messages can add user follow-ups or external events to a still-running run; the run picks them up at the next step boundary and responds within the same run, and unprocessed messages are returned as pending_messages.
  • Skills and deferred tooTools: skills[] uses the SKILL.md shape; after seeing the index, the model can load skill instructions and tools at runtime; deferred tools do not enter the context until introduced by a skill or search_tools (BM25), and the prompt cache can be preserved.
  • Debuggability: Each run and session has an event log (GET /logs); whether content is recorded is configurable, with support for in-memory storage or LOG_DIR daily file storage (retained for one week).
  • Display invariants: Marks harness-rendered content; the engine guarantees one card or one group per run, blocks do not enter tool steps, and validates that card values come from tool results.
  • Still responds when limited: When max_steps or max_tool_calls is reached, the last step carries no tools, ensuring the run ends with an answer rather than an empty error.

Usage

Running from source requires Node 22.9+; you can also use the Docker image (amd64 and arm64 images are provided with each release), or build it yourself: docker build -t theloop . && docker run -p 8080:8080 --env-file .env theloop. The example integration examples/sqlite-harness provides a complete SQLite-based harness (history, read tools, write tools with approval, conversation continuation, resume), and you can chat in the terminal via npm run example:sqlite.

Applicable scenarios and limitations

Suitable for multi-tenant scenarios where you embed the assistant into your own product, your backend already owns the data, you want to drive it over HTTP from any language or low-code platform, write operations require approval, and usage needs to be billed per attempt. It also supports local models (Ollama, vLLM, TGI, llama.cpp, LM Studio, etc.) and closed-network deployments, and content can be kept out of logs via LOG_CONTENT=none.

Regarding limitations: the project is at v1, and the contract is frozen (SPEC.md), but the implementation is still young, so expect fixes rather than contract changes; the engine does not execute changes, and the safety properties of write operations depend on the caller satisfying several guarantees (write endpoints only register intent, read tools truly have no side effects, approval and execution are completed in the caller's system, tool endpoints scope data by meta, only trusted servers hold ENGINE_TOKEN, etc.); the engine detects write-tool protocol errors after invocation, but has noway to undo changes that have already occurred. Specific details such as charges, pricing, and platform support have not yet been provided.