Athena Loops 标志

Athena Loops

社区
luckeyfaraday

MIT-licensed, backend-agnostic AI agent orchestration loop in Python: orchestrator→worker→reviewer as a deterministic harness. Drive coding-agent backends through an MCP server + CLI.

发布者luckeyfaraday
代码仓库athena-loops
语言Python
复刻数
13
星标数
61
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    Athena Loops 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 61 个星标和 13 个复刻。

Athena Loops — backend-agnostic AI agent orchestration loop for Python

License: MIT

agentloop is a lightweight Python framework for multi-agent orchestration. It implements the orchestrator → worker → reviewer pattern (the AI agent orchestration loop) as a deterministic harness with a closed feedback loop: a goal is decomposed into subtasks, fanned out to worker subagents, aggregated, and run through a review gate that loops until the work meets its success criteria. One loop drives any LLM backend — Anthropic Claude, Claude Code, Codex, opencode, or aider — through a single Agent interface, and it ships as both an MCP server and a plain CLI so any coding agent can call it.

The design principle: the loop is a harness (deterministic code), not a skill. A prompt can describe "decompose, review, loop until done" but can't guarantee it. So the control flow lives in code, and the model-facing judgement (how to decompose, the review rubric) lives in swappable prompts. One harness drives any backend through a single Agent interface.

Peter Steinberger: "You should be designing loops that prompt your agents."

The tweet that started it all — Peter Steinberger (@steipete): "You shouldn't be prompting coding agents anymore. You should be designing loops that prompt your agents." agentloop is that idea as a reusable harness.

            ┌──────────── harness (this package) ────────────┐
goal ─▶ decompose ─▶ fan-out to subagents ─▶ aggregate ─▶ review gate ─▶ done?
            ▲                                                          │ no
            └──────────────── feedback: refine plan ◀──────────────────┘

Quick start

bash
python3 -m examples.run_demo        # zero-dependency MockAgent
python3 -m pytest                   # full test suite, no deps
python
from agentloop import Orchestrator, Budget
from agentloop.adapters import MockAgent

orch = Orchestrator(MockAgent(), budget=Budget(max_iterations=4))
result = orch.run(
    goal="Write a briefing on the orchestrator-worker pattern.",
    success_criteria="Covers decomposition, execution, review, and the feedback loop.",
)
print(result.completed, result.iterations, result.stop_reason)
print(result.final_output)

Use a real model

Claude via Anthropic:

bash
pip install -e ".[claude]"
export ANTHROPIC_API_KEY=sk-...
python3 -m examples.run_demo --claude

Grok via xAI's OpenAI-compatible API:

bash
pip install -e ".[grok]"
export XAI_API_KEY=xai-...
python3 -m examples.run_demo --grok

GrokAgent defaults to grok-build-0.1 for coding-oriented loop work; pass model="grok-4.3" or --model grok-4.3 for general chat-style work.

Grok Build CLI as the worker:

bash
curl -fsSL https://x.ai/cli/install.sh | bash
grok login
agentloop run --goal "Add a /health endpoint + test" --criteria "test passes" \
  --backend grok_build --cwd /path/to/repo --skip-permissions

Use backend="grok_build" for the local Grok Build CLI (grok -p), or backend="grok_api" for direct xAI API calls.

Plug into any coding agent

The loop is pluggable in two directions, both thin wrappers over the Agent seam:

Inward — coding agents are the workers. CliAgent runs each role (decomposer / subagent / reviewer) through a headless coding-agent CLI, so the workers get that agent's tools, file access, and repo context:

python
from agentloop import Orchestrator
from agentloop.adapters import CliAgent

# Point the worker at a repo and let it actually edit files headlessly:
agent = CliAgent.claude_code(cwd="/path/to/repo", skip_permissions=True)
orch = Orchestrator(agent)                     # or .codex() / .opencode() / .aider() / .grok_build()
result = orch.run(goal="Add a /health endpoint + test", success_criteria="test passes")

Knobs for autonomous coding workers:

  • cwd=... — run the worker inside a specific repo (works for every preset).
  • skip_permissions=True — let the worker use tools without prompting (--dangerously-skip-permissions / --dangerously-bypass-approvals-and-sandbox / --yes-always). Needed for headless coding, but it bypasses all safety prompts — point it at a worktree or throwaway branch, not your main checkout.
  • timeout=... — seconds to cap each worker CLI call. Default is None (no cap): a real coding worker is slow and unpredictable, so a short per-call timeout just kills it mid-task and throws the work away. Bound the run instead with Budget(max_seconds=...), which is checked between iterations.
  • verify_commands=[...] — run real commands after each worker iteration and feed failures back into the next loop. Use this for deterministic checks like python3 -m pytest, npm test, or npx playwright test. Any failing verifier blocks completion even if the reviewer would otherwise accept the work.

For big builds, keep subgoals small (the worker has to finish one in a single call) and give the loop room with max_iterations; one cold worker can't build everything in one shot.

Auth piggybacks on the CLI's own login, so Claude.ai, ChatGPT, or Grok Build subscription/OAuth sessions work with no provider API key.

Isolated runs. The safe default for skip_permissions is to run inside a throwaway git worktree on its own branch — your main checkout is never touched:

python
from agentloop import Orchestrator, worktree
from agentloop.adapters import CliAgent

with worktree("/path/to/repo") as wt:               # new branch + checkout
    agent = CliAgent.claude_code(cwd=wt.path, skip_permissions=True)
    Orchestrator(agent).run(goal="...", success_criteria="...")
    print(wt.changed_files())   # what the run touched
    wt.commit("agentloop run")  # optional: persist on the branch

Cleanup mirrors the harness's own worktrees: cleanup="auto" (default) keeps the worktree iff the run changed something (so you can inspect/merge the branch) and removes it if it left nothing; "always" / "never" force the choice.

Partial work is never lost. When you orchestrate against a repo, the loop commits the worktree after every iteration (agentloop: iteration N). So if a later iteration fails or a budget guard stops the run, each completed iteration's work is preserved as a checkpoint commit on the branch — recoverable, not discarded. The result's worktree.checkpoints lists them. Workers are also told to inspect the working directory and continue from prior work rather than restart, so a retry builds on what's already there instead of clobbering it.

The example runner isolates automatically when given a repo:

bash
python3 -m examples.run_with_cli_agent claude /path/to/repo
bash
python3 -m examples.run_with_cli_agent claude   # codex | opencode | aider | grok

Custom CLI? It's just a command template ({prompt}, {system}, {combined}; no prompt placeholder ⇒ text is piped on stdin):

python
CliAgent(["my-agent", "--system", "{system}", "--ask", "{prompt}"])

Presets are starting points — CLI flags vary by version; confirm yours and tweak agentloop/adapters/cli.py. A non-zero exit or timeout becomes a FAILED task (with retries), not a silent wrong answer.

Outward — a coding agent calls the loop. An MCP server exposes the loop as a tool, so any MCP-aware agent (Claude Code, Cursor, Codex, opencode, Cline, Windsurf) can invoke it. By default backend="auto" uses the same agent family as the caller when detectable; pass backend explicitly to override it.

bash
pip install -e ".[mcp]"                # installs the `mcp` SDK
python3 -m agentloop.mcp_server        # stdio transport

Tools:

  • orchestrate(goal, success_criteria, backend, cwd, max_iterations, skip_permissions, isolate, model, verify_commands, verify_timeout, playwright, detach=true) — runs the loop. Detached by default: returns { status: "running", run_id, … } immediately and runs to completion in the background — you monitor it (see below). Pass detach=false to instead block and get the result (or { status: "needs_input", questions[], token }) back in a single call.
  • orchestrate_resume(token, answers, detach) — continues a run that asked for input
  • orchestrate_status(run_id) — light status of a detached run (phase, iteration, running)
  • orchestrate_tail(run_id, cursor, limit) — the events a detached run produced since cursor
  • orchestrate_result(run_id, wait, timeout) — the final result of a detached run
  • orchestrate_list() — every detached run this server has started, with status
  • list_backends() — the worker engines this server can drive
  • doctor(cwd?) — non-invasive diagnostics for backend CLI availability, target directory access, and timeout interpretation

A completed result is structured: { completed, iterations, stop_reason, final_output, summary, history[], worktree? } — summary is a one-line human-readable digest for the calling agent to show. While it runs, orchestrate streams a notifications/progress update when it starts and after every iteration (e.g. iteration 2/4: 3/3 subgoals ok, gates pass, goal incomplete), so the caller sees live status instead of a bare spinner. When cwd is given it runs in an isolated worktree (see above) by default.

Fire and monitor — the default. orchestrate runs detached: it returns a run_id immediately and the loop runs to completion (or error) in the background. There is no run timeout — you watch it rather than race it against a clock:

orchestrate(goal=…, cwd="/repo")   # backend="auto", detach=true by default
  -> { status: "running", run_id, run_dir, events_path, tail_command }
orchestrate_status(run_id)        -> { phase, iteration, running, … }   # poll until running=false
orchestrate_tail(run_id, cursor)  -> { events[], cursor, running, more } # or stream each step
orchestrate_result(run_id)        -> the final result, once running=false

Poll orchestrate_status (it returns instantly) until running is false, then read orchestrate_result. Avoid orchestrate_result(wait=true) with no timeout — that re-opens a request for the whole run, the very thing detached mode avoids. Intake runs in the background too, so even a slow or clarifying intake never blocks the start call; if it pauses, the result's stop_reason is needs_input (with questions + token) — answer it with orchestrate_resume.

The calling agent starts the run, then interleaves polling orchestrate_tail with talking to you — so you both see the loop work in real time: each subgoal as it's planned, every worker's start/finish and an output preview, the verification results, and the reviewer's verdict. Pass the returned cursor back to orchestrate_tail to get only what's new.

Every event is also appended to a durable JSONL log you can tail -f from any terminal, independent of the agent:

<cwd>/.agentloop/runs/<run_id>/
  events.jsonl     # one event per line — tail -f this
  status.json      # latest phase / iteration / running
  result.json      # the final result (written once, at the end)
  workers/         # full stdout of each worker call: iter<N>_<subgoal>.out

Worker output previews ride inline in the event stream; each worker's full output is written to workers/iter<N>_<subgoal>.out and referenced by data.output_path. Because the default flow returns at once, it sidesteps the MCP request-timeout problem entirely — there's no long-blocking call to time out.

Timeouts, briefly. The default detached flow has no run timeout and never holds an MCP request open, so the host's -32001 Request timed out cannot occur on it. That error applies only to the opt-in blocking mode (detach=false), where one request spans the whole run; if you use that mode, configure the host to wait generously (≥ 600000 ms). orchestrate(timeout=…) (per worker subprocess) and max_seconds (cooperative loop budget) remain optional hard kills — both default off; leave them unset for real coding runs and monitor to completion instead. Have agents call doctor() before guessing about missing CLIs or broken backend spawning.

Plug into Claude Code. Point PYTHONPATH at the repo so the server resolves the package no matter where Claude Code launches it (no install needed):

bash
claude mcp add athena-loops --scope user \
  -e PYTHONPATH=/abs/path/to/athena-loops \
  -- python3 -m agentloop.mcp_server

claude mcp list                        # -> athena-loops: ✔ Connected

Claude Code's CLI registration does not expose a per-server request-timeout flag; use doctor() to distinguish host timeout symptoms from backend availability.

--scope user makes it available in every project; use local for just this one, or project to write a shared .mcp.json. If you pip install -e . instead, the agentloop-mcp console script is on PATH and the -e PYTHONPATH=… is unnecessary: claude mcp add athena-loops -- agentloop-mcp.

Plug into Cursor / Cline / Windsurf (.mcp.json / mcp.json):

json
{
  "mcpServers": {
    "athena-loops": {
      "command": "python3",
      "args": ["-m", "agentloop.mcp_server"],
      "env": { "PYTHONPATH": "/abs/path/to/athena-loops" },
      "timeout": 600000
    }
  }
}

Then (restart the session first) ask the host agent to "use agentloop to orchestrate: ". The default backend="auto" picks the matching worker for the caller (codex from Codex, opencode from OpenCode, claude_code from Claude Code when detectable). Choose a concrete backend (claude_code, codex, mock, …) to override that.

For agents that don't speak MCP but can run a shell, there's a plain CLI over the same contract:

bash
agentloop run --goal "Add a /health endpoint + test" --criteria "test passes" \
  --cwd . --skip-permissions --json \
  --verify "python3 -m pytest" --verify "npx playwright test"
agentloop backends

--json prints the full result on stdout; --progress streams one NDJSON line per iteration on stderr; --goal - / --goal-file read long prompts. --verify is repeatable and runs each command after every iteration in the same repo/worktree as the worker. Exit code is 0 if completed, 1 if a budget guard stopped it, 2 on error — so scripts and agents can branch on the outcome.

For web/UI work, --playwright (MCP: playwright=true) is a one-switch shortcut that turns on browser-level testing across the whole loop: it adds npx playwright test as a verify gate and instructs the subagent to write/extend Playwright tests and the reviewer to require passing ones before completing. Leave --verify-timeout unset — browser launch is slow.

How the user gives input (intake & clarification)

Before any planning, the loop runs an intake phase: it can propose success criteria (if you didn't give any) and ask the clarifying questions it needs — the diagram's "App Follow-up Questions". Where the human answers is a second swappable seam, Interaction, mirroring the Agent seam:

SurfaceInteractionUX
Python / headless (default)AutoInteractionnever blocks; proceeds with best judgment
Interactive terminalConsoleInteractionprompts the human via input()
MCP / scripted CLISuspendInteractionreturns needs_input + a resume token instead of blocking

Terminal wizard — omit --goal and it asks; criteria and clarifying questions are prompted inline:

bash
agentloop run                         # Goal> … then proposes criteria + asks questions
agentloop run --goal "…" --non-interactive   # never prompt; use defaults

Inside another agent (MCP) — orchestrate(...) returns { status: "needs_input", questions: [...], token } when it needs answers; the host agent collects them from the user and calls orchestrate_resume(token, answers) to continue. Same flow on the CLI for tools:

bash
agentloop run --goal "build an API" --ask        # prints questions + token, exits 3
agentloop run --resume <token> --answer "FastAPI" --answer "Postgres"

Python — pass your own:

python
from agentloop import Orchestrator, ConsoleInteraction
Orchestrator(agent, interaction=ConsoleInteraction()).run(goal="…")  # criteria optional

The seam (where to put what)

LayerLives inWhat it owns
Harnessorchestrator.py, scheduler.py, types.pythe loop, fan-out, aggregation, review gate, termination guards, failure capture
Agent seamagent.py + adapters/one Agent.run(request) -> response per backend (Mock, Claude, …)
Skillsroles.pythe prompts inside each box: decomposer, subagent, reviewer rubric

To support a new backend, implement one method:

python
from agentloop.agent import Agent, AgentRequest, AgentResponse

class MyAgent(Agent):
    def run(self, request: AgentRequest) -> AgentResponse:
        text = call_your_model(system=request.system, prompt=request.prompt)
        return AgentResponse(text=text)

The three roles (Orchestrator, Subagent, Reviewer) are the same Agent invoked with different system prompts — not separate classes.

Two gaps in the original diagram, handled here

  • Termination guards — Budget caps iterations, wall-clock time, and total agent calls so the NO-branch can't spin forever.
  • Subagent failure handling — a subagent that raises becomes a FAILED TaskResult (with retries), visible to the reviewer and the feedback step, instead of crashing the run or being silently dropped.

Layout

agentloop/
  orchestrator.py   # the loop (deterministic harness) — emits live events
  scheduler.py      # parallel/sequential subagent execution + retries
  roles.py          # role prompts — the tunable "skills"
  agent.py          # Agent interface + robust JSON extraction
  types.py          # Budget, Subgoal, TaskResult, ReviewResult, LoopState, LoopEvent, ...
  interaction.py    # Interaction seam: Auto / Console / Suspend (intake & clarify)
  verifier.py       # CommandVerifier: real verify-command gate after each iteration
  runs.py           # detached background runs + the tail-able event log
  mcp_server.py     # MCP tools: orchestrate(detach), orchestrate_tail/status/result
  cli.py            # `agentloop run` / `agentloop backends` entry point
  adapters/
    mock.py         # deterministic, dependency-free (demo + tests)
    claude.py       # Anthropic SDK backend
    cli.py          # CliAgent: drive any headless coding-agent CLI as a backend
examples/run_demo.py, examples/run_with_cli_agent.py
tests/  # full suite (orchestrator, scheduler, CLI adapter, MCP server, ...)

FAQ

What is agentloop? A backend-agnostic Python framework that implements the AI agent orchestration loop — the orchestrator–worker–reviewer pattern with a closed feedback loop — as deterministic harness code rather than a prompt.

What is the orchestrator–worker–reviewer pattern? An LLM agent decomposes a goal into subtasks (orchestrator), parallel worker subagents execute them, and a reviewer gates the aggregated result against success criteria, looping with refined plans until done or a budget guard stops it.

Which LLM backends does agentloop support? Any model behind a single Agent.run() method. Built-in adapters cover a dependency-free MockAgent, Anthropic Claude, xAI Grok, and headless coding-agent CLIs — Claude Code, Codex, opencode, aider, and Grok Build — via CliAgent.

How do I orchestrate multiple coding agents from Claude Code, Cursor, or Cline? Run agentloop as an MCP server (python3 -m agentloop.mcp_server) and call its orchestrate tool, or use the plain agentloop run CLI from any agent that has a shell.

Does agentloop need an API key? No — when you drive it through a coding-agent CLI it piggybacks on that CLI's own login, so subscription/OAuth sessions can work without provider API keys. Direct API backends use their provider keys.

How does agentloop avoid infinite agent loops? A Budget caps iterations, wall-clock time, and total agent calls, and a failing subagent becomes a FAILED task result (with retries) instead of crashing or silently vanishing.

Is this like Peter Steinberger Loops / the agent loop technique? Yes — it's the same family of idea popularized by Peter Steinberger's writing on running coding agents in a loop ("Peter Steinberger Loops"). agentloop turns that pattern into a reusable, backend-agnostic harness with an explicit review gate and budget guards, rather than a one-off shell script.

License

Athena Loops is released under the MIT License.

安装

TypingMind
{
  "mcpServers": {
    "athena-loops": {
      "command": "agentloop-mcp",
      "args": []
    }
  }
}

将 Athena Loops MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Athena Loops 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 Athena Loops 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Athena Loops MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "athena-loops": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Athena Loops MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Athena Loops MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Athena Loops 帮我完成这项任务吗?
Athena Loops
当然,我看过了。
以下是我使用 Athena Loops 得到的结果。

常见问题

Athena Loops MCP 服务器有什么用途?

Athena Loops 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Athena Loops MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 Athena Loops。

为什么在 TypingMind 中使用 Athena Loops MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 Athena Loops 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Athena Loops MCP 连接到 TypingMind?

Athena Loops 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Athena Loops MCP 在 TypingMind 中提供哪些工具?

Athena Loops 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Athena Loops MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 Athena Loops 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇