Skip to content

feat(agent-runtime): autonomous OpenMontage agent runtime + LLM prompt director (Gap B)#7

Draft
FluffyAIcode wants to merge 28 commits into
mainfrom
AgentMemory/agent-runtime-mvp-cc88
Draft

feat(agent-runtime): autonomous OpenMontage agent runtime + LLM prompt director (Gap B)#7
FluffyAIcode wants to merge 28 commits into
mainfrom
AgentMemory/agent-runtime-mvp-cc88

Conversation

@FluffyAIcode

@FluffyAIcode FluffyAIcode commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

Autonomous agent runtime for the gateway's mode=agent (ADR 0016): brief → script → scene_plan → prompt-director → per-scene assets → compose, LLM-driven, schema-validated + checkpointed. Plus the distributed render path (ADR 0017) and three production-grade upgrades.

LLM providers (llm.py)

AGENT_LLM = anthropic | openai | kakeya | kakeya_grpc | stub. kakeya_grpc talks directly to the head's Kakeya Gemma 26B gRPC RuntimeService (external dep contract via KAKEYA_REPO). Owner-verified live.

Prompt director + 3 upgrades

  • Prompt director: rewrites each scene into a rich native-T2V prompt using the provider's Layer-3 skill (ADR 0015 cross-attention insight).
  • (1) Render quality passthrough: generate_clip renders via the gateway /v1/videos when AGENT_GATEWAY_URL is set (quality=AGENT_VIDEO_QUALITY; high → Hunyuan native 720p), else video_selector + resolution hint.
  • (2) Cross-scene consistency: plan_style_bible → one fixed subject+style embedded into every directed prompt (assets/style_bible.json; AGENT_CONSISTENCY).
  • (3) Governance reviewer: review_plan LLM pass (consistency/coherence/quality) → optional auto-revise (AGENT_AUTO_REVISE) + human-approval gate (AGENT_REQUIRE_APPROVAL); assets/review.json.

Distributed render farm (ADR 0017)

  • SubprocBackend (--subproc): runs heavy CUDA generation in a spawned child's MAIN thread (fixes the in-gRPC-thread VAE-decode hang).
  • Quality tiers (gateway): draft 384×224 / standard 832×480 (WAN native) / high 1280×720 (Hunyuan native), via orchestrator --prefer-backend. Supervisor manages the Hunyuan worker + tunnel durably.
  • Verified public renders: WAN native h264 1280×720; Hunyuan native h264 1280×720×45.

CLI

  • --check-llm (verify LLM endpoint), --plan-only (planning + bible + director + review, no GPU/gateway/key).

Validation

  • pytest tests/tools/test_agent_runtime.py -q5 passed (E2E, plan-only w/ bible+review, directed-prompt, kakeya_grpc guard, script-sanitizer).
  • Public gateway renders verified end-to-end (ffprobe).

Docs

ADR 0016 (runtime + 3 upgrades), ADR 0017 (Hunyuan); loop log iterations 43–47.

Open in Web Open in Cursor 

cursoragent and others added 5 commits June 23, 2026 04:28
… mode=agent (Gap B Phase 1)

OpenMontage has no Python pipeline runner (host LLM is the orchestrator), so mode=agent needs a new
unattended runtime. Adds services/agent_runtime/:
- llm.py: urllib-only cloud LLM client (anthropic|openai|kakeya|stub, auto-detect from keys).
- run.py: LLM -> brief/script/scene_plan (schema-validated + checkpointed) -> assets via
  video_selector (auto best provider) + tts_selector + music_gen -> edit -> audio_mixer +
  video_compose (ffmpeg) -> final mp4. AGENT_RUNTIME_FAKE_ASSETS=1 for offline CI.
- tests: stub-LLM + ffmpeg end-to-end (valid h264 + checkpoints) + JSON extraction. 23 pass.
ADR 0016 + loop-log iteration 41. Needs a cloud LLM key to run live; quality is provider-bounded.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ave no system ffmpeg)

_prepare_ffmpeg symlinks the bundled imageio-ffmpeg binary as 'ffmpeg' on PATH so video_compose/
audio_mixer subprocesses work without a brew install. Verified end-to-end on the head Mac (stub LLM
+ fake assets -> real mp4). Offline tests still pass.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…y provider option

diffusers HunyuanVideoPipeline / HunyuanVideoImageToVideoPipeline; 13B, native 720p ~5s clips.
--backend hunyuan, ops framework,i2v; HUNYUAN_OFFLOAD (default on) for VRAM. For an A/B vs WAN
to decide whether Hunyuan becomes the default quality layer.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
… as quality layer

Real same-prompt 720p A/B on vast: WAN quality=high = unusable abstract blobs (bad 1.3B seed);
HunyuanVideo = coherent photorealistic cinematic clip. Verdict: Hunyuan = default quality provider.
Caveats: ~8min/2s@720p, VRAM-heavy, prompt-adherence/long-form/license noted.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…kills)

Per ADR 0016, enrich each scene into a rich native-T2V prompt before generation,
using the provider's advertised agent_skills (ai-video-gen/ltx2) as guidance, and
persist directed prompts to assets/director_prompts.json. Extends offline test.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
@cursor cursor Bot changed the title feat(agent-runtime): autonomous OpenMontage agent runtime for gateway mode=agent (Gap B Phase 1) feat(agent-runtime): autonomous OpenMontage agent runtime + LLM prompt director (Gap B) Jun 23, 2026
cursoragent and others added 23 commits June 23, 2026 13:44
One tiny LLM round-trip to verify the reasoner (head Kakeya/Gemma gRPC runtime via
OpenAI HTTP shim) before committing to a full pipeline run. Exit 0/1/2 = ok/error/
no-endpoint. Docs updated with the live mode=agent verification recipe.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…rvice)

Fold the head's working transport into the repo: AGENT_LLM=kakeya_grpc talks token-id
level to the user-run Kakeya engine (Gemma 26B @ :51051) via its gRPC SDK. External
dependency contract (KAKEYA_REPO required; kakeya/transformers imported lazily) so grpc/
transformers never become core deps. Clear RuntimeError when KAKEYA_REPO unset; offline
guard test. Verified live by owner (--check-llm -> OK).

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…/gateway/key)

The public gateway enforces X-API-Key which the owner cannot retrieve, blocking
mode=agent smoke tests. The runtime is a plain module; --plan-only runs LLM planning
+ prompt director, writes director_prompts.json, and exits before any render. Refactor
run() to compute directed prompts up front. Offline plan-only test.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
Gemma's 4-bit script stage emitted enhancement_cues.type='visual' (out of the
script schema enum), failing validation. Tighten plan_script prompt to the exact
enum + minimal sections, and add defensive _sanitize_script() that drops unknown
section keys and out-of-enum/malformed cues before validation. Folds owner's local
plan_script patch into the repo. Offline test reproduces the drift. Live --plan-only
on the head (real Gemma via kakeya_grpc) confirmed exit 0.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
The X-API-Key requirement repeatedly blocked the web UI because the key had to be
re-typed each time. Prefill the key field from localStorage on load and persist it
on submit, so it is entered once per browser.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
Web UI can now trigger the full agent pipeline (mode=agent) and pick quality/length
for direct video, without hand-crafting API calls. Quality/length auto-disable in
agent mode (the LLM plans its own scenes/pacing).

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
First framework/refine RPC was hitting INTERNAL BrokenPipe because the cold ~30s
model download/load happened mid-RPC over the held-SSH pipe. Add --preload (load at
boot; server binds only after, so supervisor keeps it out of the pool until ready)
and HF_HUB_DISABLE_PROGRESS_BARS/TQDM_DISABLE to avoid flooding the SSH stderr pipe.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…unnel)

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…x BrokenPipe)

The worker's stdout/stderr was piped over the held SSH; diffusion progress bars on
stderr both raised BrokenPipeError when the channel hiccuped and the heavy traffic
triggered 'Connection reset by peer' that killed the worker mid-refine. Redirect
worker output to a local file so the held SSH carries ~no data and only keeps the
process alive.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
… -> tmux mode

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ne hang)

The high-quality path upscales the proposer to 1280x720 before refine, so the Wan VAE
must encode+decode a full-frame 720p clip in fp32. Untiled this allocates a huge tensor
and HANGS after the denoise loop (worker stuck in VAE decode, GPU 0%, final message never
sent -> orchestrator wedged at 58%). enable_tiling()+enable_slicing() processes spatial
tiles / temporal slices, keeping memory bounded. Applied to T2V/v2v and I2V pipelines.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…upscale

Full-frame v2v at 1280x720 hangs in the Wan VAE (denoise completes, worker stuck at GPU
0%, never returns -> job wedges at 58%). Refine at a capped longest-side (default 512,
proven stable ~6s) and let the existing post-refine LANCZOS upscale reach the 720p target.
Env REFINE_MAX_DIM tunable; 0 = original full-res behavior.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…rker thread)

The distributed v2v refine op wedges in the worker's gRPC thread after denoise (VAE
decode never returns; confirmed framework/native-T2V @720p completes in-thread and the
1MB result traverses the tunnel fine). Repoint 'high' to native 1280x720 generation on
the strongest worker (Blackwell CUDA), no refine -- reliable + aligns with ADR 0015's
'native T2V beats low-res seed + refine'. Verified end-to-end: public download = h264
1280x720. (Also keeps REFINE_MAX_DIM cap as defense for any single-refine use.)

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
… worker thread)

All three tiers now use the reliable direct native-T2V path (draft 384x224 / standard
832x480 / high 1280x720), differing by resolution+frames. The v2v refine op (single AND
tiled) wedges in the worker's gRPC thread, so it's removed from the default tiers.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ad hang; tiers -> native T2V direct

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ium layer)

Add orchestrator --prefer-backend (pin the generator to a backend substring, e.g. hunyuan;
falls back to fastest). Gateway: prefer_backend param + high preset prefer_backend=hunyuan,
native 1280x720 DIRECT, 30 steps / 45 frames. draft/standard stay on fast WAN; high routes
to the Hunyuan worker when present.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ecode hang)

Hunyuan native 720p produces断崖式 better quality standalone, but its heavy VAE decode
HANGS when run inside the worker's gRPC daemon thread (identical post-denoise GPU-0%
stall as WAN v2v; both work standalone). Needs the worker to run the heavy op off the
daemon thread (main thread/subprocess). Until then high stays on reliable WAN native;
--prefer-backend=hunyuan routing is wired and ready to flip on once that's fixed.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…thread VAE-decode hang

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
Fixes the in-worker-thread VAE-decode hang (Hunyuan, WAN v2v): the gRPC servicer thread
deadlocks on heavy CUDA decode, but the same op runs fine in a standalone process's main
thread. SubprocBackend spawns a persistent child (spawn ctx) that loads the model and runs
ops in its MAIN thread, streaming per-step progress back over a Queue and handing frames via
a temp .npy; the gRPC side does only IPC + a file read (no CUDA on the gRPC threads). Gated
by --subproc for cuda/hunyuan.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…durably

SubprocBackend fixed the in-worker decode hang, so flip 'high' to prefer_backend=hunyuan
(native 1280x720, 30 steps/45 frames; falls back to WAN native if no hunyuan worker).
Supervisor now (VAST_HUNYUAN=1) launches the hunyuan --subproc worker in tmux, maintains
its tunnel (VAST_HUNYUAN_LOCAL->REMOTE), and appends it to the worker list. Verified public
render: h264 1280x720x45.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…720p live as high tier

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ance reviewer

(1) generate_clip renders via the gateway /v1/videos when AGENT_GATEWAY_URL is set
    (quality=AGENT_VIDEO_QUALITY; high -> Hunyuan native 720p), else video_selector with a
    resolution hint. Director/editor (runtime) + render farm (gateway) split.
(2) plan_style_bible: one fixed subject+style 'continuity bible' embedded into every directed
    prompt for cross-scene consistency (assets/style_bible.json; AGENT_CONSISTENCY).
(3) review_plan: LLM reviewer over brief+prompts (consistency/coherence/quality) with optional
    auto-revise (AGENT_AUTO_REVISE) and human-approval gate (AGENT_REQUIRE_APPROVAL);
    assets/review.json. All shown under --plan-only. Tests updated (5 passed).

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
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.

2 participants