Files
AI-VideoAssistant/engine/docs/backend_integration.md
Xin Wang 7e0b777923 Refactor project structure and enhance backend integration
- Expanded package inclusion in `pyproject.toml` to support new modules.
- Introduced new `adapters` and `protocol` packages for better organization.
- Added backend adapter implementations for control plane integration.
- Updated main application imports to reflect new package structure.
- Removed deprecated core components and adjusted documentation accordingly.
- Enhanced architecture documentation to clarify the new runtime and integration layers.
2026-03-06 09:51:56 +08:00

1.7 KiB

Backend Integration and History Bridge

This engine uses adapter-based backend integration so core runtime logic can run with or without an external backend service.

Runtime Modes

Configure with environment variables:

  • BACKEND_MODE=auto|http|disabled
  • BACKEND_URL
  • BACKEND_TIMEOUT_SEC
  • ASSISTANT_LOCAL_CONFIG_DIR (default: engine/config/agents)
  • HISTORY_ENABLED=true|false

Mode behavior:

  • auto: use HTTP backend adapter only when BACKEND_URL is set.
  • http: force HTTP backend adapter (falls back to null adapter when URL is missing).
  • disabled: force null adapter and run engine-only.

Assistant config source behavior:

  • If BACKEND_URL exists and backend mode is enabled, fetch assistant config from backend.
  • If BACKEND_URL is missing (or backend mode is disabled), load assistant config from local YAML.
  • assistant_id query parameter is still required and maps to engine/config/agents/<assistant_id>.yaml when local YAML source is active.

Architecture

  • Ports: runtime/ports/control_plane.py
  • Adapters: adapters/control_plane/backend.py

Session and DuplexPipeline receive backend capabilities via injected adapter methods instead of hard-coding backend client imports.

Async History Writes

Session history persistence is handled by runtime/history/bridge.py.

Design:

  • transcript writes are queued with put_nowait (non-blocking turn path)
  • background worker drains queue
  • failed writes retry with exponential backoff
  • finalize waits briefly for queue drain before sending call finalize
  • finalize is idempotent

Related settings:

  • HISTORY_QUEUE_MAX_SIZE
  • HISTORY_RETRY_MAX_ATTEMPTS
  • HISTORY_RETRY_BACKOFF_SEC
  • HISTORY_FINALIZE_DRAIN_TIMEOUT_SEC