feat(realism): LLM enrichment for user-class file bodies
Stage 6 of the realism migration. User-class file bodies (note, todo, draft, script) optionally get LLM-authored content; system classes (cron / daemon logs, /tmp caches) stay template-only because formulaic *is* the right look for them. New surface: - realism.llm.circuit.LLMCircuitBreaker — process-local sliding-window breaker. 3 consecutive failures trip open; 60s cooldown to half-open; half-open success closes, failure re-opens. Protects the orchestrator tick from sustained Ollama wedges (per-call timeout already covers one-shot hangs). - realism.prompts._style — em-dash suppression lifted from the email prompt. Persona.uses_llms_heavily opts out per the feedback_em_dash_llm_tell.md memory. Includes strip_em_dashes belt-and-braces sub for output that slipped past the prompt rule. - realism.prompts.filebody — class-conditioned prompts (note / todo / draft / script) with persona context, language pinning, output shape rule. - realism.bodies.make_body_with_llm — async wrapper around make_body that calls the LLM when one is provided AND the breaker allows. Falls back to template on timeout / error / empty / system-class. Wiring: - scheduler.pick_file accepts optional llm + llm_breaker + llm_timeout. When the planner picks a create action and the content_class is a user-class, the body_hint is replaced with the LLM-authored body (or falls back to the deterministic body_hint). - orchestrator.worker constructs get_llm() at startup gated by DECNET_REALISM_LLM env var (any non-empty value enables; empty / "off" / "none" / "0" disables). Passes llm + breaker through every tick. - decnet orchestrate gains --llm/--no-llm flag overriding the env var.
This commit is contained in:
@@ -121,6 +121,9 @@ async def pick_file(
|
||||
*,
|
||||
now: Optional[datetime] = None,
|
||||
rand: Optional[secrets.SystemRandom] = None,
|
||||
llm: Any = None,
|
||||
llm_breaker: Any = None,
|
||||
llm_timeout: float = 60.0,
|
||||
) -> Optional[Action]:
|
||||
"""Realism-driven file action — create or edit.
|
||||
|
||||
@@ -179,17 +182,46 @@ async def pick_file(
|
||||
synthetic_file_uuid=(edit_candidate or {}).get("uuid", ""),
|
||||
mtime=plan.mtime,
|
||||
)
|
||||
|
||||
# Create branch. If LLM is wired, optionally swap body_hint for
|
||||
# an LLM-authored body. Always keep the deterministic body_hint
|
||||
# as the fallback the function call returns when LLM
|
||||
# times out / errors / breaker-trips.
|
||||
body = plan.body_hint or ""
|
||||
if llm is not None and plan.content_class.is_user_class():
|
||||
persona_obj = _persona_by_name(enriched, plan.persona)
|
||||
if persona_obj is not None:
|
||||
from decnet.realism.bodies import make_body_with_llm
|
||||
body = await make_body_with_llm(
|
||||
plan.content_class,
|
||||
persona_obj,
|
||||
llm=llm,
|
||||
breaker=llm_breaker,
|
||||
timeout=llm_timeout,
|
||||
rand=rng,
|
||||
)
|
||||
return FileAction(
|
||||
dst_uuid=plan.decky_uuid,
|
||||
dst_name=plan.decky_name,
|
||||
path=plan.target_path,
|
||||
content=plan.body_hint or "",
|
||||
content=body,
|
||||
persona=plan.persona,
|
||||
content_class=plan.content_class.value,
|
||||
mtime=plan.mtime,
|
||||
)
|
||||
|
||||
|
||||
def _persona_by_name(
|
||||
enriched: list[dict[str, Any]], name: str,
|
||||
) -> Optional[EmailPersona]:
|
||||
"""Find the persona instance the planner used; ``None`` if missing."""
|
||||
for decky in enriched:
|
||||
for persona in decky.get("_realism_personas") or []:
|
||||
if persona.name == name:
|
||||
return persona
|
||||
return None
|
||||
|
||||
|
||||
async def _resolve_personas(
|
||||
deckies: Sequence[dict[str, Any]],
|
||||
repo: Any,
|
||||
|
||||
Reference in New Issue
Block a user