Skip to content

cli: fail fast when explicit model provider is not configured#987

Closed
caozuoba wants to merge 1 commit intoHKUDS:mainfrom
caozuoba:pr/provider-precheck
Closed

cli: fail fast when explicit model provider is not configured#987
caozuoba wants to merge 1 commit intoHKUDS:mainfrom
caozuoba:pr/provider-precheck

Conversation

@caozuoba
Copy link
Copy Markdown

Summary

This PR adds a fail-fast precheck in CLI startup to catch explicit model/provider mismatches early.

Before this change, configs like model=anthropic/... with only providers.zhipu.apiKey set could fail later at runtime with a less actionable provider error.
Now the CLI exits early with a clear configuration message.

What changed

  • Added _ensure_explicit_model_provider_configured(config, model) in nanobot/cli/commands.py.
  • Wired the precheck into _make_provider(...) before provider construction.
  • Added tests in tests/test_commands.py for:
    • explicit provider mismatch -> exits early
    • explicit provider match -> passes
    • model without explicit provider prefix -> no strict block
    • _make_provider fail-fast behavior

Why this approach

  • Keeps behavior unchanged for normal fallback flows.
  • Adds guardrails only when users explicitly select a provider-prefixed model.
  • Improves startup error clarity and reduces support/debug time.

Validation

Automated tests

python -m pytest -q tests/test_commands.py
python -m pytest -q

A/B manual verification

Use your local launcher (nanobot, nb, or a full executable path).
Below, <nanobot_cmd> means whichever command works in your environment.

Scenario A (guard case): explicit provider mismatch should fail fast

Config setup:

  • agents.defaults.model = anthropic/claude-opus-4-5
  • only providers.zhipu.apiKey is set

Command:

<nanobot_cmd> agent -m "hi"

Expected:

  • immediate config error:
    • Model 'anthropic/...' requires provider 'anthropic'
    • prompt to set providers.anthropic.apiKey or switch model
image

Scenario B (happy path): matched provider should proceed normally

Config setup:

  • agents.defaults.model = glm-4.7-flash
  • providers.zhipu.apiKey is set

Command:

<nanobot_cmd> agent -m "Please reply with exactly: startup test passed" --logs

Expected:

  • normal response from model (for example: startup test passed)
image

Notes

  • No API/schema changes.
  • No behavior change for users who do not use explicit provider-prefixed models.

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