OUTPUT #896 | 4260 karakter | 85 satır
========== YENİ KOMUT | 21.09.2026 16:24:02 ==========


### REVIEW AUX ROUTE

========== YENİ KOMUT | 21.09.2026 16:24:02 ==========


### REVIEW AUX ROUTE
    lines += [
        "",
        "Your review is delivered back into that conversation, addressed to "
        "the primary agent and its user. Be direct and specific; do not "
        "soften findings.",
    ]
    return goal, "\n".join(lines)


def _load_review_credentials_cfg() -> Optional[Dict[str, Any]]:
    """``auxiliary.review`` as a delegation-credentials dict, or None when unconfigured (provider auto/empty
    and no model/base_url) so the reviewer inherits the parent's credentials."""
    try:
        from hermes_cli.config import load_config_readonly
        review = (load_config_readonly().get("auxiliary") or {}).get("review") or {}
    except Exception:
        return None
    if not isinstance(review, dict):
        return None

    cfg = {k: str(review.get(k) or "").strip() for k in ("provider", "model", "base_url", "api_key", "api_mode")}
    if cfg["provider"].lower() == "auto":
        cfg["provider"] = ""
    if not (cfg["provider"] or cfg["model"] or cfg["base_url"]):
        return None
    return cfg


def start_review(parent_agent, messages: List[Dict[str, Any]], user_prompt: str = "") -> Dict[str, Any]:
    """Dispatch the reviewer subagent; returns the parsed ``delegate_task`` dict (``status: "dispatched"`` +
    ``delegation_id``, or the synchronous result on channels without async completions). Raises ValueError
    when there is nothing to review or the dispatch is rejected/errored."""
    if parent_agent is None:
        raise ValueError("No active agent — send a message first.")
    snapshot = snapshot_recent_messages(messages)
    if not snapshot:
        raise ValueError("Nothing to review yet — the conversation is empty.")
    goal, context = build_review_task(snapshot, user_prompt, collect_parent_loaded_skills(parent_agent, messages))
    credentials_cfg = _load_review_credentials_cfg()

    from tools.delegate_tool import delegate_task
    raw = delegate_task(goal=goal, context=context, background=True, parent_agent=parent_agent, credentials_cfg=credentials_cfg)
    try:
        result = json.loads(raw)
    except Exception:
        result = None
    if isinstance(result, dict) and result.get("error"):
        raise ValueError(str(result["error"]))
    if not isinstance(result, dict):
        raise ValueError(f"Review dispatch failed: {raw!r}")
    result.setdefault("review_model", (credentials_cfg or {}).get("model") or "")

### CREDENTIAL RESOLUTION
355-        f"Install it or choose a different delegation provider.",
356-    )
357-    return _credential_bundle(
358-        v["model"] or runtime.get("model") or None,
359-        configured_provider if runtime.get("provider") == _RUNTIME_PROVIDER_CUSTOM else runtime.get("provider"),
360-        runtime.get("base_url"), api_key, runtime.get("api_mode"),
361-        _merge_request_overrides(runtime.get("request_overrides"), explicit_request_overrides) or {},
362-        command=pinned_command, args=list(runtime.get("args") or []),
363-    )
364-
365:def _resolve_delegation_credentials(cfg: dict, parent_agent) -> dict:
366-    """Child credential bundle from the ``delegation`` config section. Three branches: ``base_url`` set → direct
367-    endpoint (``api_key`` None means inherit the parent's key, so providers keyed outside OPENAI_API_KEY work);
368-    ``provider`` set → full bundle via the runtime provider system (same path as CLI/gateway startup); neither →
369-    None values, child inherits everything. ``request_overrides`` is honored on every branch. Raises ValueError
370-    with a user-facing message."""
371-    values = {k: str(cfg.get(k) or "").strip() or None for k in ("model", "provider", "base_url", "api_key")}
372-    values["api_mode"] = str(cfg.get("api_mode") or "").strip().lower() or None
373-    explicit_request_overrides = cfg.get("request_overrides") if isinstance(cfg.get("request_overrides"), dict) else None
374-    is_native_sdk_provider = (values["provider"] or "").strip().lower() in _NATIVE_SDK_PROVIDERS
375-
root@213-238-170-219:~#