Skip to content

feat(prime-agent): adapt Prime Intellect's Prime Agent over ACP - #62

Merged
xdotli merged 4 commits into
mainfrom
add-prime-agent
Aug 9, 2026
Merged

xdotli merged 4 commits into
mainfrom
add-prime-agent

Conversation

@xdotli

@xdotli xdotli commented Aug 7, 2026

Copy link
Copy Markdown
Member

feat(prime-agent): adapt Prime Intellect's Prime Agent over ACP

Adapts Prime Agent — Prime Intellect's self-improving RLM coding agent (MIT, released 2026-08-06, built on pi) — as a declarative manifest package at acp/prime-agent/.

Design

  • ACP native: prime-agent --mode acp is in-process (no daemon), stdio JSON-RPC, one session per connection — matches BenchFlow's ACP client exactly. The agent's single model-facing tool is a persistent IPython kernel.
  • Install pins the self-hosted npm release tarball (0.7.1; the project is not on npmjs) and pre-provisions the kernel environment at /opt/benchflow/prime-agent/kernel-venv (uv-managed Python 3.11 + ipykernel + the tarball's bundled prime-agent-runtime + default RLM packages). Everything is /opt-anchored so it works identically under the dropped-privilege sandbox user; first tool use needs no network.
  • Model routing is env-owned (no ACP set_model): supports_acp_set_model = false + BENCHFLOW_PROVIDER_MODEL in env_mapping engages core's model-via-env path (verified in run logs: "Skipping ACP model configuration"). The launcher generates a models.json custom provider from BENCHFLOW_PROVIDER_*; the API key is referenced by env-var name, never written to disk.

The compat landmine this PR documents and defuses

Prime Agent auto-detects provider compatibility from the base URL (resolveCompat, packages/ai/src/providers/openai-completions.ts): isNonStandard matches baseUrl.includes("deepseek.com") but not provider === "deepseek". Behind any proxy base URL the detection flips and the agent sends the system prompt as the developer role (plus store), which DeepSeek's real API rejects with a 400 (verified live; LiteLLM masks it by translating the role — i.e. a silent native-vs-benchflow divergence). The launcher therefore mirrors the full effective native compat for DeepSeek ids explicitly (supportsDeveloperRole=false, supportsStore=false, maxTokensField=max_completion_tokens, thinkingFormat=deepseek, requiresReasoningContentOnAssistantMessages=true, catalog contextWindow/maxTokens/thinkingLevelMap). This generalizes to any pi-family agent run through a gateway.

Verification (Daytona + DeepSeek)

  • Real task: SkillsBench citation-check — reward 1.0, 19 tool calls, 18 gateway-traced LLM roundtrips, usage_source=provider_response, cost $0.008 (deepseek-v4-flash; DeepSeek thinking + reasoning_effort=high survive the gateway).
  • Wire parity: request #0 (system prompt + tools + params) is byte-identical between a native run (models.json pointed at a local capture proxy → api.deepseek.com, isolated HOME) and the benchflow run's gateway trace, after exactly four named normalizations: model alias, cwd, install prefix, and two fields (max_completion_tokens, stream_options) that LiteLLM's post-parse trace view consumes (capture artifact — the response's usage confirms include_usage took effect).
  • Watchdog behavior: a model-written infinite-loop cell (buggy BibTeX parser) was correctly killed by the task's 900s wall-clock budget with clean reward 0.0 accounting — the intended backstop for kernel-based agents.
  • Batch (10 diverse SkillsBench tasks × deepseek-v4-pro, Daytona conc 10): 9/10 healthy rollouts (all with real tool calls + token accounting), 3 passes (3d-scan-calc, hvac-control, threejs-to-obj), 1 task wall-clock timeout (task budget respected), 1 infra failure unrelated to this agent (suricata-custom-exfil's image ships Python 3.9, which can't host the sandbox-local LiteLLM — benchflow-core issue, tracked separately). A full 87-task sweep + a second trial are running; results in PR comments.
  • Native-vs-benchflow outcome A/B (same benchflow-built Daytona env + verifier, but agent driven natively via -p with direct DeepSeek creds — no ACP, no gateway): citation-check native 1.0 = benchflow 1.0; lake-warming-attribution (v4-pro) native 0.0 = benchflow 0.0. Arms agree on both success and failure.

Notes

  • -p print mode reads piped stdin until EOF — drivers must close stdin.
  • Found in passing: acp/corust-agent/manifest.toml fails the contract schema (acp_model_format = "prefixed"), i.e. contract/ tests are red on main before this PR (fix tracked separately).

xdotli added 2 commits August 7, 2026 12:37
Declarative manifest for prime-agent 0.7.1 (self-hosted npm tarball release):
- ACP mode is in-process; model selection is env-owned (no ACP set_model)
- /opt-anchored uv kernel venv (Python 3.11 + bundled prime-agent-runtime)
  pre-provisioned at install so first tool use is offline and works under
  the dropped-privilege sandbox user
- launcher generates models.json from BENCHFLOW_PROVIDER_* env; API key is
  referenced by env-var name, never written to disk
- DeepSeek model ids mirror the full effective native compat: prime-agent's
  base-URL compat autodetection flips behind a proxy and sends the
  'developer' role, which DeepSeek's real API 400s (verified live); the
  explicit compat keeps wire behavior identical to a native run
…shness test

Review follow-ups:
- pin the release tarball to its official SHA256SUMS digest (the R2 bucket is
  a mutable trust anchor; Prime Intellect's own installer verifies the same)
- launcher: fail fast on JSON-unsafe model/base strings and on a missing API
  key env var; case-insensitive DeepSeek compat match; document why proxy/TLS
  env is stripped (wire parity with native runs)
- contract: generic freshness test — every acp/*/launcher.sh must match its
  manifest's embedded base64 blob byte-for-byte (pi-acp precedent)
@xdotli

xdotli commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Structural review done (approve): added a generic launcher-embed freshness test (contract/), checksum-pinned the release tarball against Prime Intellect's official SHA256SUMS, and hardened the launcher (JSON-unsafe input guard, API-key preflight, case-insensitive DeepSeek match, documented proxy-env stripping). Contract tests: 21 passed; the only failure on this branch is the pre-existing corust-agent schema violation from main. Full 87-task SkillsBench sweep + second 10-task trial are running; numbers to follow.

@xdotli

xdotli commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

87-task SkillsBench sweep (deepseek-v4-pro, Daytona conc 30) — stopped early on request; results from the 70 rollouts that ran:

  • 35 trusted completed rollouts (real tool calls + token accounting): mean reward 0.366
  • 13 tasks at 1.0: 3d-scan-calc, citation-check, court-form-filling, econ-detrending-correlation, edit-pdf, fix-visual-stability, gravitational-wave-detection, hvac-control, invoice-fraud-detection, jax-computing-basics, lean4-proof (+ partial credit: dialogue-parser 0.667, lab-unit-harmonization 0.625, crystallographic-wyckoff 0.27, debug-trl-grpo 0.25)
  • The other 35 rollouts are excluded as non-runs: most were in-flight when the job was intentionally stopped (session/PTY teardown artifacts); the remainder are the two known infra classes — sandbox-local LiteLLM cannot install on Python<3.10 task images (deterministic; core fix in progress) and transient Daytona session/sandbox-creation flakes at conc 30. None are agent-caused.
  • Largest healthy rollout: 89 tool calls / 4.2M tokens (latex-formula-extraction) — the kernel loop is stable over long horizons.

Note for reruns: per repo owner's testing policy, future DeepSeek runs use deepseek-v4-flash (0731 build), not v4-pro.

@xdotli

xdotli commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

Final head-to-head parity: original prime-agent vs benchflow-adapted, 25 SkillsBench tasks, deepseek-v4-flash, 1 trial/arm.

Arm A = repo-official install (install.sh, built-in deepseek provider, -p) driven inside the same benchflow-built Daytona task envs + verifiers, no ACP/no gateway. Arm B = bench eval run --agent prime-agent.

Metric Result
Comparable pairs 20 (5 tasks lost to persistent Daytona-side infra flakes on the B arm, listed below)
Exact agreement 15/20
Mean reward A 0.500 vs B 0.525
Disagreements symmetric: A>B on powerlifting-coef-calc, syzkaller-ppdev-syzlang; B>A on flood-risk-analysis, hvac-control, setup-fuzzing-py (0.5 partial) — all tasks with observed run-to-run flips within a single arm

Agreements include 8 joint passes and 7 joint failures. Verdict: no directional adaptation effect at 1-trial resolution (detection floor ~15-20pp); combined with the byte-identical request #0 wire evidence, the adapted agent is behaviorally the original.

Arm A also surfaced: the official installer refuses headless Node bootstrap ("No terminal detected") — the manifest's own Node provisioning is required for sandbox use, documented in the README.

Unpaired (B-side infra, not agent): fix-build-agentops, fix-build-google-auto, jax-computing-basics, quantum-numerical-simulation, xlsx-recover-data. Harness issues found while running this (filed separately): a Daytona PTY hang that evades both watchdogs, and wall-clock-timeout rollouts inconsistently skipping the verifier (reward=None vs scored).

xdotli added 2 commits August 8, 2026 19:59
prime-agent (and any agent that lists bundled skills in its system prompt)
embeds the agent INSTALL PREFIX in each <location> tag. Standalone installs
live under the host npm prefix; BenchFlow installs under /opt/benchflow —
same skill set, different mount point: the same environment-placement class
as cwd. The rule collapses only the prefix ahead of the dist/skills/ tail
inside a <location> tag, so a different skill NAME or an extra/missing
entry still FAILs. Found running the mock-upstream wire-parity protocol
against prime-agent on Daytona.
…cipe

- single-text-part-vs-string: [{type:text,...}] vs bare string content —
  the same model input; LiteLLM provider transforms flatten the array
  form. Different text or a multi-part array still FAILs.
- blank-reasoning-content: '' vs ' ' replayed reasoning_content (LiteLLM
  pads the empty string). Non-blank reasoning compares verbatim.
- docs/parity.md: the Daytona variant of the mock-upstream recipe
  (in-sandbox mock via setup_commands + verifier exfiltration), including
  the session-exec backgrounding landmine, and why wire claims need a
  capture at the mock rather than the gateway trace log.

With these, the full protocol run against prime-agent on Daytona PASSES:
multi-turn byte-identical under the sanctioned allowlist, with thinking +
reasoning_effort verified ARRIVING at the upstream (after the benchflow
gateway fixes in benchflow-ai/benchflow#949).
@xdotli

xdotli commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Protocol-exact wire parity: PASS. Ran the adaptation-parity skill's mock-upstream check end-to-end on Daytona (in-sandbox mock; recipe now in docs/parity.md): the full multi-turn request sequence is byte-identical native-vs-benchflow under the sanctioned NEUTRAL_DIFFS, with thinking + reasoning_effort verified arriving at the upstream.

The protocol run earned its keep twice: (1) it caught benchflow's gateway silently dropping agent-sent thinking/reasoning_effort on openai/ passthrough routes — invisible to the gateway's own trace log, which records the incoming request (fixed in benchflow-ai/benchflow#949, re-verified through the same protocol); (2) it motivated three new allowlist rules (skill-location install prefix, single-text-part-vs-string, blank-reasoning-content), each with fail-preserving tests.

Caveat for the record: the earlier 25-task outcome A/B predates the gateway fix, so its benchflow arm ran with DeepSeek's default thinking config rather than the agent's explicit one — arms still scored equal means, and the wire is now verified identical going forward.

@xdotli
xdotli merged commit 87990a8 into main Aug 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant