How zhan-zip/model-switch-optimize works
Model Switch is a standalone model-failover and self-repair manager. A host submits a task through the Python API or CLI; the pipeline uses model-based decisions and a toolbox to choose and call a provider, then records failures, switches models, and tries configuration-ordered mechanical fallback when needed. Separate capabilities cover provider diagnosis and gated repair, onboarding, recovery probes, MCP/tool integration, and run history/statistics. Edges reflect the excerpts, SOURCE INDEX references, and README; several subsystem internals were not sampled, so uncertain wiring is omitted.
Main entry points: pipeline.py Run pipeline · tools.py Toolbox · switcher.py Python API · manager.py Decision manager
Components 24
Entry and integration
- CLI
model_switch/cli.py - Python API
model_switch/switcher.py - MCP adapter
model_switch/mcp.py
Task runtime
- Run pipeline
model_switch/pipeline.py - Decision manager
model_switch/manager.py - Toolbox
model_switch/tools.py - Model client
model_switch/client.py - Model registry
model_switch/model.py
Recovery and setup
- Provider diagnosis
model_switch/diagnose.py - Gated repair
model_switch/fix.py - Model onboarding
model_switch/onboarding.py - Recovery probes
model_switch/probe.py - Web search
model_switch/websearch.py
State and observability
- Probe queue
model_switch/probe.py - Model preferences
model_switch/prefs.py - Run statistics
model_switch/stats.py - Fault history
model_switch/history.py - Event stream
model_switch/events.py
Configuration and safeguards
- Model configuration
model_switch/config.py - Secret redaction
model_switch/safety.py
Other components
- Host / user
- Model provider
- Provider console
- MCP host
Connections 42
- Host / user → CLI: runs command
README.md - Host / user → Python API: submits task
model_switch/switcher.py - Host / user → MCP host: uses tools
README.md - CLI → Run pipeline: runs task
model_switch/cli.py - Python API → Run pipeline: runs task
model_switch/switcher.py - Python API → Toolbox: exposes dispatch
model_switch/switcher.py - MCP host → MCP adapter: requests tools
README.md - MCP adapter → Python API: uses runtime
model_switch/mcp.py - Run pipeline → Decision manager: requests decisions
model_switch/pipeline.py - Run pipeline → Toolbox: calls models
model_switch/pipeline.py - Run pipeline → Fault history: records faults
model_switch/pipeline.py - Run pipeline → Probe queue: queues failures
README.md - Run pipeline → Model preferences: uses switch preferences
model_switch/pipeline.py - Run pipeline → Run statistics: records runs
model_switch/pipeline.py - Run pipeline → Event stream: emits events
model_switch/pipeline.py - Decision manager → Toolbox: queries models
model_switch/manager.py - Decision manager → Model preferences: uses preferences
model_switch/manager.py - Decision manager → Run statistics: uses experience scores
model_switch/manager.py - Decision manager → Event stream: emits decisions
model_switch/manager.py - Toolbox → Model registry: reads model status
model_switch/tools.py - Toolbox → Model client: calls provider
model_switch/tools.py - Model client → Model provider: sends model request
model_switch/client.py - Toolbox → Event stream: emits call results
model_switch/tools.py - Model registry → Model configuration: builds model states
model_switch/model.py - CLI → Model configuration: loads and validates
model_switch/cli.py - Python API → Model configuration: loads configuration
model_switch/switcher.py - Recovery probes → Toolbox: tests connectivity
model_switch/probe.py - Recovery probes → Probe queue: reads and updates
model_switch/probe.py - CLI → Recovery probes: runs probes
model_switch/cli.py - Python API → Recovery probes: exposes probing
model_switch/switcher.py - Model onboarding → Toolbox: checks connectivity
model_switch/onboarding.py - Model onboarding → Model preferences: saves model labels
model_switch/onboarding.py - CLI → Model onboarding: runs onboarding
model_switch/cli.py - Python API → Provider diagnosis: exposes diagnosis
model_switch/switcher.py - Provider diagnosis → Decision manager: requests conclusion
model_switch/diagnose.py - Provider diagnosis → Provider console: checks provider
model_switch/diagnose.py - Gated repair → Provider console: applies approved fix
model_switch/fix.py - Gated repair → Event stream: records repair
model_switch/fix.py - Toolbox → Fault history: serves fault history
model_switch/tools.py - Web search → Model provider: searches web
- Event stream → Secret redaction: redacts event data
model_switch/events.py - Model client → Secret redaction: redacts errors
model_switch/client.py