reflection-agent 2.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reflection_agent-2.0.2/.env.example +52 -0
- reflection_agent-2.0.2/.github/workflows/ci.yml +84 -0
- reflection_agent-2.0.2/.gitignore +18 -0
- reflection_agent-2.0.2/AUDIT.md +291 -0
- reflection_agent-2.0.2/CHANGELOG.md +445 -0
- reflection_agent-2.0.2/CHANGELOG_v2.2.0.md +40 -0
- reflection_agent-2.0.2/CHANGELOG_v2.3.0.md +40 -0
- reflection_agent-2.0.2/CHANGELOG_v2.3.1.md +26 -0
- reflection_agent-2.0.2/CHANGELOG_v2.4.0.md +70 -0
- reflection_agent-2.0.2/CHANGELOG_v2.4.1.md +82 -0
- reflection_agent-2.0.2/CHANGELOG_v2.5.0.md +89 -0
- reflection_agent-2.0.2/CHANGELOG_v2.5.1.md +57 -0
- reflection_agent-2.0.2/CHANGELOG_v2.5.2.md +84 -0
- reflection_agent-2.0.2/CLAUDE.md +69 -0
- reflection_agent-2.0.2/Dockerfile +71 -0
- reflection_agent-2.0.2/LICENSE +23 -0
- reflection_agent-2.0.2/PKG-INFO +319 -0
- reflection_agent-2.0.2/README.md +250 -0
- reflection_agent-2.0.2/VERSION +1 -0
- reflection_agent-2.0.2/alembic/__init__.py +0 -0
- reflection_agent-2.0.2/alembic/env.py +123 -0
- reflection_agent-2.0.2/alembic/script.py.mako +26 -0
- reflection_agent-2.0.2/alembic/versions/20260202_000000_001_initial_schema.py +258 -0
- reflection_agent-2.0.2/alembic/versions/20260202_000001_002_memories_table.py +110 -0
- reflection_agent-2.0.2/alembic/versions/20260202_000002_003_session_history.py +95 -0
- reflection_agent-2.0.2/alembic/versions/20260203_000000_004_api_key_composite_index.py +45 -0
- reflection_agent-2.0.2/alembic/versions/__init__.py +0 -0
- reflection_agent-2.0.2/alembic.ini +76 -0
- reflection_agent-2.0.2/docker-compose.yml +118 -0
- reflection_agent-2.0.2/examples/hybrid_routing_example.py +137 -0
- reflection_agent-2.0.2/examples/quickstart.py +220 -0
- reflection_agent-2.0.2/install.sh +228 -0
- reflection_agent-2.0.2/installer/README.txt +76 -0
- reflection_agent-2.0.2/installer/build_installer.py +125 -0
- reflection_agent-2.0.2/installer/cli_installer.py +515 -0
- reflection_agent-2.0.2/installer/installer.spec +78 -0
- reflection_agent-2.0.2/installer/setup_wizard.py +717 -0
- reflection_agent-2.0.2/papers/reflection_security_paper.md +749 -0
- reflection_agent-2.0.2/pyproject.toml +143 -0
- reflection_agent-2.0.2/reflection/__init__.py +195 -0
- reflection_agent-2.0.2/reflection/__main__.py +10 -0
- reflection_agent-2.0.2/reflection/_familiar_setup.py +38 -0
- reflection_agent-2.0.2/reflection/auth/__init__.py +45 -0
- reflection_agent-2.0.2/reflection/auth/sso.py +894 -0
- reflection_agent-2.0.2/reflection/cli.py +498 -0
- reflection_agent-2.0.2/reflection/core/__init__.py +230 -0
- reflection_agent-2.0.2/reflection/core/agent.py +549 -0
- reflection_agent-2.0.2/reflection/core/async_base.py +384 -0
- reflection_agent-2.0.2/reflection/core/async_orchestrator.py +966 -0
- reflection_agent-2.0.2/reflection/core/circuit_breaker.py +512 -0
- reflection_agent-2.0.2/reflection/core/enterprise_tools.py +595 -0
- reflection_agent-2.0.2/reflection/core/executor.py +580 -0
- reflection_agent-2.0.2/reflection/core/extended_tools.py +860 -0
- reflection_agent-2.0.2/reflection/core/memory.py +614 -0
- reflection_agent-2.0.2/reflection/core/orchestrator.py +748 -0
- reflection_agent-2.0.2/reflection/core/providers.py +753 -0
- reflection_agent-2.0.2/reflection/core/providers_async.py +1078 -0
- reflection_agent-2.0.2/reflection/core/regions.py +518 -0
- reflection_agent-2.0.2/reflection/core/settings.py +287 -0
- reflection_agent-2.0.2/reflection/core/tokens.py +630 -0
- reflection_agent-2.0.2/reflection/core/tools.py +630 -0
- reflection_agent-2.0.2/reflection/core/usage_alerts.py +664 -0
- reflection_agent-2.0.2/reflection/core/usage_calculator.py +491 -0
- reflection_agent-2.0.2/reflection/data/__init__.py +68 -0
- reflection_agent-2.0.2/reflection/data/migrations/.gitkeep +0 -0
- reflection_agent-2.0.2/reflection/data/models.py +291 -0
- reflection_agent-2.0.2/reflection/data/postgres.py +142 -0
- reflection_agent-2.0.2/reflection/data/redis.py +144 -0
- reflection_agent-2.0.2/reflection/data/repositories.py +714 -0
- reflection_agent-2.0.2/reflection/gateway/__init__.py +68 -0
- reflection_agent-2.0.2/reflection/gateway/app.py +406 -0
- reflection_agent-2.0.2/reflection/gateway/auth.py +797 -0
- reflection_agent-2.0.2/reflection/gateway/auth_routes.py +970 -0
- reflection_agent-2.0.2/reflection/gateway/chat_routes.py +569 -0
- reflection_agent-2.0.2/reflection/gateway/chat_routes_v2.py +364 -0
- reflection_agent-2.0.2/reflection/gateway/health.py +524 -0
- reflection_agent-2.0.2/reflection/gateway/job_routes.py +378 -0
- reflection_agent-2.0.2/reflection/gateway/lifecycle_routes.py +383 -0
- reflection_agent-2.0.2/reflection/gateway/quota_middleware.py +316 -0
- reflection_agent-2.0.2/reflection/gateway/quota_routes.py +466 -0
- reflection_agent-2.0.2/reflection/gateway/rate_limit.py +425 -0
- reflection_agent-2.0.2/reflection/gateway/request_context.py +413 -0
- reflection_agent-2.0.2/reflection/gateway/routes.py +760 -0
- reflection_agent-2.0.2/reflection/gateway/sso_routes.py +563 -0
- reflection_agent-2.0.2/reflection/gateway/token_store.py +622 -0
- reflection_agent-2.0.2/reflection/gateway/versioning.py +481 -0
- reflection_agent-2.0.2/reflection/jobs/__init__.py +728 -0
- reflection_agent-2.0.2/reflection/jobs/export_handlers.py +542 -0
- reflection_agent-2.0.2/reflection/observability/__init__.py +148 -0
- reflection_agent-2.0.2/reflection/observability/logging.py +607 -0
- reflection_agent-2.0.2/reflection/observability/metrics.py +701 -0
- reflection_agent-2.0.2/reflection/observability/middleware.py +250 -0
- reflection_agent-2.0.2/reflection/observability/tracing.py +486 -0
- reflection_agent-2.0.2/reflection/routing/__init__.py +24 -0
- reflection_agent-2.0.2/reflection/routing/phi_detector.py +165 -0
- reflection_agent-2.0.2/reflection/routing/smart_router.py +313 -0
- reflection_agent-2.0.2/reflection/services/__init__.py +31 -0
- reflection_agent-2.0.2/reflection/services/orchestrator.py +468 -0
- reflection_agent-2.0.2/reflection/tenant_wrappers/__init__.py +81 -0
- reflection_agent-2.0.2/reflection/tenant_wrappers/agent.py +626 -0
- reflection_agent-2.0.2/reflection/tenant_wrappers/channels.py +311 -0
- reflection_agent-2.0.2/reflection/tenant_wrappers/memory.py +597 -0
- reflection_agent-2.0.2/reflection/tenant_wrappers/tools.py +176 -0
- reflection_agent-2.0.2/reflection/tenants/__init__.py +68 -0
- reflection_agent-2.0.2/reflection/tenants/context.py +438 -0
- reflection_agent-2.0.2/reflection/tenants/lifecycle.py +552 -0
- reflection_agent-2.0.2/reflection/tenants/models.py +617 -0
- reflection_agent-2.0.2/reflection/tenants/quota_service.py +602 -0
- reflection_agent-2.0.2/reflection/tenants/quotas.py +681 -0
- reflection_agent-2.0.2/reflection_core/__init__.py +112 -0
- reflection_agent-2.0.2/reflection_core/exceptions/__init__.py +7 -0
- reflection_agent-2.0.2/reflection_core/exceptions/hierarchy.py +380 -0
- reflection_agent-2.0.2/reflection_core/security/__init__.py +9 -0
- reflection_agent-2.0.2/reflection_core/security/encryption.py +276 -0
- reflection_agent-2.0.2/reflection_core/security/sanitization.py +272 -0
- reflection_agent-2.0.2/reflection_core/security/trust.py +131 -0
- reflection_agent-2.0.2/run.sh +192 -0
- reflection_agent-2.0.2/scripts/generate_secrets.py +177 -0
- reflection_agent-2.0.2/scripts/model_setup.sh +363 -0
- reflection_agent-2.0.2/tests/__init__.py +0 -0
- reflection_agent-2.0.2/tests/conftest.py +60 -0
- reflection_agent-2.0.2/tests/test_constitution.py +314 -0
- reflection_agent-2.0.2/tests/test_installation.py +116 -0
- reflection_agent-2.0.2/tests/test_mcp_server.py +285 -0
- reflection_agent-2.0.2/tests/test_memory_agent.py +369 -0
- reflection_agent-2.0.2/tests/test_mesh_delegation.py +486 -0
- reflection_agent-2.0.2/tests/test_mesh_discovery.py +545 -0
- reflection_agent-2.0.2/tests/test_mesh_memory_bridge.py +637 -0
- reflection_agent-2.0.2/tests/test_mesh_trust.py +535 -0
- reflection_agent-2.0.2/tests/test_phi_routing.py +165 -0
- reflection_agent-2.0.2/tests/test_planner.py +273 -0
- reflection_agent-2.0.2/tests/test_reflection_core.py +153 -0
- reflection_agent-2.0.2/tests/test_self_correction.py +251 -0
- reflection_agent-2.0.2/tests/test_semantic_memory.py +303 -0
- reflection_agent-2.0.2/tests/test_skill_handlers.py +214 -0
- reflection_agent-2.0.2/tests/test_skill_loading.py +126 -0
- reflection_agent-2.0.2/tests/test_skill_presets.py +160 -0
- reflection_agent-2.0.2/tests/test_tenant_isolation.py +200 -0
- reflection_agent-2.0.2/tests/test_v2_integration.py +310 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# Reflection - Environment Configuration
|
|
3
|
+
# =============================================================================
|
|
4
|
+
# Copy this file to .env and fill in your values:
|
|
5
|
+
# cp .env.example .env
|
|
6
|
+
#
|
|
7
|
+
# Required settings are marked with [REQUIRED]
|
|
8
|
+
# Everything else has sensible defaults
|
|
9
|
+
# =============================================================================
|
|
10
|
+
|
|
11
|
+
# -- General ------------------------------------------------------------------
|
|
12
|
+
ENVIRONMENT=production # development | staging | production
|
|
13
|
+
DEBUG=false
|
|
14
|
+
|
|
15
|
+
# -- Database [REQUIRED for production] ---------------------------------------
|
|
16
|
+
# SQLite is used automatically in development if this is not set
|
|
17
|
+
DATABASE_URL=postgresql+asyncpg://reflection:reflection@localhost:5432/reflection
|
|
18
|
+
|
|
19
|
+
# -- Redis [REQUIRED for production] ------------------------------------------
|
|
20
|
+
# In-memory fallback is used in development if this is not set
|
|
21
|
+
REDIS_URL=redis://localhost:6379/0
|
|
22
|
+
|
|
23
|
+
# -- LLM Providers (at least one required) ------------------------------------
|
|
24
|
+
LLM_DEFAULT_PROVIDER=anthropic # anthropic | openai | ollama
|
|
25
|
+
|
|
26
|
+
# Anthropic (recommended)
|
|
27
|
+
LLM_ANTHROPIC_API_KEY= # sk-ant-...
|
|
28
|
+
|
|
29
|
+
# OpenAI
|
|
30
|
+
LLM_OPENAI_API_KEY= # sk-...
|
|
31
|
+
|
|
32
|
+
# Ollama (self-hosted, free)
|
|
33
|
+
LLM_OLLAMA_URL=http://localhost:11434
|
|
34
|
+
LLM_OLLAMA_MODEL=llama3.2
|
|
35
|
+
|
|
36
|
+
# -- Security [REQUIRED] -----------------------------------------------------
|
|
37
|
+
# Generate with: python3 -c "import secrets; print(secrets.token_urlsafe(64))"
|
|
38
|
+
SECURITY_JWT_SECRET_KEY=DEV-ONLY-b2d6d62536a6da9c2a40874fa86e108adce6d0b3228cd2349e476eeb4ae5f34a
|
|
39
|
+
|
|
40
|
+
# Generate with: python3 -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
|
|
41
|
+
SECURITY_MASTER_ENCRYPTION_KEY=
|
|
42
|
+
|
|
43
|
+
# -- HIPAA Compliance (healthcare only) ---------------------------------------
|
|
44
|
+
# Set to true to enable automatic PHI routing, audit retention, etc.
|
|
45
|
+
# HIPAA_COMPLIANT=false
|
|
46
|
+
# PHI_PROVIDER_NAME=ollama
|
|
47
|
+
# PHI_MODEL=qwen2.5:7b
|
|
48
|
+
|
|
49
|
+
# -- Observability (optional) -------------------------------------------------
|
|
50
|
+
OTEL_ENABLED=false
|
|
51
|
+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
|
|
52
|
+
# OTEL_SERVICE_NAME=reflection
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master, "feat/**"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
lint:
|
|
15
|
+
name: Lint
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
|
|
24
|
+
- name: Install ruff
|
|
25
|
+
run: pip install ruff
|
|
26
|
+
|
|
27
|
+
- name: Ruff check
|
|
28
|
+
run: ruff check reflection/ reflection_core/
|
|
29
|
+
|
|
30
|
+
- name: Ruff format check
|
|
31
|
+
run: ruff format --check reflection/ reflection_core/
|
|
32
|
+
|
|
33
|
+
test:
|
|
34
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
strategy:
|
|
37
|
+
matrix:
|
|
38
|
+
python-version: ["3.11", "3.12"]
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
|
|
42
|
+
- uses: actions/setup-python@v5
|
|
43
|
+
with:
|
|
44
|
+
python-version: ${{ matrix.python-version }}
|
|
45
|
+
|
|
46
|
+
- name: Install dependencies
|
|
47
|
+
run: |
|
|
48
|
+
pip install --upgrade pip
|
|
49
|
+
pip install -e ".[dev]"
|
|
50
|
+
|
|
51
|
+
- name: Run tests
|
|
52
|
+
run: pytest tests/ -q --tb=short
|
|
53
|
+
|
|
54
|
+
verify-imports:
|
|
55
|
+
name: Verify Imports
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
steps:
|
|
58
|
+
- uses: actions/checkout@v4
|
|
59
|
+
|
|
60
|
+
- uses: actions/setup-python@v5
|
|
61
|
+
with:
|
|
62
|
+
python-version: "3.12"
|
|
63
|
+
|
|
64
|
+
- name: Install Reflection
|
|
65
|
+
run: |
|
|
66
|
+
pip install --upgrade pip
|
|
67
|
+
pip install .
|
|
68
|
+
|
|
69
|
+
- name: Verify imports
|
|
70
|
+
run: |
|
|
71
|
+
python -c "import familiar; print(f'familiar {familiar.__version__}')"
|
|
72
|
+
python -c "import reflection; print(f'reflection {reflection.__version__}')"
|
|
73
|
+
|
|
74
|
+
docker:
|
|
75
|
+
name: Docker Build
|
|
76
|
+
runs-on: ubuntu-latest
|
|
77
|
+
steps:
|
|
78
|
+
- uses: actions/checkout@v4
|
|
79
|
+
|
|
80
|
+
- name: Build image
|
|
81
|
+
run: docker build -t reflection:ci --target production .
|
|
82
|
+
|
|
83
|
+
- name: Verify image runs
|
|
84
|
+
run: docker run --rm reflection:ci python -c "import reflection; print(f'v{reflection.__version__}')"
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# Reflection — Living Audit Document
|
|
2
|
+
|
|
3
|
+
**Last updated:** 2026-02-25
|
|
4
|
+
**Current version:** 2.0.0
|
|
5
|
+
**Maintained by:** George Scott Foley
|
|
6
|
+
|
|
7
|
+
This document is the single source of truth for known issues, intentional stubs,
|
|
8
|
+
architectural decisions, and the gap between what exists and what's wired.
|
|
9
|
+
Update it when you add a TODO, complete a stub, or make a decision you'll want
|
|
10
|
+
to remember next session.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## How to Use This Document
|
|
15
|
+
|
|
16
|
+
**Starting a session:** Read this first. It saves reconstructing context from code.
|
|
17
|
+
|
|
18
|
+
**Ending a session:** Add anything that's intentionally incomplete, any architectural
|
|
19
|
+
decision made, any new TODO introduced. If you completed something, mark it ✅ and
|
|
20
|
+
add the version it landed in.
|
|
21
|
+
|
|
22
|
+
**Marker conventions in code:**
|
|
23
|
+
|
|
24
|
+
| Marker | Meaning |
|
|
25
|
+
|--------|---------|
|
|
26
|
+
| `# TODO:` | Planned but not started |
|
|
27
|
+
| `# STUB:` | Structure exists, execution path not yet implemented |
|
|
28
|
+
| `# FIXME:` | Known bug, not yet fixed |
|
|
29
|
+
| `# INTENTIONAL:` | Looks wrong but isn't — explains why |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Version Status
|
|
34
|
+
|
|
35
|
+
### Current: v2.0.0
|
|
36
|
+
Reflection split into its own repo (`omegcrash/reflection`) as a standalone
|
|
37
|
+
multi-tenant platform. Depends on `familiar-agent>=1.4.0` from PyPI.
|
|
38
|
+
|
|
39
|
+
**Packages:** `reflection/` (69 .py files), `reflection_core/` (8 .py files)
|
|
40
|
+
**Entry point:** `reflection` (CLI via typer, 20+ commands)
|
|
41
|
+
**Build:** hatchling | Python >=3.11
|
|
42
|
+
**Tests:** 700 passed, 0 failed, 1 skipped (10.7s)
|
|
43
|
+
**Lint:** ruff check + format clean (77 files)
|
|
44
|
+
|
|
45
|
+
### Familiar Core Dependency
|
|
46
|
+
Familiar v1.6.1 is the latest release of the core library (`omegcrash/familiar`).
|
|
47
|
+
PyPI has `familiar-agent==1.6.1`. Key features available:
|
|
48
|
+
- 50+ skills, all channel integrations (CLI, Telegram, Discord, Matrix, Teams, Signal, iMessage, WhatsApp, SMS)
|
|
49
|
+
- IMAP server, mesh gateway peer auth, Double Ratchet prev_chain_len
|
|
50
|
+
- 785 tests passing
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Test Results (2026-02-25)
|
|
55
|
+
|
|
56
|
+
**700 passed, 0 failed, 1 skipped** across 19 test files in 10.7s.
|
|
57
|
+
Tested against `familiar-agent==1.6.1` from PyPI.
|
|
58
|
+
|
|
59
|
+
### ~~Known Failure: SKILL.md packaging~~ ✅ Fixed (Familiar v1.6.1)
|
|
60
|
+
`test_skill_description_from_md` previously failed because the PyPI wheel did not
|
|
61
|
+
bundle `SKILL.md` files. Fixed in Familiar v1.6.1 by adding `artifacts` config to
|
|
62
|
+
`[tool.hatch.build.targets.wheel]` in `pyproject.toml`. 44 SKILL.md + 27 config.yaml
|
|
63
|
+
files now included in the wheel.
|
|
64
|
+
|
|
65
|
+
### ~~Known Failure: Skill count assertion~~ ✅ Fixed (Reflection 6bb1e2e)
|
|
66
|
+
`test_total_skill_count` hardcoded `== 40` but Familiar v1.6.1 ships 48 skills.
|
|
67
|
+
Changed to `>= 40` so it doesn't break when upstream adds skills.
|
|
68
|
+
|
|
69
|
+
### Known Skip
|
|
70
|
+
Environment-dependent test (likely hardware detection or optional dependency).
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Verified Implemented (Previously Misclassified as Stubs)
|
|
75
|
+
|
|
76
|
+
These files were initially classified as stubs but are **fully implemented and wired**
|
|
77
|
+
in `app.py`. Corrected 2026-02-25 after code review.
|
|
78
|
+
|
|
79
|
+
### ~~Gateway: Request Context Middleware~~ ✅ Implemented
|
|
80
|
+
**File:** `reflection/gateway/request_context.py` (413 lines)
|
|
81
|
+
**Implementation:** Full `RequestContextMiddleware` with ContextVar propagation,
|
|
82
|
+
X-Request-ID generation/forwarding, tenant context injection, structured logging filter.
|
|
83
|
+
**Wired in:** `app.py` — always registered as middleware.
|
|
84
|
+
|
|
85
|
+
### ~~Gateway: Token Store~~ ✅ Implemented
|
|
86
|
+
**File:** `reflection/gateway/token_store.py` (622 lines)
|
|
87
|
+
**Implementation:** Redis-backed `TokenStore` with session management, refresh token
|
|
88
|
+
rotation, `TokenReuseError` detection for replay attacks.
|
|
89
|
+
**Wired in:** `JWTService.decode_token_async()` in `auth.py`.
|
|
90
|
+
|
|
91
|
+
### ~~Gateway: Quota Middleware~~ ✅ Implemented
|
|
92
|
+
**File:** `reflection/gateway/quota_middleware.py` (316 lines)
|
|
93
|
+
**Implementation:** Full `QuotaMiddleware(BaseHTTPMiddleware)` with `QuotaChecker`
|
|
94
|
+
dependency injection, per-request quota enforcement, 429 responses.
|
|
95
|
+
**Wired in:** `app.py` — conditional on `settings.quota_middleware_enabled`.
|
|
96
|
+
|
|
97
|
+
### ~~Gateway: Rate Limiter~~ ✅ Implemented
|
|
98
|
+
**File:** `reflection/gateway/rate_limit.py` (425 lines)
|
|
99
|
+
**Implementation:** Redis-backed `RateLimiter` + `LoginRateLimiter` with sliding window
|
|
100
|
+
algorithm, progressive lockout, configurable thresholds.
|
|
101
|
+
**Wired in:** `auth_routes.py` — login endpoint brute-force protection.
|
|
102
|
+
|
|
103
|
+
### ~~Observability: Middleware~~ ✅ Implemented
|
|
104
|
+
**File:** `reflection/observability/middleware.py` (251 lines)
|
|
105
|
+
**Implementation:** `MetricsMiddleware` (Prometheus request metrics) + `TracingMiddleware`
|
|
106
|
+
(OpenTelemetry span creation), path normalization for cardinality control.
|
|
107
|
+
**Wired in:** `app.py` — `MetricsMiddleware` always registered, `TracingMiddleware`
|
|
108
|
+
production only.
|
|
109
|
+
|
|
110
|
+
### ~~Tenant Wrappers: Memory~~ ✅ Implemented
|
|
111
|
+
**File:** `reflection/tenant_wrappers/memory.py` (598 lines)
|
|
112
|
+
**Implementation:** `TenantMemory(Memory)` — DB-native UPSERT, LRU cache with TTL,
|
|
113
|
+
async+sync methods, SQL tenant isolation (tenant_id in every WHERE clause).
|
|
114
|
+
Also `TenantConversationHistory` for scoped chat history.
|
|
115
|
+
**Wired in:** `TenantAgent.__init__()` — replaces parent Memory when `db_session`
|
|
116
|
+
is provided. `AgentOrchestrator._get_agent()` passes the session automatically.
|
|
117
|
+
Corrected 2026-02-25 after code review.
|
|
118
|
+
|
|
119
|
+
### ~~Tenant Wrappers: Tools~~ ✅ Implemented
|
|
120
|
+
**File:** `reflection/tenant_wrappers/tools.py` (177 lines)
|
|
121
|
+
**Implementation:** `TenantToolRegistry(ToolRegistry)` — per-tenant enable/disable,
|
|
122
|
+
tenant-specific configs, usage tracking callback, sandboxed directories.
|
|
123
|
+
**Wired in:** `TenantAgent.__init__()` — creates `_tenant_tools` via
|
|
124
|
+
`get_tenant_tool_registry()`, applies skill preset filtering from `_allowed_skills`.
|
|
125
|
+
Corrected 2026-02-25 after code review.
|
|
126
|
+
|
|
127
|
+
### ~~Tenant Wrappers: Channels~~ ✅ Implemented
|
|
128
|
+
**File:** `reflection/tenant_wrappers/channels.py` (312 lines)
|
|
129
|
+
**Implementation:** `TenantChannelManager` (lifecycle management, health monitoring) +
|
|
130
|
+
`TenantChannelRouter` (server/chat-to-tenant routing for shared bots). Conditional
|
|
131
|
+
channel classes for Discord, Telegram, Teams.
|
|
132
|
+
**Wired in:** `app.py` — startup/shutdown lifecycle hooks initialize the singleton
|
|
133
|
+
and gracefully stop all running channels. Corrected 2026-02-25 after code review.
|
|
134
|
+
|
|
135
|
+
### ~~Gateway: Chat Routes V2~~ ✅ Implemented
|
|
136
|
+
**File:** `reflection/gateway/chat_routes_v2.py` (365 lines)
|
|
137
|
+
**Implementation:** 3 endpoints (`POST /v2/chat/completions`, `GET /v2/chat/path-info`,
|
|
138
|
+
`POST /v2/chat/simple`). Dual-path routing: async (direct provider call) vs sync
|
|
139
|
+
(thread pool + full Familiar Agent) via `AsyncOrchestrator` (967 lines). SSE streaming
|
|
140
|
+
with nginx-aware headers. Full auth with JWT, API key, and dev fallback — resolves
|
|
141
|
+
tenant tier from DB.
|
|
142
|
+
**Wired in:** `app.py` — `app.include_router(chat_router_v2, prefix="/api")`.
|
|
143
|
+
Corrected 2026-02-25 after code review.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Known Intentional Stubs
|
|
148
|
+
|
|
149
|
+
None. All previously identified stubs have been verified as fully implemented
|
|
150
|
+
or removed (types package deleted — empty, unreferenced).
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Known Technical Debt
|
|
155
|
+
|
|
156
|
+
### ~~Familiar PyPI Package: Missing Non-Python Files~~ ✅ Fixed (Familiar v1.6.1)
|
|
157
|
+
Fixed by adding `artifacts` to wheel build config. 44 SKILL.md + 27 config.yaml
|
|
158
|
+
files now included.
|
|
159
|
+
|
|
160
|
+
### ~~Familiar PyPI Version Lag~~ ✅ Resolved (v1.6.1 published)
|
|
161
|
+
`familiar-agent==1.6.1` is now on PyPI with all v1.6.0 features (IMAP, mesh
|
|
162
|
+
gateway auth, prev_chain_len) plus the packaging fix.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Architecture Overview
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
Reflection v2.0.0 — Enterprise Multi-Tenant AI Platform
|
|
170
|
+
├── reflection/
|
|
171
|
+
│ ├── cli.py — 20+ typer commands
|
|
172
|
+
│ ├── auth/sso.py — SAML 2.0 + OIDC (550+ lines)
|
|
173
|
+
│ ├── core/
|
|
174
|
+
│ │ ├── settings.py — Pydantic env config
|
|
175
|
+
│ │ ├── orchestrator.py — Sync agent orchestration
|
|
176
|
+
│ │ ├── async_orchestrator.py — Dual-path (async simple, sync complex)
|
|
177
|
+
│ │ ├── providers_async.py — Native Anthropic/OpenAI async SDKs
|
|
178
|
+
│ │ ├── circuit_breaker.py — LLM provider resilience
|
|
179
|
+
│ │ ├── executor.py — Tier-based thread pools
|
|
180
|
+
│ │ ├── tokens.py — Accurate token counting + pricing
|
|
181
|
+
│ │ ├── regions.py — Multi-region routing (519 lines)
|
|
182
|
+
│ │ ├── usage_calculator.py — Unified billing
|
|
183
|
+
│ │ ├── usage_alerts.py — Budget monitoring + webhooks
|
|
184
|
+
│ │ └── memory.py — Summarization + semantic search
|
|
185
|
+
│ ├── data/
|
|
186
|
+
│ │ ├── models.py — SQLAlchemy ORM (8 tables)
|
|
187
|
+
│ │ ├── postgres.py — Async engine (PostgreSQL + SQLite)
|
|
188
|
+
│ │ ├── redis.py — Redis + in-memory fallback
|
|
189
|
+
│ │ └── repositories.py — CRUD with tenant isolation
|
|
190
|
+
│ ├── gateway/
|
|
191
|
+
│ │ ├── app.py — FastAPI with 10+ routers
|
|
192
|
+
│ │ ├── auth.py — JWT + bcrypt (OWASP compliant)
|
|
193
|
+
│ │ ├── auth_routes.py — Register, login, token refresh
|
|
194
|
+
│ │ ├── chat_routes.py — Chat completions + streaming
|
|
195
|
+
│ │ ├── sso_routes.py — Enterprise SSO endpoints
|
|
196
|
+
│ │ ├── health.py — Kubernetes probes + Prometheus
|
|
197
|
+
│ │ ├── request_context.py — ContextVar propagation + X-Request-ID (413 lines)
|
|
198
|
+
│ │ ├── token_store.py — Redis-backed session + refresh rotation (622 lines)
|
|
199
|
+
│ │ ├── quota_middleware.py — Per-request quota enforcement (316 lines)
|
|
200
|
+
│ │ ├── rate_limit.py — Sliding window + progressive lockout (425 lines)
|
|
201
|
+
│ │ └── chat_routes_v2.py — Async dual-path chat API (365 lines)
|
|
202
|
+
│ ├── tenants/
|
|
203
|
+
│ │ ├── context.py — contextvars isolation
|
|
204
|
+
│ │ ├── quotas.py — Redis-backed enforcement
|
|
205
|
+
│ │ ├── lifecycle.py — GDPR Article 17 support
|
|
206
|
+
│ │ └── quota_service.py — Tier-based limits
|
|
207
|
+
│ ├── tenant_wrappers/
|
|
208
|
+
│ │ ├── agent.py — TenantAgent (extends Familiar Agent)
|
|
209
|
+
│ │ ├── memory.py — TenantMemory (DB-native, cached, tenant-isolated)
|
|
210
|
+
│ │ ├── tools.py — TenantToolRegistry (per-tenant enable/disable)
|
|
211
|
+
│ │ └── channels.py — TenantChannelManager + Router (multi-tenant bots)
|
|
212
|
+
│ ├── observability/
|
|
213
|
+
│ │ ├── logging.py — Structured JSON + PII masking
|
|
214
|
+
│ │ ├── metrics.py — 50+ Prometheus metrics
|
|
215
|
+
│ │ ├── tracing.py — OpenTelemetry + fallback
|
|
216
|
+
│ │ └── middleware.py — Metrics + Tracing auto-instrumentation (251 lines)
|
|
217
|
+
│ ├── routing/
|
|
218
|
+
│ │ ├── smart_router.py — HIPAA-aware LLM routing
|
|
219
|
+
│ │ └── phi_detector.py — PHI/PII detection (18 identifiers)
|
|
220
|
+
│ └── jobs/export_handlers.py — GDPR data export (JSON/CSV/ZIP)
|
|
221
|
+
├── reflection_core/
|
|
222
|
+
│ ├── exceptions/hierarchy.py — 19 exception classes (4 domains)
|
|
223
|
+
│ ├── security/encryption.py — Fernet + PBKDF2 (480K iterations)
|
|
224
|
+
│ ├── security/sanitization.py — Shell, path, prompt injection defense
|
|
225
|
+
│ └── security/trust.py — Trust levels + 20 capabilities
|
|
226
|
+
├── tests/ — 19 test files, 667 passing
|
|
227
|
+
├── alembic/ — 4 migrations (8 tables + indexes)
|
|
228
|
+
├── Dockerfile — Multi-stage, non-root, health check
|
|
229
|
+
├── docker-compose.yml — API + PostgreSQL 16 + Redis 7
|
|
230
|
+
└── .github/workflows/ci.yml — lint + test (3.11, 3.12) + Docker build
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Architectural Decisions (Recorded)
|
|
236
|
+
|
|
237
|
+
### Repo Split: Familiar + Reflection (v1.4.0 / v2.0.0)
|
|
238
|
+
Familiar core library split into `omegcrash/familiar` as a standalone PyPI package
|
|
239
|
+
(`familiar-agent`). Reflection multi-tenant platform at `omegcrash/reflection`
|
|
240
|
+
depends on `familiar>=1.4.0`. Android app at `omegcrash/familiar-android` also
|
|
241
|
+
depends on `familiar-agent[llm,mesh]>=1.5.0`.
|
|
242
|
+
|
|
243
|
+
### Dependency Strategy
|
|
244
|
+
Reflection imports Familiar as a library dependency rather than vendoring.
|
|
245
|
+
This means Reflection always gets the latest Familiar features via `pip install --upgrade`.
|
|
246
|
+
|
|
247
|
+
### Dual-Path Orchestration (Phase 5)
|
|
248
|
+
Simple chat (no tools) routes through `AsyncOrchestrator` using native async SDKs.
|
|
249
|
+
Complex workflows (tools enabled) route through `TenantExecutorPool` with sync
|
|
250
|
+
Familiar `Agent.chat()` in thread pools. This avoids blocking the event loop while
|
|
251
|
+
maintaining Familiar's full tool execution capabilities.
|
|
252
|
+
|
|
253
|
+
### Tier-Based Thread Isolation
|
|
254
|
+
Each tenant tier (Free/Pro/Enterprise) gets its own thread pool with bounded queue.
|
|
255
|
+
Prevents noisy-neighbor issues where one tenant's heavy workload blocks others.
|
|
256
|
+
Free: 2 workers, Pro: 10, Enterprise: 50.
|
|
257
|
+
|
|
258
|
+
### HIPAA Smart Routing
|
|
259
|
+
PHI/PII detection runs before every LLM call. If sensitive data is detected and
|
|
260
|
+
the provider doesn't have a BAA, the request is routed to self-hosted Ollama.
|
|
261
|
+
General queries go to cloud APIs for better performance. Manual override available.
|
|
262
|
+
|
|
263
|
+
### Security: reflection_core
|
|
264
|
+
Security primitives (encryption, sanitization, trust model) live in `reflection_core`
|
|
265
|
+
rather than `reflection` to allow reuse without pulling in the full platform.
|
|
266
|
+
PBKDF2 at 480K iterations (OWASP 2023). Fernet for data at rest. Trust model
|
|
267
|
+
mirrors Familiar's with local fallback if Familiar not installed.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## CI Status
|
|
272
|
+
|
|
273
|
+
GitHub Actions pipeline configured in `.github/workflows/ci.yml`.
|
|
274
|
+
Runs on push to main/master/feat/** and pull requests.
|
|
275
|
+
|
|
276
|
+
**Repo:** `omegcrash/reflection`
|
|
277
|
+
**Matrix:** Python 3.11, 3.12 on `ubuntu-latest`
|
|
278
|
+
**Jobs:** Lint (ruff check + format), Test (matrix), Verify Import, Docker Build
|
|
279
|
+
**Lint:** ruff check + format — both clean (77 files)
|
|
280
|
+
|
|
281
|
+
Current result: 700 passed, 0 failed, 1 skipped.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Open Questions
|
|
286
|
+
|
|
287
|
+
1. ~~**Familiar PyPI publish:**~~ ✅ Resolved — v1.6.1 published to PyPI.
|
|
288
|
+
2. ~~**SKILL.md packaging:**~~ ✅ Resolved — fixed in Familiar v1.6.1.
|
|
289
|
+
3. ~~**Stub priority:**~~ ✅ Resolved — the 4 gateway files (request_context, token_store,
|
|
290
|
+
quota_middleware, rate_limit) were misclassified as stubs. All are fully implemented
|
|
291
|
+
and wired in `app.py` / `auth_routes.py`. Corrected 2026-02-25.
|