external_backends provides adapter contracts and registration helpers for knowledge-search and code-parse backends while keeping callers backend-agnostic.
- Lifecycle registry lives in
teaagent/backend_registry.py(BackendRegistry,get_default_backend_registry). teaagent/external_backends.pydefines protocols, adapters, validator/factory helpers, and wrapper registration/getters.- Default registrations are installed at import time (
localknowledge backend andcx_clicode-parse backend).
- Registration requires non-empty names; blank names raise
ValueError. - Lookup is strict; unknown backend names raise
ValueError. - Health checks are best-effort: prefer
check_health(), elsehealth(root=...), else report nohealthcheckavailable. - Lifecycle operations are non-fatal across registry entries: one backend failure is logged and does not stop iteration.
FallbackKnowledgeBackendcalls primary first; on failure it calls fallback and annotates result withfallback_usedandprimary_error.- Validation-enabled registry variants enforce protocol method presence before accepting registration.
- Registry state is keyed by backend name and returns the latest binding.
is_initialized()reflects lifecycle transition points (initialize()true,shutdown()false).- Wrapper APIs (
register_*,get_*) dispatch through a singleton default registry. - Backend integration failures are surfaced as explicit exceptions or structured unhealthy states, never silently ignored.