概要
Prime Agent は、再帰言語モデル(RLM)と永続化フレームワークを基盤に構築されたオープンソースのプログラミング・リサーチエージェントです。持続的な IPython 環境を使用し、コードを通じてファイル操作、Shell コマンド、サブエージェントを実行します。バックグラウンドデーモン、エージェント間通信、自律モードをサポートしており、長時間実行されるタスクに適しています。
README プレビュー
\n \n \n \n \n \n \n \n\n\n\nPrime Agent: A Self-Improving RLM Agent\n\n\n\n Documentation •\n Verifiers •\n PRIME-RL •\n pi-mono\n\n\n\n \n \n \n \n \n \n\n\nPrime Agent is an open-source coding and research agent for general and long-running work. It is designed around two core abstractions:\n\n- The **[Recursive Language Model (RLM)](https://www.primeintellect.ai/blog/rlm)** treats context as variables (*prompt-as-a-variable*) and tools like recursive subagents as function calls (*programmatic tool /sub-agent calling*) inside a persistent REPL.\n- The **[Continual Harness](https://arxiv.org/abs/2605.09998)** stores supplemental prompts, memories, skill descriptions, and reusable subagent specifications as durable state that Prime Agent can refine through small, evidence-backed updates, local to the session by default.\n\nPrime Agent combines a persistent Python control environment with durable harness state, so useful working context and reusable operating patterns can outlive a single chat window.\n\n- **Everything is programmatic:** persistent IPython is the built-in model tool; file operations, shell commands, tool use, subagents, and context management happen through code.\n- **Subagents are built in:** `rlm(...)` spawns real child agents for parallel or background work and returns their results programmatically.\n- **The harness can improve:** `/refine` reviews the current trajectory and can apply small, evidence-backed updates to supplemental harness state. It never rewrites the immutable base system prompt, and recorded snapshots support rollback.\n- **Skills are executable:** skills are importable Python packages, and the built-in skill creator can turn recurring workflows into project or personal skills.\n- **Sessions run in the background:** daemon-backed agents keep running when the terminal disconnects and can be reattached later.\n- **Agents communicate directly:** running agents can exchange messag
FAQ (5)
トラブル対応Bedrock Claude 5 でプロンプトキャッシュが cachePoint ブロックを送信せず、すべてのリクエストが新規入力として課金される問題を修正するにはどうすればよいですか?
これは prime-agent の packages/ai 0.7.x および commit 9fb6cde の main における packages/ai/src/providers/amazon-bedrock.ts のバグです。supportsPromptCaching() は -4-、claude-3-7-sonnet、または claude-3-5-haiku を含むモデル ID に対してのみキャッシュを有効にするため、claude-fable-5-1、claude-opus-5-5、claude-sonnet-5 などの Claude 5 ID では cachePoint ブロックが暗黙的に省略されます。AWS_BEDROCK_FORCE_CACHE=1 を設定しても機能しません。これは、関数がその環境変数をチェックする前に Claude モデルの分岐からリターンしてしまうためです。上流の修正を適用するか、Claude 5 以降のモデルを認識するように関数にパッチを適用してください: 既存の -4- および従来の Claude チェックの横に if (candidates.some((s) => /claude-(?:fable|opus|sonnet|haiku)-(?:[5-9]|\d{2,})(?:-|$)/.test(s))) return true; を追加します。より安全な長期的な修正は、3.7 以前のモデルの短い拒否リストを除き、すべての Claude モデルがキャッシュをサポートしていると仮定することです。packages/ai パッケージを再ビルドして再デプロイし、同じプレフィックスで 2 回連続の ConverseStream 呼び出しを行います。2 回目のレスポンスでは cacheReadInputTokens > 0 が報告されるはずです。us.anthropic.claude-fable-5-1 でのテストでは cacheReadInputTokens: 21829 が返されました。キャッシュ読み取りトークンと新規入力トークンを監視して、キャッシュが有効であることを確認してください。
トラブル対応不正な非ASCII CSIエスケープシーケンスが原因で発生する pa-tui のパニック "byte index is not a char boundary" を修正する方法
パニックが発生するのは、decode_csi_with_modifier が Unicode の文字数を str::split_at に渡しているためです。str::split_at は UTF-8 のバイトオフセットを要求します。\x1b[;éA のような入力に含まれる é のようなマルチバイト文字では、計算されたオフセットが文字の内部に入り込んでしまうことがあります。
crates/pa-tui/src/input.rs で、次のコードを:
let (modifier, final_char) = last.split_at(last.chars().count() - 1);
char_indices から導出したバイト境界を使う次のコードに置き換えてください:
let final_index = last
.char_indices()
.next_back()
.map_or(0, |(index, _)| index);
let (modifier, final_char) = last.split_at(final_index);
これにより、最後の UTF-8 文字の先頭で分割されます。その後、既存の modifier.parse::<u8>() が、TUI をクラッシュさせる代わりに、不正な形式のプレフィックスを通常どおり拒否します。issue #3175 の修正を含むビルドを使用してください。それまでは、不正な形式の非 ASCII CSI シーケンスをターミナルに送信しないでください。
トラブル対応カーネル再起動後に dill のスナップショット復元によって書き込みモードのファイルがゼロバイトに切り詰められるのを防ぐにはどうすればよいですか?
この障害は、dill 0.4.1 がクローズされたハンドルを含むファイルオブジェクトを _create_filehandle(name, mode) としてシリアライズするために発生します。_restore_state が dill.loads() を呼び出すと、dill は保存されたパスを再度開きます。保存されたモードが "w" の場合、再オープン時に O_TRUNC が使用され、ロード後のチェックがハンドルを閉じる前に、ファイルが警告なくゼロ化されます。
即時の回避策:
1. with open(...) as f の変数をカーネルの名前空間に残さないでください。ブロックの後で削除してください:
with open("/path/file.md", "w") as f:
f.write(data)
del f
2. 再起動する前に、名前空間からファイルオブジェクトをすべて削除してください:
import io
for name, value in list(globals().items()):
if isinstance(value, io.IOBase):
try:
value.close()
except Exception:
pass
del globals()[name]
3. dill の _create_filehandle を含む既存のスナップショットレコードは、dill.loads() が実行される前に破棄または除去する必要があります。ロード後にオブジェクトをチェックしても、デシリアライズ中にファイルがすでに切り詰められているため、手遅れです。
prime-agent-runtime/src/rlm/repl.py の _snapshot_state(約714行目)での恒久的な修正:
import io
if isinstance(value, io.IOBase):
skipped.append({"name": name, "reason": "file handle"})
continue
また、デシリアライズの前に、_read_snapshot_records でレガシーな _create_filehandle レコードを除去してください。_restore_state でのロード後のファイルオブジェクトチェックは、多層防御のためのクリーンアップにすぎず、最初の O_TRUNC を防ぐことはできません。利用可能な場合は、v0.1.21 のリカバリ安全性修正を含むリリースにアップグレードし、影響を受けたファイルをバックアップから復元してください。
トラブル対応なぜ ACP の session/prompt は、モデルのレスポンスが max_tokens で切り捨てられた場合でも end_turn を返すのですか?
これは prime-agent の ACP stop-reason マッピングにおけるバグです。キャンセルフラグと自律トークン予算ステータスのみを考慮するため、finish_reason: "length" を返した最後のモデル呼び出しが stopReason: "end_turn" として誤って報告されます。修正 acp: report max_tokens when the final model response was truncated を含むリリースにアップグレードしてください。ソースからビルドする場合は、crates/pa-daemon/src/acp/meta.rs 内の acp_stop_reason_for_status と、acp-stop-reason.ts 内の TypeScript の acpStopReason マッピングを更新し、最後のアシスタントメッセージの stopReason: "length" が ACP の stopReason: "max_tokens" にマッピングされるようにしてください。回避策としては、呼び出しごとのモデルトレースを調べ、finish_reason=length であるか、出力トークン数がトークン上限と等しい場合を切り詰め(truncation)として扱ってください。
トラブル対応oMLX / OpenAI互換のローカルモデルで、自動コンパクションが「Prompt is too long: N tokens > M maximum context length」エラーで失敗するのはなぜですか?
オーバーフロー検出器 is_context_overflow(crates/pa-ai/src/utils_inner/overflow.rs)は oMLX の 400 エラーメッセージを認識しないため、コンパクション、末尾のアシスタントメッセージの削除、リトライのいずれも行われず、セッション内の後続のプロンプトはすべて同じように失敗します。これは正規表現の 2 つの抜け漏れが原因です: (1) prompt is too long パターンは大文字小文字を区別しますが、oMLX は "Prompt" を大文字で始めています。(2) maximum context length is \d+ tokens パターンは、oMLX の N tokens > M maximum context length とは異なる語順を想定しています。修正方法: パターンを (?i)prompt is too long に変更する、および/または新しいパターン (?i)tokens > \d+ maximum context length を追加します。パッチが適用されるまでの回避策: コンテキストウィンドウの小さいモデル(例: 大規模な OpenRouter モデルから 262k のローカルモデル)にセッションを切り替える場合は、オーバーフローが発生する前に手動でコンパクションを実行するか、新しいセッションを開始してください。