能力标签
🛠
AI工具

递归语言模型运行时

基于 Python · 开源免费,本地部署,数据完全自主可控
英文名:pyrlm-runtime
⭐ 26 Stars 🍴 1 Forks 💻 Python 📄 MIT 🏷 AI 7.5分
7.5AI 综合评分
aianthropicgptllmopenaipython
✦ AI Skill Hub 推荐

AI Skill Hub 推荐使用:递归语言模型运行时 是一款优质的AI工具。AI 综合评分 7.5 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。

📚 深度解析
递归语言模型运行时 是一款基于 Python 的开源工具,在 GitHub 上收获 0k+ Star,是ai、anthropic、gpt、llm领域中的优质开源项目。开源工具的最大优势在于代码完全透明,你可以审计每一行代码的安全性,也可以根据自身需求进行二次开发和定制。

**为什么要使用开源工具而非商业 SaaS?**
对于个人开发者和有隐私需求的用户,本地部署的开源工具意味着数据不离本机,不受第三方服务商的数据政策约束。同时,开源工具通常没有使用次数限制和月度费用,一次安装即可长期使用,对于高频使用场景的总拥有成本(TCO)远低于订阅制商业工具。

**安装与环境准备**
递归语言模型运行时 依赖 Python 运行环境。建议通过 pyenv(Python)或 nvm(Node.js)管理 Python 版本,避免全局环境污染。对于新手用户,推荐先创建虚拟环境(python -m venv venv && source venv/bin/activate),再安装依赖,这样即使出现问题也可以随时删除虚拟环境重新开始,不影响系统稳定性。

**社区与维护**
GitHub Issue 和 Discussion 是获取帮助的最快渠道。在提问前建议先检查 Closed Issues(已关闭的问题),大多数常见问题都已有解答。遇到 Bug 时,提供 pip list 的输出、完整错误堆栈和最小可复现示例,能显著提高开发者响应速度。AI Skill Hub 将持续追踪 递归语言模型运行时 的版本更新,及时通知重要功能变化。
📋 工具概览

递归语言模型运行时 是一款基于 Python 开发的开源工具,专注于 ai、anthropic、gpt 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

GitHub Stars
⭐ 26
开发语言
Python
支持平台
Windows / macOS / Linux
维护状态
轻量级项目,按需更新
开源协议
MIT
AI 综合评分
7.5 分
工具类型
AI工具
Forks
1
📖 中文文档
以下内容由 AI Skill Hub 根据项目信息自动整理,如需查看完整原始文档请访问底部「原始来源」。

递归语言模型运行时 是一款基于 Python 开发的开源工具,专注于 ai、anthropic、gpt 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

📌 核心特色
  • 开源免费,支持本地部署,数据完全自主可控
  • 活跃的 GitHub 开源社区,持续迭代更新
  • 提供详细文档和使用示例,新手友好
  • 支持自定义配置,灵活适配不同使用环境
  • 可作为基础组件集成进现有技术栈或进行二次开发
🎯 主要使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
以下安装命令基于项目开发语言和类型自动生成,实际以官方 README 为准。
安装命令
# 方式一:pip 安装(推荐)
pip install pyrlm-runtime

# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install pyrlm-runtime

# 方式三:从源码安装(获取最新功能)
git clone https://github.com/apenab/pyrlm-runtime
cd pyrlm-runtime
pip install -e .

# 验证安装
python -c "import pyrlm_runtime; print('安装成功')"
📋 安装步骤说明
  1. 访问 GitHub 仓库页面
  2. 按照 README 文档完成依赖安装
  3. 根据系统环境完成初始化配置
  4. 参考官方示例或文档开始使用
  5. 遇到问题可在 GitHub Issues 中查找解答
以下用法示例由 AI Skill Hub 整理,涵盖最常见的使用场景。
常用命令 / 代码示例
# 命令行使用
pyrlm-runtime --help

# 基本用法
pyrlm-runtime input_file -o output_file

# Python 代码中调用
import pyrlm_runtime

# 示例
result = pyrlm_runtime.process("input")
print(result)
以下配置示例基于典型使用场景生成,具体参数请参照官方文档调整。
配置示例
# pyrlm-runtime 配置文件示例(config.yml)
app:
  name: "pyrlm-runtime"
  debug: false
  log_level: "INFO"

# 运行时指定配置文件
pyrlm-runtime --config config.yml

# 或通过环境变量配置
export PYRLM_RUNTIME_API_KEY="your-key"
export PYRLM_RUNTIME_OUTPUT_DIR="./output"
📑 README 深度解析 真实文档 完整度 88/100 查看 GitHub 原文 →
以下内容由系统直接从 GitHub README 解析整理,保留代码块、表格与列表结构。

pyrlm-runtime

Minimal Python runtime for Recursive Language Models (RLMs) — inspired by the MIT CSAIL paper "Recursive Language Models"_.

RLMs solve the long-context problem: instead of sending huge contexts directly to an LLM (which truncates or degrades), the context lives as environment state in a Python REPL. The LLM writes code to inspect, search, and chunk the data, making recursive subcalls to smaller models when needed. Result: handle arbitrarily large contexts with constant token usage per step.

Install dependencies

uv sync

Installation

pip install pyrlm-runtime

Or with uv:

uv add pyrlm-runtime

For live terminal visualization of the REPL loop with rich:

pip install "pyrlm-runtime[rich]"

Requirements: Python 3.12+

Optional: For the secure Monty REPL backend (Rust sandbox):

pip install pydantic-monty

Requires: pip install pydantic-monty

rlm = RLM(adapter=adapter, repl_backend="monty") ```

How MontyREPL handles complex objects: Python objects like Context can't run natively in the Rust sandbox. MontyREPL uses an object proxy system — methods are registered as external functions with {name}__{method} naming, and AST rewrites transform ctx.method() calls into ctx__method() calls transparently.

Variable persistence: MontyREPL uses AST-based detection of assignments, appending a capture dict to extract variable state from each execution.

Both backends implement the same REPLProtocol interface: exec(code) -> ExecResult, get(name), set(name, value).

Quick Setup

First, install the optional Elasticsearch extra:

pip install "pyrlm-runtime[elasticsearch]"
from pyrlm_runtime import RLM
from pyrlm_runtime.adapters import OpenAICompatAdapter
from pyrlm_runtime.retrieval import ElasticsearchRetriever

retriever = ElasticsearchRetriever(
    host="https://my-cluster.es.cloud.com",
    api_key="xxx",
    index="pdf_corpus",
    embedding_model="text-embedding-3-small",
)

rlm = RLM(adapter=OpenAICompatAdapter(model="gpt-5"), retriever=retriever)
answer, trace = rlm.run("Who signed document X?")  # No context needed

When a retriever is configured, four functions become available in the REPL:

es_search(query, top_k=10, filters=None)        # BM25 keyword search
es_vector_search(query, top_k=10, filters=None)  # Semantic similarity
es_hybrid_search(query, top_k=10, filters=None)  # Combined (recommended)
es_get(doc_id)                                    # Fetch full document

The retrieval layer is backend-agnostic: any object implementing the RetrieverProtocol (with search, vector_search, hybrid_search, get methods) works as a drop-in backend.

Quickstart

2. Basic usage

```python from pyrlm_runtime import RLM, Context from pyrlm_runtime.adapters import OpenAICompatAdapter

Common configurations by use case

Use caseConfiguration
Small context (<8K chars)Use SmartRouter — it will pick baseline automatically
Large corpus (10K+ docs)RLM(adapter, retriever=ElasticsearchRetriever(...)) — search on demand
Large context (>100K chars)RLM(adapter, conversation_history=True, parallel_subcalls=True)
Batch many independent promptsUse llm_batch(prompts) — always parallel, no config needed
Cost-sensitiveUse a cheaper subcall_adapter for subcalls
Safety-critical code executionrepl_backend="monty"
Deterministic extractionSmartRouter with DETERMINISTIC_FIRST profile
Complex multi-hop reasoningrecursive_subcalls=True, max_recursion_depth=2

Examples

ExampleDescriptionRequires API?
[minimal.py](examples/minimal.py)Basic RLM flow with FakeAdapterNo
[rlm_vs_baseline.py](examples/rlm_vs_baseline.py)Needle-in-haystack benchmark (MIT paper Figure 1)Yes
[smart_router_demo.py](examples/smart_router_demo.py)SmartRouter auto-selecting baseline vs RLM by context sizeYes
[bench_repl_python_vs_monty.py](examples/bench_repl_python_vs_monty.py)Raw REPL performance: PythonREPL vs MontyREPL (no LLM calls)No
[bench_rlm_repl_backends.py](examples/bench_rlm_repl_backends.py)Full RLM loop benchmark with both REPL backends (FakeAdapter)No

Run any example:

uv run python examples/minimal.py

Quick demo

RLM_CONTEXT_SIZES=5,30 uv run python examples/rlm_vs_baseline.py

Optional: custom endpoint (Ollama, LM Studio, etc.)

Retrieval (when retriever is configured)

es_search(query, top_k=10, filters=None)
    # BM25 full-text search → list of {doc_id, preview, score, metadata}

es_vector_search(query, top_k=10, filters=None)
    # Semantic similarity search → list of {doc_id, preview, score, metadata}

es_hybrid_search(query, top_k=10, filters=None)
    # Combined BM25 + semantic (recommended) → list of {doc_id, preview, score, metadata}

es_get(doc_id)
    # Fetch full document → {doc_id, content, metadata}

Configuration

Environment variables

```bash

Custom endpoint (optional)

LLM_BASE_URL="https://..."

1. Set your API key

```bash export LLM_API_KEY="your-api-key-here"

3. Run without external APIs (for testing)

from pyrlm_runtime import RLM, Context
from pyrlm_runtime.adapters import FakeAdapter

adapter = FakeAdapter(script=[
    "snippet = peek(80)\nsummary = llm_query(f'Summarize: {snippet}')\nanswer = f'Summary -> {summary}'",
    "FINAL_VAR: answer",
])
adapter.add_rule("You are a sub-LLM", "[fake] short summary")

context = Context.from_text("RLMs treat long prompts as environment state.")
output, trace = RLM(adapter=adapter).run("Summarize this.", context)
print(output)  # Summary -> [fake] short summary

API Reference

Any OpenAI-compatible endpoint

adapter = OpenAICompatAdapter( model="my-model", base_url="https://my-endpoint.com/v1", )


Uses environment variables: `LLM_API_KEY` (or `OPENAI_API_KEY`), `LLM_BASE_URL`.

#### GenericChatAdapter

For non-standard APIs with custom request/response formats.
python from pyrlm_runtime.adapters import GenericChatAdapter

adapter = GenericChatAdapter( base_url="https://custom-api.com", path="/chat/completions", model="custom-model", api_key="your-key", payload_builder=my_custom_builder, # Custom request format response_parser=my_custom_parser, # Custom response format timeout=60.0, max_retries=3, )


Auto-retries on 429, 500, 502, 503, 504 with exponential backoff. Supports context manager (`with GenericChatAdapter(...) as adapter:`).

#### FakeAdapter

Deterministic adapter for testing. No external API needed.
python from pyrlm_runtime.adapters import FakeAdapter

adapter = FakeAdapter( script=["code step 1", "code step 2", "FINAL_VAR: result"] )

API key (checked in order)

LLM_API_KEY="your-key" # Primary OPENAI_API_KEY="your-key" # Fallback

References

Retrieval Integration

For large corpora that don't fit in memory, the RLM can search external document indexes directly from the REPL loop. See the detailed architecture guide: docs/RETRIEVAL.md

Benchmark: RLM vs Baseline

The rlm_vs_baseline.py example reproduces the key finding from the MIT paper (Figure 1): RLMs maintain accuracy as context grows, while baseline approaches degrade due to truncation.

Figure 1 from MIT Paper

Figure 1: RLM accuracy remains high as distractor documents increase, while baseline accuracy drops.

Ask questions over the entire context

answer, trace = rlm.run("What are the main themes across all documents?", context) print(answer) ```

🇨🇳 中文文档镜像 AI 翻译 2026-05-26
英文原文章节由系统翻译为中文摘要,便于快速理解。完整原文见上方 "📑 README 深度解析"。
📌 简介

pyrlm-runtime 是一个专为 Recursive Language Models (RLMs) 设计的轻量级 Python 运行时环境。受 MIT CSAIL 关于 Recursive Language Models 论文的启发,该项目旨在解决大语言模型(LLM)在处理超长上下文时的截断或性能退化问题。不同于传统的直接发送长文本方式,RLM 将上下文作为 Python REPL 中的环境状态(environment state)进行管理,允许 LLM 通过编写代码来主动执行检查、搜索和分块操作���从而实现对海量信息的精准操控。

📋 环境依赖

在使用 pyrlm-runtime 之前,请确保您的开发环境已安装 Python 3.12 或更高版本。推荐使用 uv 工具进行依赖管理,通过 `uv sync` 命令可以快速同步项目所需的依赖环境。

🛠 安装步骤(Docker/pip/源码)

您可以通过 pip 或 uv 进行安装。使用 pip 时执行 `pip install pyrlm-runtime`;若使用 uv,请执行 `uv add pyrlm-runtime`。为了在终端获得带有 `rich` 库美化效果的 REPL 交互体验,建议安装扩展包:`pip install "pyrlm-runtime[rich]"`。此外,若需使用基于 Rust 沙箱的安全型 Monty REPL 后端,请额外安装 `pydantic-monty`。

🚀 使用教程

本项目提供了灵活的适配器机制。对于常规开发,可以使用 `OpenAICompatAdapter`。针对不同的应用场景,系统提供了差异化的配置方案:对于小规模上下文(<8K 字符),建议使用 `SmartRouter` 自动选择基准模型;对于大规模语料库(10K+ 文档),可通过配置 `ElasticsearchRetriever` 实现按需搜索;对于超长上下文(>100K 字符),则需配合特定的对话历史管理策略。

⚙️ 配置说明(含 MCP / env)

pyrlm-runtime 支持高度自定义的配置。您可以配置自定义的 API 端点(如 Ollama 或 LM Studio)来接入���地模型。当配置了检索器(Retriever)后,用户可以在 REPL 中直接调用 `es_search`(BM25 全文检索)、`es_vector_search`(语义相似度检索)或 `es_hybrid_search`(混合检索,推荐使用)来处理大规模文档,实现精准的知识检索。

🔌 API 说明

开发者可以通过设置环境变量 `LLM_API_KEY` 来配置 API 密钥。为了方便测试,项目内置了 `FakeAdapter`,允许开发者通过编写模拟脚本来模拟 LLM 的行为,无需调用外部 API 即可验证逻辑。此外,项目提供了完整的 API Reference 供开发者查阅各类核心类与方法的调用规范。

🔄 工作流/模块

针对无法全部装入内存的大规模语料库,pyrlm-runtime 集成了强大的 Retrieval Integration 功能。RLM 可以在 REPL 循环中直接与外部文档索引进行交互,实现实时搜索。关于检索系统的详细架构设计与工作流,请参阅 `docs/RETRIEVAL.md` 深度指南。

❓ FAQ 摘要

如果您需要针对整个上下文进行提问,可以直接使用 `rlm.run()` 方法。该方法会处理复杂的检索与推理逻辑,并返回最终的答案(answer)以及执行过程的追踪信息(trace),确保您能够清晰地了解模型是如何从海量文档中提取信息的。

🎯 aiskill88 AI 点评 A 级 2026-05-25

高效的递归语言模型运行时,值得关注

📚 实用指南(长尾问题)
适合谁
  • 构建企业知识库 / RAG 检索应用的团队
最佳实践
  • 本地部署优先选 GGUF 量化模型,节省显存并保持响应速度
  • 分块大小建议 256-512 tokens,向量库优选 pgvector 或 Qdrant
常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • embedding 模型与查询模型不一致导致检索失效
  • 显存不足直接 OOM — 优先降低 context 或换更小的量化模型
  • Python 依赖冲突:建议用 venv / uv 隔离环境
部署方案
  • CLI:直接 npm install -g / pip install,命令行调用
  • 本地部署:CPU 8GB 起,GPU 推荐 16GB+ 显存
  • 云端托管:可放在 Vercel / Railway / Fly.io 等 PaaS 平台
相关搜索
pyrlm-runtime 中文教程pyrlm-runtime 安装报错怎么办pyrlm-runtime 与同类工具对比pyrlm-runtime 最佳实践pyrlm-runtime 适合谁用
⚡ 核心功能
👥 适合谁
  • 构建企业知识库 / RAG 检索应用的团队
⭐ 最佳实践
  • 本地部署优先选 GGUF 量化模型,节省显存并保持响应速度
  • 分块大小建议 256-512 tokens,向量库优选 pgvector 或 Qdrant
⚠️ 常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • embedding 模型与查询模型不一致导致检索失效
  • 显存不足直接 OOM — 优先降低 context 或换更小的量化模型
  • Python 依赖冲突:建议用 venv / uv 隔离环境
👥 适合人群
AI 技术爱好者研究人员和学生开发者和工程师技术创业者
🎯 使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
⚖️ 优点与不足
✅ 优点
  • +MIT 协议,可免费商用
  • +完全开源免费,无授权费用
  • +本地部署,数据完全自主可控
  • +开发者社区支持,遇问题可查可问
⚠️ 不足
  • 安装和初始配置可能需要一定技术基础
  • 功能完整性通常不如成熟商业产品
  • 技术支持主要依赖开源社区,响应速度不稳定
⚠️ 使用须知

AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。

建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。

📄 License 说明

✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。

🔗 相关工具推荐
📚 相关教程推荐
📰 相关 AI 新闻
🍿 AI 圈相关吃瓜
🗺️ 相关解决方案
🧩 你可能还需要
基于当前 Skill 的能力图谱,自动补全的工具组合
❓ 常见问题 FAQ
pyrlm-runtime 是一款Python开发的AI辅助工具。开源AI工具:Minimal runtime for Recursive Language Models (RLMs) inspired by the MIT CSAIL p。⭐26 · Python 主要应用场景包括:AI模型运行和部署。
💡 AI Skill Hub 点评

总体来看,递归语言模型运行时 是一款质量良好的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。

📚 深入学习 递归语言模型运行时
查看分步骤安装教程和完整使用指南,快速上手这款工具
🌐 原始信息
原始名称 pyrlm-runtime
原始描述 开源AI工具:Minimal runtime for Recursive Language Models (RLMs) inspired by the MIT CSAIL p。⭐26 · Python
Topics aianthropicgptllmopenaipython
GitHub https://github.com/apenab/pyrlm-runtime
License MIT
语言 Python
🔗 原始来源
🐙 GitHub 仓库  https://github.com/apenab/pyrlm-runtime 🌐 官方网站  https://arxiv.org/html/2512.24601v1

收录时间:2026-05-25 · 更新时间:2026-05-26 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。