MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / decide_advisor_mode

Function decide_advisor_mode

src/utils/advisor.py:339–411  ·  view source on GitHub ↗

Pick activation mode for the upcoming turn. Returns one of: * ``ADVISOR_MODE_INACTIVE`` — no advisor on this request. * ``ADVISOR_MODE_SERVER_SIDE`` — Anthropic 1P beta path. * ``ADVISOR_MODE_CLIENT_SIDE`` — separate provider call from the tool dispatcher. Decision tree:

(
    provider: "BaseProvider | None",
    main_loop_model: str | None,
    advisor_model: str | None,
    *,
    force_client_mode: bool = False,
    advisor_provider: str | None = None,
    advisor_enabled: bool = True,
)

Source from the content-addressed store, hash-verified

337
338
339def decide_advisor_mode(
340 provider: "BaseProvider | None",
341 main_loop_model: str | None,
342 advisor_model: str | None,
343 *,
344 force_client_mode: bool = False,
345 advisor_provider: str | None = None,
346 advisor_enabled: bool = True,
347) -> str:
348 """Pick activation mode for the upcoming turn.
349
350 Returns one of:
351 * ``ADVISOR_MODE_INACTIVE`` — no advisor on this request.
352 * ``ADVISOR_MODE_SERVER_SIDE`` — Anthropic 1P beta path.
353 * ``ADVISOR_MODE_CLIENT_SIDE`` — separate provider call from the
354 tool dispatcher.
355
356 Decision tree:
357
358 1. ``advisor_model`` empty / env-disabled → INACTIVE.
359 2. ``advisor_provider`` empty → INACTIVE (the multi-provider
360 rewrite requires explicit provider; name-based inference was
361 removed because the same model name can sit behind multiple
362 providers).
363 3. ``force_client_mode`` set → CLIENT_SIDE iff the advisor
364 provider is a configured key; else INACTIVE.
365 4. 1P + main_loop_model supports server advisor + advisor_model is
366 a valid server target + advisor_provider == "anthropic"
367 SERVER_SIDE (the optimized path; one roundtrip, prompt-cache
368 friendly). Server-side only makes sense when the advisor call
369 lands on the same Anthropic API as the main loop.
370 5. Otherwise, if the advisor provider is configured → CLIENT_SIDE.
371 6. Else INACTIVE — the configured advisor can't be reached.
372
373 ``advisor_enabled`` is the master switch (settings ``advisor_enabled``,
374 default False in production): when False the advisor is INACTIVE regardless
375 of model/provider. The parameter defaults True so direct callers (the
376 activation truth-table tests) keep their behavior; production call sites pass
377 ``get_settings().advisor_enabled``.
378 """
379 if not advisor_enabled:
380 return ADVISOR_MODE_INACTIVE
381 if _env_truthy(_DISABLE_ENV):
382 return ADVISOR_MODE_INACTIVE
383 if not advisor_model:
384 return ADVISOR_MODE_INACTIVE
385 if not advisor_provider:
386 return ADVISOR_MODE_INACTIVE
387
388 # Provider must be configured in ~/.clawcodex/config.json. Use the
389 # provider class registry as the lightweight check (a key with no
390 # class registered can't be instantiated anyway).
391 advisor_routes = False
392 try:
393 from src.providers import get_provider_class
394 get_provider_class(advisor_provider)
395 advisor_routes = True
396 except Exception:

Calls 5

get_provider_classFunction · 0.90
is_advisor_enabledFunction · 0.85
model_supports_advisorFunction · 0.85
is_valid_advisor_modelFunction · 0.85
_env_truthyFunction · 0.70