claude-smart 0.2.42 → 0.2.44
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.
- package/.claude-plugin/marketplace.json +3 -3
- package/README.md +1 -1
- package/bin/claude-smart.js +2 -2
- package/package.json +9 -3
- package/plugin/.claude-plugin/plugin.json +9 -3
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/README.md +23 -3
- package/plugin/pyproject.toml +3 -3
- package/plugin/scripts/_lib.sh +91 -0
- package/plugin/scripts/backend-service.sh +51 -4
- package/plugin/scripts/cli.sh +3 -1
- package/plugin/scripts/codex-hook.js +72 -4
- package/plugin/scripts/dashboard-build.sh +1 -0
- package/plugin/scripts/dashboard-service.sh +1 -0
- package/plugin/scripts/ensure-plugin-root.sh +1 -0
- package/plugin/scripts/hook_entry.sh +6 -3
- package/plugin/scripts/smart-install.sh +3 -2
- package/plugin/src/README.md +57 -0
- package/plugin/src/claude_smart/context_format.py +11 -12
- package/plugin/src/claude_smart/cs_cite.py +26 -12
- package/plugin/src/claude_smart/ids.py +13 -5
- package/plugin/uv.lock +126 -5
- package/plugin/vendor/reflexio/.env.example +62 -0
- package/plugin/vendor/reflexio/LICENSE +201 -0
- package/plugin/vendor/reflexio/README.md +338 -0
- package/plugin/vendor/reflexio/pyproject.toml +274 -0
- package/plugin/vendor/reflexio/reflexio/README.md +184 -0
- package/plugin/vendor/reflexio/reflexio/__init__.py +166 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/README.md +109 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/backends.py +175 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/bench.py +642 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/embed_cache.py +330 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/report.py +317 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/results/report.md +43 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/results/results.json +4478 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/scenarios.py +134 -0
- package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/seed.py +255 -0
- package/plugin/vendor/reflexio/reflexio/cli/README.md +287 -0
- package/plugin/vendor/reflexio/reflexio/cli/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/cli/__main__.py +56 -0
- package/plugin/vendor/reflexio/reflexio/cli/_client.py +86 -0
- package/plugin/vendor/reflexio/reflexio/cli/app.py +127 -0
- package/plugin/vendor/reflexio/reflexio/cli/bootstrap_config.py +265 -0
- package/plugin/vendor/reflexio/reflexio/cli/codex_auth.py +503 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/admin_cmd.py +65 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/agent_playbooks.py +503 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/api.py +114 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/auth.py +109 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/config_cmd.py +511 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/doctor.py +127 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/embeddings.py +53 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/interactions.py +478 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/profiles.py +303 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/services.py +289 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/setup_cmd.py +964 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/shortcuts.py +285 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/status_cmd.py +143 -0
- package/plugin/vendor/reflexio/reflexio/cli/commands/user_playbooks.py +373 -0
- package/plugin/vendor/reflexio/reflexio/cli/env_loader.py +284 -0
- package/plugin/vendor/reflexio/reflexio/cli/errors.py +217 -0
- package/plugin/vendor/reflexio/reflexio/cli/log_format.py +247 -0
- package/plugin/vendor/reflexio/reflexio/cli/output.py +867 -0
- package/plugin/vendor/reflexio/reflexio/cli/paths.py +41 -0
- package/plugin/vendor/reflexio/reflexio/cli/run_services.py +391 -0
- package/plugin/vendor/reflexio/reflexio/cli/state.py +204 -0
- package/plugin/vendor/reflexio/reflexio/cli/stop_services.py +96 -0
- package/plugin/vendor/reflexio/reflexio/cli/utils.py +329 -0
- package/plugin/vendor/reflexio/reflexio/client/__init__.py +3 -0
- package/plugin/vendor/reflexio/reflexio/client/cache.py +150 -0
- package/plugin/vendor/reflexio/reflexio/client/client.py +2613 -0
- package/plugin/vendor/reflexio/reflexio/defaults.py +23 -0
- package/plugin/vendor/reflexio/reflexio/integrations/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/.clawhubignore +7 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/README.md +274 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/TESTING.md +517 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/hook/handler.js +473 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/package-lock.json +2156 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/package.json +18 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/hook/handler.ts +241 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/hook/setup.ts +140 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/index.ts +130 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/publish.ts +113 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/search.ts +52 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/server.ts +103 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/sqlite-buffer.ts +156 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/user-id.ts +134 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/openclaw.plugin.json +41 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/package.json +17 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/rules/reflexio.md +24 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/reflexio/SKILL.md +48 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/publish_clawhub.sh +278 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/references/HOOK.md +164 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/scripts/install.sh +36 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/scripts/uninstall.sh +35 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/publish.test.ts +27 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/search.test.ts +31 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/server.test.ts +42 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/setup.test.ts +49 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/sqlite-buffer.test.ts +91 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/user-id.test.ts +50 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tsconfig.json +16 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/types/openclaw.d.ts +230 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/vitest.config.ts +13 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/README.md +120 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/TESTING.md +168 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/package-lock.json +1657 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/package.json +16 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/HEARTBEAT.md +6 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/README.md +84 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/SKILL.md +194 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/_meta.json +6 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/agents/reflexio-extractor.md +45 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/hook/handler.ts +214 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/hook/setup.ts +55 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/index.ts +327 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/consolidate.ts +233 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/dedup.ts +80 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/io.ts +155 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/openclaw-cli.ts +67 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/search.ts +33 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/write-playbook.ts +76 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/write-profile.ts +79 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/openclaw.plugin.json +46 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/package.json +18 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/README.md +36 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/full_consolidation.md +56 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/playbook_extraction.md +217 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/profile_extraction.md +132 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/skills/reflexio-consolidate/SKILL.md +33 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/skills/reflexio-embedded/SKILL.md +194 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/HOOK.md +18 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/architecture.md +49 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/comparison.md +31 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/future-work.md +47 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/porting-notes.md +52 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/scripts/install.sh +52 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/scripts/uninstall.sh +36 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/consolidate.test.ts +135 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/dedup.test.ts +104 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/io.test.ts +175 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/search.test.ts +66 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/smoke-test.ts +140 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/write-playbook.test.ts +93 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/write-profile.test.ts +174 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tsconfig.json +16 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/types/openclaw.d.ts +230 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/vitest.config.ts +7 -0
- package/plugin/vendor/reflexio/reflexio/lib/__init__.py +23 -0
- package/plugin/vendor/reflexio/reflexio/lib/_agent_playbook.py +310 -0
- package/plugin/vendor/reflexio/reflexio/lib/_base.py +225 -0
- package/plugin/vendor/reflexio/reflexio/lib/_config.py +83 -0
- package/plugin/vendor/reflexio/reflexio/lib/_dashboard.py +266 -0
- package/plugin/vendor/reflexio/reflexio/lib/_generation.py +176 -0
- package/plugin/vendor/reflexio/reflexio/lib/_interactions.py +334 -0
- package/plugin/vendor/reflexio/reflexio/lib/_operations.py +153 -0
- package/plugin/vendor/reflexio/reflexio/lib/_profiles.py +545 -0
- package/plugin/vendor/reflexio/reflexio/lib/_reflection.py +52 -0
- package/plugin/vendor/reflexio/reflexio/lib/_search.py +167 -0
- package/plugin/vendor/reflexio/reflexio/lib/_storage_labels.py +103 -0
- package/plugin/vendor/reflexio/reflexio/lib/_user_playbook.py +288 -0
- package/plugin/vendor/reflexio/reflexio/lib/reflexio_lib.py +27 -0
- package/plugin/vendor/reflexio/reflexio/models/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/braintrust_schema.py +141 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/common.py +41 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/__init__.py +3 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/entities.py +1112 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/enums.py +63 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/eval_overview_schema.py +487 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/internal_schema.py +28 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/pending_tool_call_schema.py +83 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/retriever_schema.py +768 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/service_schemas.py +9 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/stall_state_schema.py +32 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/__init__.py +3 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/converters.py +177 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/entities.py +129 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/enums.py +25 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/validators.py +333 -0
- package/plugin/vendor/reflexio/reflexio/models/config_schema.py +908 -0
- package/plugin/vendor/reflexio/reflexio/models/py.typed +0 -0
- package/plugin/vendor/reflexio/reflexio/server/OVERVIEW.md +90 -0
- package/plugin/vendor/reflexio/reflexio/server/README.md +622 -0
- package/plugin/vendor/reflexio/reflexio/server/__init__.py +210 -0
- package/plugin/vendor/reflexio/reflexio/server/__main__.py +132 -0
- package/plugin/vendor/reflexio/reflexio/server/_auth.py +25 -0
- package/plugin/vendor/reflexio/reflexio/server/api.py +2868 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/README.md +34 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/account_api.py +143 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/health_api.py +91 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/pending_tool_call_api.py +572 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/precondition_checks.py +66 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/publisher_api.py +562 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/request_context.py +50 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/stall_state_api.py +100 -0
- package/plugin/vendor/reflexio/reflexio/server/cache/__init__.py +15 -0
- package/plugin/vendor/reflexio/reflexio/server/cache/reflexio_cache.py +208 -0
- package/plugin/vendor/reflexio/reflexio/server/correlation.py +46 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/__init__.py +30 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/embedding_service.py +359 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/image_utils.py +55 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/litellm_client.py +1871 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/llm_utils.py +140 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/model_defaults.py +479 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/claude_code_provider.py +1122 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/claude_code_stream_parser.py +197 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/embedding_service_provider.py +338 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/local_embedding_provider.py +213 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/nomic_embedding_provider.py +288 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/rerank/__init__.py +6 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/rerank/cross_encoder_reranker.py +187 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/rerank/llm_reranker.py +148 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/tools.py +716 -0
- package/plugin/vendor/reflexio/reflexio/server/operation_limiter.py +179 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/_dispatchers.py +54 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/README.md +121 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/agent_success_evaluation/v1.0.0.prompt.md +58 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/agent_success_evaluation_with_comparison/v1.0.0.prompt.md +76 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/answer_synthesis/v1.5.2.prompt.md +88 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/compress_session_for_query/v1.3.0.prompt.md +31 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/document_expansion/v1.0.0.prompt.md +20 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.0.0.prompt.md +53 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.1.0.prompt.md +57 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.2.0.prompt.md +68 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.3.0.prompt.md +70 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.4.0.prompt.md +77 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.5.0.prompt.md +82 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.6.0.prompt.md +83 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_aggregation/v2.1.0.prompt.md +193 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_aggregation/v2.2.0.prompt.md +206 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v1.0.0-deprecated.prompt.md +66 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v1.0.0.prompt.md +43 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v1.1.0.prompt.md +46 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.0.0-deprecated.prompt.md +64 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.0.0.prompt.md +39 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.1.0.prompt.md +39 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.2.0.prompt.md +47 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.3.0.prompt.md +58 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.3.1.prompt.md +69 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.3.2.prompt.md +71 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.0.2.prompt.md +254 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.1.0.prompt.md +274 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.2.0.prompt.md +283 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.2.2.prompt.md +234 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.2.3.prompt.md +244 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v1.0.0.prompt.md +73 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v2.0.0.prompt.md +86 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.0.0.prompt.md +97 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.1.0.prompt.md +119 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.2.0.prompt.md +123 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.3.0.prompt.md +137 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.0.0.prompt.md +14 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.1.0.prompt.md +24 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.2.0.prompt.md +29 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main_expert/v1.0.0.prompt.md +11 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main_expert/v1.1.0.prompt.md +21 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main_expert/v1.2.0.prompt.md +25 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_optimizer_judge/v1.0.0.prompt.md +37 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_optimizer_judge/v1.1.0.prompt.md +40 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_optimizer_judge/v1.2.0.prompt.md +36 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate/v1.0.0.prompt.md +45 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate/v2.0.0.prompt.md +81 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate/v3.0.0.prompt.md +80 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate_expert/v1.0.0.prompt.md +34 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_deduplication/v1.0.0.prompt.md +116 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_should_generate/v1.0.0.prompt.md +33 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_should_generate_override/v1.0.0.prompt.md +16 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_instruction_start/v1.0.0.prompt.md +140 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_instruction_start/v1.1.0.prompt.md +160 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_main/v1.0.0.prompt.md +14 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/query_reformulation/v1.0.0.prompt.md +19 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/rerank_relevance/v1.1.0.prompt.md +44 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/shadow_comparison/v1.0.0.prompt.md +43 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/shadow_content_evaluation/v1.0.0.prompt.md +33 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_evaluation/prompt_evaluation_dataset/feedback_extraction_main_v1.jsonl +10 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_evaluation/prompt_evaluation_dataset/profile_update_main_v1.jsonl +10 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_manager.py +280 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_schema.py +11 -0
- package/plugin/vendor/reflexio/reflexio/server/services/README.md +58 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/_eval_health.py +131 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_constants.py +60 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_service.py +228 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_utils.py +87 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluator.py +372 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/delayed_group_evaluator.py +156 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/group_evaluation_runner.py +336 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/regen_jobs.py +471 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation_service.py +1668 -0
- package/plugin/vendor/reflexio/reflexio/server/services/braintrust/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/services/braintrust/_cron.py +196 -0
- package/plugin/vendor/reflexio/reflexio/server/services/braintrust/_encryption.py +101 -0
- package/plugin/vendor/reflexio/reflexio/server/services/braintrust/client.py +167 -0
- package/plugin/vendor/reflexio/reflexio/server/services/braintrust/service.py +281 -0
- package/plugin/vendor/reflexio/reflexio/server/services/configurator/base_configurator.py +179 -0
- package/plugin/vendor/reflexio/reflexio/server/services/configurator/config_storage.py +62 -0
- package/plugin/vendor/reflexio/reflexio/server/services/configurator/configurator.py +87 -0
- package/plugin/vendor/reflexio/reflexio/server/services/configurator/local_file_config_storage.py +187 -0
- package/plugin/vendor/reflexio/reflexio/server/services/configurator/test_config_storage.py +162 -0
- package/plugin/vendor/reflexio/reflexio/server/services/deduplication_utils.py +112 -0
- package/plugin/vendor/reflexio/reflexio/server/services/embedding_text.py +62 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/distribution.py +33 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/eval_sampler.py +126 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/group_aggregation.py +192 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/hero_state.py +75 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/rule_attribution.py +97 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/service.py +515 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/shadow_aggregation.py +90 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/agent_run_records.py +91 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/invariants.py +303 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/outcome.py +25 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/pending_tool_call_dispatch.py +358 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/plan.py +138 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/prior_answer_search.py +217 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/resumable_agent.py +535 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/resume_scheduler.py +171 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/resume_worker.py +779 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/tools.py +1125 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extractor_config_utils.py +94 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extractor_interaction_utils.py +251 -0
- package/plugin/vendor/reflexio/reflexio/server/services/generation_service.py +702 -0
- package/plugin/vendor/reflexio/reflexio/server/services/operation_state_utils.py +835 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/README.md +89 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_aggregator.py +1388 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_consolidator.py +1045 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_extractor.py +436 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_generation_service.py +808 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_service_constants.py +28 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_service_utils.py +362 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/__init__.py +24 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/assistant_webhook.py +246 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/gepa_adapter.py +291 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/judge.py +97 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/models.py +96 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/optimizer.py +645 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/rollout.py +35 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/scenario_resolver.py +93 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/scheduler.py +174 -0
- package/plugin/vendor/reflexio/reflexio/server/services/pre_retrieval/__init__.py +26 -0
- package/plugin/vendor/reflexio/reflexio/server/services/pre_retrieval/_document_expander.py +179 -0
- package/plugin/vendor/reflexio/reflexio/server/services/pre_retrieval/_query_reformulator.py +297 -0
- package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_deduplicator.py +772 -0
- package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_extractor.py +462 -0
- package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_generation_service.py +737 -0
- package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_generation_service_utils.py +290 -0
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/__init__.py +17 -0
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/reflection_extractor.py +247 -0
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/reflection_service.py +803 -0
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/reflection_service_utils.py +146 -0
- package/plugin/vendor/reflexio/reflexio/server/services/retrieval/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/services/retrieval/relevance_floor.py +80 -0
- package/plugin/vendor/reflexio/reflexio/server/services/search/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/services/service_utils.py +756 -0
- package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/judge.py +184 -0
- package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/outcome.py +81 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/constants.py +2 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/error.py +11 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/retention.py +154 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/retention_mixin.py +155 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/__init__.py +59 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_agent_run.py +1298 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_base.py +1945 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_extras.py +600 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_operations.py +346 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_playbook.py +1378 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_profiles.py +747 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_requests.py +263 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_shadow_verdicts.py +193 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_share_links.py +166 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_stall_state.py +217 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/__init__.py +153 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_agent_run.py +384 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_base.py +71 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_extras.py +235 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_operations.py +170 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_playbook.py +677 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_profiles.py +250 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_requests.py +154 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_shadow_verdicts.py +130 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_share_links.py +93 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_stall_state.py +76 -0
- package/plugin/vendor/reflexio/reflexio/server/services/unified_search_service.py +572 -0
- package/plugin/vendor/reflexio/reflexio/server/site_var/README.md +77 -0
- package/plugin/vendor/reflexio/reflexio/server/site_var/feature_flags.py +116 -0
- package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_manager.py +263 -0
- package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_sources/feature_flags.json +13 -0
- package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_sources/llm_model_setting.json +7 -0
- package/plugin/vendor/reflexio/reflexio/server/tracing.py +158 -0
- package/plugin/vendor/reflexio/reflexio/server/usage_metrics.py +113 -0
- package/plugin/vendor/reflexio/reflexio/server/uvicorn_logging.py +76 -0
- package/plugin/vendor/reflexio/reflexio/test_support/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/test_support/llm_fixtures.py +62 -0
- package/plugin/vendor/reflexio/reflexio/test_support/llm_mock.py +242 -0
- package/plugin/vendor/reflexio/reflexio/test_support/llm_model_registry.py +129 -0
- package/plugin/vendor/reflexio/reflexio/test_support/skip_decorators.py +43 -0
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
# Reflexio Server
|
|
2
|
+
Description: FastAPI backend server that processes user interactions to generate profiles, extract playbooks, and evaluate agent success
|
|
3
|
+
|
|
4
|
+
## Table of Contents
|
|
5
|
+
|
|
6
|
+
- [Main Entry Points](#main-entry-points)
|
|
7
|
+
- [Cache](#cache)
|
|
8
|
+
- [API Endpoints](#api-endpoints)
|
|
9
|
+
- [LLM Client](#llm-client)
|
|
10
|
+
- [Prompts](#prompts)
|
|
11
|
+
- [Site Variables](#site-variables)
|
|
12
|
+
- [Scripts](#scripts)
|
|
13
|
+
- [Services](#services)
|
|
14
|
+
- [Orchestrator](#orchestrator)
|
|
15
|
+
- [Base Infrastructure](#base-infrastructure)
|
|
16
|
+
- [Profile Generation](#profile-generation)
|
|
17
|
+
- [Playbook Extraction](#playbook-extraction)
|
|
18
|
+
- [Agent Success Evaluation](#agent-success-evaluation)
|
|
19
|
+
- [Reflection and Async Extraction](#reflection-and-async-extraction)
|
|
20
|
+
- [Shadow Comparison and Evaluation Overview](#shadow-comparison-and-evaluation-overview)
|
|
21
|
+
- [Playbook Optimizer and Braintrust](#playbook-optimizer-and-braintrust)
|
|
22
|
+
- [Query Reformulator](#query-reformulator)
|
|
23
|
+
- [Unified Search Service](#unified-search-service)
|
|
24
|
+
- [Storage](#storage)
|
|
25
|
+
- [Configurator](#configurator)
|
|
26
|
+
- [Architecture Patterns](#architecture-patterns)
|
|
27
|
+
- [Request Flow](#request-flow)
|
|
28
|
+
- [Service Pattern](#service-pattern)
|
|
29
|
+
- [Key Rules](#key-rules)
|
|
30
|
+
- [See Also](#see-also)
|
|
31
|
+
|
|
32
|
+
## Main Entry Points
|
|
33
|
+
|
|
34
|
+
- **API**: `api.py` - FastAPI routes (only place to expose endpoints)
|
|
35
|
+
- **Endpoint Helpers**: `api_endpoints/` - Bridge between routes and business logic
|
|
36
|
+
- **Core Service**: `services/generation_service.py` - Main orchestrator
|
|
37
|
+
|
|
38
|
+
## Cache
|
|
39
|
+
|
|
40
|
+
**Directory**: `cache/`
|
|
41
|
+
|
|
42
|
+
| File | Purpose |
|
|
43
|
+
|------|---------|
|
|
44
|
+
| `reflexio_cache.py` | TTL-cached Reflexio instances (1 hour TTL, max 100 orgs) |
|
|
45
|
+
|
|
46
|
+
**Key Functions**:
|
|
47
|
+
- `get_reflexio(org_id)` - Get or create cached instance
|
|
48
|
+
- `invalidate_reflexio_cache(org_id)` - Invalidate after config changes
|
|
49
|
+
- `clear_reflexio_cache()` - Clear entire cache (testing/admin)
|
|
50
|
+
|
|
51
|
+
**Pattern**: **ALWAYS use `get_reflexio()`** instead of `Reflexio()` directly in API endpoints
|
|
52
|
+
|
|
53
|
+
## API Endpoints
|
|
54
|
+
|
|
55
|
+
**Directory**: `api_endpoints/`
|
|
56
|
+
|
|
57
|
+
**Detailed Documentation**: See [`api_endpoints/README.md`](api_endpoints/README.md) for the `RequestContext` contract and per-file handler map.
|
|
58
|
+
|
|
59
|
+
| File | Purpose |
|
|
60
|
+
|------|---------|
|
|
61
|
+
| `request_context.py` | RequestContext (bundles org_id, storage, configurator, prompt_manager) |
|
|
62
|
+
| `publisher_api.py` | Publishing interactions plus direct create/update/delete helpers for profiles, playbooks, requests, sessions, and clear-data operations |
|
|
63
|
+
| `account_api.py` | Account/config identity helpers used by `/api/whoami` and related account surfaces |
|
|
64
|
+
| `health_api.py` | `/healthz` and `/healthz/eval` health checks |
|
|
65
|
+
| `pending_tool_call_api.py` | Pending tool-call and human-clarification routes for resumable extraction |
|
|
66
|
+
| `stall_state_api.py` | Stall-state read/update routes |
|
|
67
|
+
| `precondition_checks.py` | Request validation |
|
|
68
|
+
|
|
69
|
+
**Key Endpoints**:
|
|
70
|
+
- **Health/version**: `GET /`, `GET /health`, `GET /healthz`, `GET /healthz/eval`, `GET /meta/version`
|
|
71
|
+
- **Identity/config**: `GET /api/whoami`, `GET /api/my_config`, `GET /api/get_config`, `POST /api/set_config`, `POST /api/update_config`
|
|
72
|
+
- **Publish/direct writes**: `POST /api/publish_interaction`, `POST /api/add_user_profile`, `POST /api/add_user_playbook`, `POST /api/add_agent_playbook`
|
|
73
|
+
- **Retrieval**: `POST /api/get_requests`, `POST /api/get_interactions`, `GET /api/get_all_interactions`, `POST /api/get_profiles`, `GET /api/get_all_profiles`, `POST /api/get_user_playbooks`, `POST /api/get_agent_playbooks`, `POST /api/get_agent_success_evaluation_results`
|
|
74
|
+
- **Search/stats**: `POST /api/search`, `POST /api/search_profiles`, `POST /api/rerank_user_profiles`, `POST /api/search_interactions`, `POST /api/search_user_playbooks`, `POST /api/search_agent_playbooks`, `GET /api/storage_stats`, `GET /api/get_profile_statistics`, `POST /api/get_dashboard_stats`, `POST /api/get_playbook_application_stats`
|
|
75
|
+
- **Profile lifecycle**: `POST /api/rerun_profile_generation`, `POST /api/manual_profile_generation`, `POST /api/upgrade_all_profiles`, `POST /api/downgrade_all_profiles`, `GET /api/profile_change_log`, `PUT /api/update_user_profile`, `DELETE /api/delete_profile`, `DELETE /api/delete_profiles_by_ids`, `DELETE /api/delete_all_profiles`
|
|
76
|
+
- **Playbook lifecycle**: `POST /api/rerun_playbook_generation`, `POST /api/manual_playbook_generation`, `POST /api/run_playbook_aggregation`, `GET /api/playbook_aggregation_change_logs`, `POST /api/upgrade_all_user_playbooks`, `POST /api/downgrade_all_user_playbooks`, `PUT /api/update_agent_playbook_status`, `PUT /api/update_agent_playbook`, `PUT /api/update_user_playbook`, `DELETE /api/delete_agent_playbook`, `DELETE /api/delete_user_playbook`, `DELETE /api/delete_agent_playbooks_by_ids`, `DELETE /api/delete_user_playbooks_by_ids`, `DELETE /api/delete_all_playbooks`, `DELETE /api/delete_all_user_playbooks`, `DELETE /api/delete_all_agent_playbooks`
|
|
77
|
+
- **Evaluation**: `POST /api/get_evaluation_overview`, `POST /api/evaluations/regenerate`, `GET /api/evaluations/regenerate/{job_id}`, `DELETE /api/evaluations/regenerate/{job_id}`, `POST /api/evaluations/grade_on_demand`, `GET /api/evaluations/shadow_comparisons/recent`
|
|
78
|
+
- **Braintrust**: `POST /api/braintrust/connect`, `POST /api/braintrust/select_projects`, `GET /api/braintrust/status`, `DELETE /api/braintrust/connection`, `POST /api/braintrust/sync`
|
|
79
|
+
- **Operations/admin**: `GET /api/get_operation_status`, `POST /api/cancel_operation`, `POST /api/admin/cache/invalidate`, `DELETE /api/delete_interaction`, `DELETE /api/delete_request`, `DELETE /api/delete_session`, `DELETE /api/delete_requests_by_ids`, `DELETE /api/delete_all_interactions`, `POST /api/clear_user_data`
|
|
80
|
+
- **Human clarification/stall state**: `GET /api/pending_tool_calls`, `GET /api/pending_tool_calls/{pending_tool_call_id}`, `POST /api/pending_tool_calls/{pending_tool_call_id}/resolve`, `PATCH /api/pending_tool_calls/{pending_tool_call_id}/answer`, `POST /api/pending_tool_calls/{pending_tool_call_id}/not_applicable`, `POST /api/pending_tool_calls/{pending_tool_call_id}/cancel`, `GET /api/stall_state`, `POST /api/stall_state/notified`
|
|
81
|
+
|
|
82
|
+
**Authentication Pattern**: The open-source app uses `default_get_org_id` and `DEFAULT_ORG_ID` for local/no-auth starts. The enterprise extension wraps `create_app()` with authenticated org resolution, login/OAuth/account/share/waitlist routers, admin checks, Sentry tracing, and usage metrics.
|
|
83
|
+
|
|
84
|
+
**Pattern**: Core route handlers call `Reflexio` through `get_reflexio(org_id)`; endpoint helper files should not instantiate `Reflexio` directly.
|
|
85
|
+
|
|
86
|
+
## LLM Client
|
|
87
|
+
|
|
88
|
+
**Directory**: `llm/`
|
|
89
|
+
**Entry Point**: `litellm_client.py` - `LiteLLMClient`
|
|
90
|
+
|
|
91
|
+
Key files:
|
|
92
|
+
- `litellm_client.py`: Unified LiteLLMClient using LiteLLM for multi-provider support
|
|
93
|
+
- `openai_client.py`: OpenAI implementation (legacy, do not use directly)
|
|
94
|
+
- `claude_client.py`: Claude implementation (legacy, do not use directly)
|
|
95
|
+
- `llm_utils.py`: Helper functions for Pydantic model conversion
|
|
96
|
+
|
|
97
|
+
**Features**:
|
|
98
|
+
- Uses LiteLLM for multi-provider support (OpenAI, Claude, Azure, OpenRouter, Gemini, custom endpoints, etc.)
|
|
99
|
+
- **Custom endpoint support**: `CustomEndpointConfig` (model, api_key, api_base) takes priority over all other providers for LLM completion calls when configured with non-empty fields (but not embeddings)
|
|
100
|
+
- **Gemini support**: Model names with `gemini/` prefix route through Google Gemini; API key from `api_key_config.gemini`
|
|
101
|
+
- **OpenRouter support**: Model names with `openrouter/` prefix (e.g., `openrouter/openai/gpt-5-nano`) route through OpenRouter; API key from `api_key_config.openrouter`
|
|
102
|
+
- API keys read from environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY) or `ApiKeyConfig`
|
|
103
|
+
- Interface: `generate_response()`, `generate_chat_response()`, `get_embedding()`
|
|
104
|
+
- **Structured Outputs**: Supports Pydantic models via `response_format` parameter
|
|
105
|
+
- Return types: `str` for text, or `BaseModel` for Pydantic models
|
|
106
|
+
|
|
107
|
+
**Usage**:
|
|
108
|
+
```python
|
|
109
|
+
from reflexio.server.llm.litellm_client import LiteLLMClient, LiteLLMConfig
|
|
110
|
+
|
|
111
|
+
# Create client
|
|
112
|
+
config = LiteLLMConfig(model="gpt-4o-mini")
|
|
113
|
+
client = LiteLLMClient(config)
|
|
114
|
+
|
|
115
|
+
# Text response
|
|
116
|
+
response = client.generate_response("Hello") # Returns str
|
|
117
|
+
|
|
118
|
+
# Structured output with Pydantic model
|
|
119
|
+
from pydantic import BaseModel
|
|
120
|
+
class Answer(BaseModel):
|
|
121
|
+
result: int
|
|
122
|
+
response = client.generate_response("What is 2+2?", response_format=Answer) # Returns Answer instance
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Rules**:
|
|
126
|
+
- **ALWAYS use `LiteLLMClient`**, never import `OpenAIClient` or `ClaudeClient` directly
|
|
127
|
+
- **ALWAYS use Pydantic models** for structured outputs (dict-based schemas are not supported)
|
|
128
|
+
|
|
129
|
+
## Prompts
|
|
130
|
+
|
|
131
|
+
**Directory**: `prompt/`
|
|
132
|
+
|
|
133
|
+
**Detailed Documentation**: See [`prompt/prompt_bank/README.md`](prompt/prompt_bank/README.md) for the versioned template system.
|
|
134
|
+
|
|
135
|
+
Key components:
|
|
136
|
+
- `prompt_manager.py`: PromptManager for loading and rendering
|
|
137
|
+
- `prompt_bank/`: Templates by prompt_id (metadata.json + version.prompt files)
|
|
138
|
+
|
|
139
|
+
**Pattern**: Access via `request_context.prompt_manager.render_prompt(prompt_id, variables)`
|
|
140
|
+
|
|
141
|
+
## Site Variables
|
|
142
|
+
|
|
143
|
+
**Directory**: `site_var/`
|
|
144
|
+
|
|
145
|
+
**Detailed Documentation**: See [`site_var/README.md`](site_var/README.md) for the full configuration and feature flag system.
|
|
146
|
+
|
|
147
|
+
| File | Purpose |
|
|
148
|
+
|------|---------|
|
|
149
|
+
| `site_var_manager.py` | SiteVarManager (singleton) - loads JSON/TXT configs |
|
|
150
|
+
| `feature_flags.py` | Per-org feature gating (`is_feature_enabled()`, `get_all_feature_flags()`) |
|
|
151
|
+
|
|
152
|
+
**Feature Flags**: Config in `site_var_sources/feature_flags.json`. Each flag has global `enabled` toggle and per-org `enabled_org_ids` allowlist. Unknown flags default to enabled (fail-open). Currently gates: `invitation_only` (global flag, gates registration to require invitation codes), `deduplicator` (gates playbook deduplication).
|
|
153
|
+
|
|
154
|
+
Access: `SiteVarManager().get_site_var(key)` for raw values, `feature_flags.is_feature_enabled(org_id, name)` for flag checks
|
|
155
|
+
|
|
156
|
+
## Scripts
|
|
157
|
+
|
|
158
|
+
**Directory**: `scripts/`
|
|
159
|
+
|
|
160
|
+
| File | Purpose |
|
|
161
|
+
|------|---------|
|
|
162
|
+
| `manage_invitation_codes.py` | CLI to generate and list invitation codes |
|
|
163
|
+
| `show_raw_feedback_with_interactions.py` | Debug script to display user playbook alongside interaction context |
|
|
164
|
+
|
|
165
|
+
**Usage**:
|
|
166
|
+
```shell
|
|
167
|
+
python -m reflexio.server.scripts.manage_invitation_codes generate --count 5
|
|
168
|
+
python -m reflexio.server.scripts.manage_invitation_codes generate --count 3 --expires-in-days 30
|
|
169
|
+
python -m reflexio.server.scripts.manage_invitation_codes list
|
|
170
|
+
python -m reflexio.server.scripts.manage_invitation_codes list --show-used
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Services
|
|
174
|
+
|
|
175
|
+
**Directory**: `services/`
|
|
176
|
+
|
|
177
|
+
**Detailed Documentation**: See [`services/README.md`](services/README.md) for the per-directory file index across generation, evaluation, async extraction, search, and persistence.
|
|
178
|
+
|
|
179
|
+
**Service Boundary**: The service layer owns LLM orchestration, extraction, evaluation, optimization, search preparation, storage access, and long-running operation state. API endpoints should validate/authenticate requests, build `RequestContext`, and delegate into `Reflexio` or focused service helpers rather than embedding business logic.
|
|
180
|
+
|
|
181
|
+
**Encapsulated Components**:
|
|
182
|
+
- **Publish pipeline**: `generation_service.py` coordinates interaction persistence, profile generation, playbook generation, reflection, and deferred evaluation scheduling.
|
|
183
|
+
- **Profile memory**: `profile/` extracts, deduplicates, and applies user profile updates.
|
|
184
|
+
- **Playbook memory**: `playbook/` extracts user playbooks, consolidates them against existing rows, aggregates them into agent playbooks, and tracks aggregation change logs.
|
|
185
|
+
- **Evaluation**: `agent_success_evaluation/`, `shadow_comparison/`, and `evaluation_overview/` handle session grading, per-turn shadow verdicts, regeneration jobs, and dashboard-facing rollups.
|
|
186
|
+
- **Async clarification**: `extraction/` and `reflection/` manage resumable agent runs, pending tool calls, prior-answer search, and long-horizon reflection updates.
|
|
187
|
+
- **Search preparation**: `pre_retrieval/` and `unified_search_service.py` handle query reformulation, document expansion, embeddings, and cross-entity search orchestration.
|
|
188
|
+
- **Optimization/integrations**: `playbook_optimizer/` and `braintrust/` run candidate playbook optimization, rollout support, and Braintrust export/sync.
|
|
189
|
+
- **Persistence/config**: `storage/`, `configurator/`, and `operation_state_utils.py` provide storage abstractions, config loading, locks, bookmarks, progress, and cancellation.
|
|
190
|
+
|
|
191
|
+
### Orchestrator
|
|
192
|
+
|
|
193
|
+
**File**: `generation_service.py` - GenerationService
|
|
194
|
+
|
|
195
|
+
Main orchestrator flow:
|
|
196
|
+
1. Save interactions to storage
|
|
197
|
+
2. Run ProfileGenerationService, PlaybookGenerationService in parallel (ThreadPoolExecutor, 2 workers)
|
|
198
|
+
3. Schedule deferred agent success evaluation via `GroupEvaluationScheduler` when `session_id` is present (10 min delay after last request in session)
|
|
199
|
+
|
|
200
|
+
**Timeout Protection**: Two-layer timeout strategy:
|
|
201
|
+
- **Service level**: `GENERATION_SERVICE_TIMEOUT_SECONDS = 600` (10 min) — outer timeout for each parallel service
|
|
202
|
+
- **Extractor level**: `EXTRACTOR_TIMEOUT_SECONDS = 300` (5 min) — per-extractor safety net in `base_generation_service.py`
|
|
203
|
+
- If one service/extractor times out, others continue unaffected
|
|
204
|
+
|
|
205
|
+
**Stride Size Processing**: Each extractor independently checks if it should run based on its configured stride_size size and tracks its own operation state.
|
|
206
|
+
|
|
207
|
+
Called by API endpoints via `Reflexio`
|
|
208
|
+
|
|
209
|
+
**Profile Timeout Troubleshooting**:
|
|
210
|
+
- Use `python -m reflexio.scripts.reproduce_profile_timeout --mode storage --org-id <org> --user-id <user>` to reproduce with real interactions.
|
|
211
|
+
- Use `--mode log --log-path server_log.txt` to replay extraction prompts captured in logs.
|
|
212
|
+
- Look for structured events in logs:
|
|
213
|
+
- `event=profile_extract_llm_start` / `event=profile_extract_llm_end`
|
|
214
|
+
- `event=llm_request_start` / `event=llm_request_end`
|
|
215
|
+
- `event=profile_extract_failed`
|
|
216
|
+
- If all extractors fail for a user during rerun/manual operations, the user is now marked in `failed_user_ids` instead of silently completing with zero generated items.
|
|
217
|
+
|
|
218
|
+
### Base Infrastructure
|
|
219
|
+
|
|
220
|
+
- `base_generation_service.py`: Abstract base for all services (parallel extractor execution via ThreadPoolExecutor, `EXTRACTOR_TIMEOUT_SECONDS = 300` per-extractor safety timeout)
|
|
221
|
+
- `extractor_config_utils.py`: Shared utility for filtering extractor configs by source, `allow_manual_trigger`, and extractor names
|
|
222
|
+
- `extractor_interaction_utils.py`: Per-extractor utilities for stride_size checking and source filtering
|
|
223
|
+
- `operation_state_utils.py`: Centralized `OperationStateManager` for all `_operation_state` table interactions (progress tracking, concurrency locks, extractor/aggregator bookmarks, simple locks)
|
|
224
|
+
- `deduplication_utils.py`: Shared utilities for LLM-based deduplication (used by ProfileDeduplicator and PlaybookConsolidator)
|
|
225
|
+
- `service_utils.py`: Utilities (`construct_messages_from_interactions()`, `format_interactions_to_history_string()` (prepends tool usage info when `tools_used` is present), `extract_json_from_string()`, `log_model_response()` for colored LLM response logging)
|
|
226
|
+
|
|
227
|
+
**Operation State Management** (via `OperationStateManager` in `operation_state_utils.py`):
|
|
228
|
+
- Centralized manager for all `_operation_state` table interactions with 6 use cases:
|
|
229
|
+
1. **Progress tracking**: Rerun + manual batch operations (key: `{service}::{org_id}::progress`)
|
|
230
|
+
2. **Concurrency lock**: Atomic lock with request queuing (key: `{service}::{org_id}[::scope_id]::lock`)
|
|
231
|
+
3. **Extractor bookmark**: Track last-processed interactions per extractor (key: `{service}::{org_id}[::scope_id]::{name}`)
|
|
232
|
+
4. **Aggregator bookmark**: Track last-processed raw_feedback_id per aggregator
|
|
233
|
+
4b. **Cluster fingerprints**: Track cluster membership fingerprints for change detection (key: `{service}::{org_id}::{name}[::version]::clusters`)
|
|
234
|
+
5. **Simple lock**: Non-queuing lock for cleanup operations
|
|
235
|
+
6. **Cancellation**: Cooperative cancellation for batch operations (`request_cancellation()`, `is_cancellation_requested()`, `mark_cancelled()`). Uses separate DB row (key: `{service}::{org_id}::cancellation`) to avoid lost-update race conditions with progress updates.
|
|
236
|
+
- Stale lock timeout: 5 minutes (assumes crashed if lock held longer)
|
|
237
|
+
- Lock scoping: Profile generation = per-user, Playbook generation = per-org
|
|
238
|
+
- Re-run mechanism: If new request arrives during generation, `pending_request_id` is set and generation re-runs after completion
|
|
239
|
+
|
|
240
|
+
### Profile Generation
|
|
241
|
+
|
|
242
|
+
**Directory**: `services/profile/`
|
|
243
|
+
|
|
244
|
+
Key files:
|
|
245
|
+
- `profile_generation_service.py`: Service orchestrator
|
|
246
|
+
- `profile_extractor.py`: Extractor that generates profile updates
|
|
247
|
+
- `profile_updater.py`: Applies updates (add/delete/mention) to storage
|
|
248
|
+
- `profile_deduplicator.py`: Deduplicates newly extracted profiles against existing DB profiles using LLM
|
|
249
|
+
|
|
250
|
+
**Flow**: Interactions → ProfileExtractor (extraction-only) → ProfileDeduplicator (deduplicates new vs existing DB profiles) → ProfileUpdater → Storage
|
|
251
|
+
|
|
252
|
+
**Generation Modes** (detailed comparison):
|
|
253
|
+
|
|
254
|
+
| Aspect | Regular | Rerun | Manual Regular |
|
|
255
|
+
|--------|---------|-------|----------------|
|
|
256
|
+
| **Trigger** | Auto (on publish) | Manual (API) | Manual (API) |
|
|
257
|
+
| **Stride Check** | Yes (skips if below threshold) | No (always runs) | No (always runs) |
|
|
258
|
+
| **Interactions** | Window-sized (last k) | Window-sized (last k) | Window-sized (last k) |
|
|
259
|
+
| **Time Range Filter** | No | Yes (optional start/end) | No |
|
|
260
|
+
| **Pre-processing** | None | None | None |
|
|
261
|
+
| **Existing Profile Context** | All profiles loaded | Only PENDING profiles loaded | All profiles loaded |
|
|
262
|
+
| **Output Status** | CURRENT | PENDING | CURRENT |
|
|
263
|
+
| **Scope** | Single user | Batch (all matching users, with progress) | Batch (all/single user, with progress) |
|
|
264
|
+
| **Use Case** | Normal operation | Test prompt changes | Force regeneration |
|
|
265
|
+
|
|
266
|
+
**Note**: All modes use `window_size` (per-extractor override or global). The key difference is that Regular checks stride_size before running, while Rerun/Manual always run. When no window is configured, rerun/manual falls back to `k=1000`.
|
|
267
|
+
|
|
268
|
+
**Constructor Flags** (`ProfileGenerationService`):
|
|
269
|
+
- `allow_manual_trigger`: Include `manual_trigger=True` extractors (default: False)
|
|
270
|
+
- `output_pending_status`: Set output profiles to PENDING status (default: False)
|
|
271
|
+
|
|
272
|
+
**Profile Versioning Workflow**:
|
|
273
|
+
|
|
274
|
+
Users can regenerate and manage profile versions using a four-state system:
|
|
275
|
+
|
|
276
|
+
1. **CURRENT** (status=None): Active profiles shown to users
|
|
277
|
+
2. **PENDING** (status="pending"): Newly generated profiles awaiting review
|
|
278
|
+
3. **ARCHIVED** (status="archived"): Previous version of profiles
|
|
279
|
+
4. **ARCHIVE_IN_PROGRESS** (status="archive_in_progress"): Temporary status during downgrade operation
|
|
280
|
+
|
|
281
|
+
**Rerun Workflow**:
|
|
282
|
+
```
|
|
283
|
+
1. Rerun Generation → Creates PENDING profiles (existing CURRENT unchanged)
|
|
284
|
+
2. Review PENDING → Compare new vs current profiles
|
|
285
|
+
3. Upgrade → CURRENT→ARCHIVED, PENDING→CURRENT, delete old ARCHIVED
|
|
286
|
+
4. OR Downgrade → CURRENT→ARCHIVED (restore previous version), ARCHIVED→CURRENT (swap)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Upgrade Process** (3 atomic steps):
|
|
290
|
+
1. Archive all CURRENT profiles → ARCHIVED
|
|
291
|
+
2. Promote all PENDING profiles → CURRENT
|
|
292
|
+
3. Delete all old ARCHIVED profiles
|
|
293
|
+
|
|
294
|
+
**Downgrade Process** (3 atomic steps):
|
|
295
|
+
1. Mark all CURRENT profiles → ARCHIVE_IN_PROGRESS (temporary)
|
|
296
|
+
2. Restore all ARCHIVED profiles → CURRENT
|
|
297
|
+
3. Complete archiving: ARCHIVE_IN_PROGRESS → ARCHIVED
|
|
298
|
+
|
|
299
|
+
**Use Cases**:
|
|
300
|
+
- Test prompt changes without affecting production profiles
|
|
301
|
+
- Review AI-generated updates before deployment
|
|
302
|
+
- Rollback to previous profile version if needed
|
|
303
|
+
|
|
304
|
+
### Playbook Extraction
|
|
305
|
+
|
|
306
|
+
**Directory**: `services/playbook/`
|
|
307
|
+
|
|
308
|
+
**Detailed Documentation**: See [`services/playbook/README.md`](services/playbook/README.md) for detailed component documentation.
|
|
309
|
+
|
|
310
|
+
Key files:
|
|
311
|
+
- `playbook_generation_service.py`: Service orchestrator
|
|
312
|
+
- `playbook_extractor.py`: Extractor that extracts user playbooks
|
|
313
|
+
- `playbook_aggregator.py`: Aggregates similar user playbooks (with cluster-level change detection to skip unchanged clusters)
|
|
314
|
+
- `playbook_consolidator.py`: Reconciles newly extracted playbooks against existing DB playbooks using LLM
|
|
315
|
+
|
|
316
|
+
**Flow**:
|
|
317
|
+
- Interactions → PlaybookExtractor (extraction-only) → PlaybookConsolidator (consolidates new vs existing DB playbooks) → UserPlaybook (with optional `blocking_issue`) → Storage
|
|
318
|
+
- UserPlaybook (manual trigger) → PlaybookAggregator → cluster fingerprint comparison → LLM only for changed clusters → AgentPlaybook (with optional `blocking_issue`) → Storage
|
|
319
|
+
|
|
320
|
+
**Tool Analysis**: PlaybookExtractor reads `tool_can_use` from root `Config` and passes it to prompts for tool usage analysis and blocking issue detection.
|
|
321
|
+
|
|
322
|
+
**Rerun Behavior**: Groups interactions by `user_id` for per-user playbook extraction (fetches all users, then processes each user's interactions together)
|
|
323
|
+
|
|
324
|
+
**Playbook Aggregation with Cluster Change Detection** (`playbook_aggregator.py`):
|
|
325
|
+
|
|
326
|
+
Aggregation clusters user playbooks by embedding similarity, then calls LLM per cluster to produce aggregated agent playbooks. Cluster-level change detection avoids redundant LLM calls on subsequent runs:
|
|
327
|
+
|
|
328
|
+
1. Cluster all user playbooks (agglomerative for <50, HDBSCAN for >=50)
|
|
329
|
+
2. Compute fingerprint per cluster (SHA-256 of sorted `raw_feedback_id`s, 16 hex chars)
|
|
330
|
+
3. Compare against stored fingerprints from previous run (via `OperationStateManager.get_cluster_fingerprints`)
|
|
331
|
+
4. Only call LLM for changed/new clusters; carry forward existing agent playbooks for unchanged clusters
|
|
332
|
+
5. Archive old agent playbooks only for changed/disappeared clusters (via `archive_feedbacks_by_ids`)
|
|
333
|
+
6. Store new fingerprints with feedback_id mapping (via `OperationStateManager.update_cluster_fingerprints`)
|
|
334
|
+
|
|
335
|
+
| Scenario | Behavior |
|
|
336
|
+
|---|---|
|
|
337
|
+
| First run (no stored fingerprints) | All clusters treated as changed, full LLM run |
|
|
338
|
+
| `rerun=True` | Bypasses fingerprint comparison, full archive/regenerate |
|
|
339
|
+
| No changes | Logs skip message, updates bookmark, returns early |
|
|
340
|
+
| Error during save | Restores only selectively archived playbooks |
|
|
341
|
+
|
|
342
|
+
**Change Log Tracking**: After each aggregation run, a `PlaybookAggregationChangeLog` is saved with before/after snapshots of added, removed, and updated playbooks. Viewable via `GET /api/playbook_aggregation_change_logs`. Change log saving is best-effort (failures are logged but don't block aggregation).
|
|
343
|
+
|
|
344
|
+
**Generation Modes** (detailed comparison):
|
|
345
|
+
|
|
346
|
+
| Aspect | Regular | Rerun | Manual Regular |
|
|
347
|
+
|--------|---------|-------|----------------|
|
|
348
|
+
| **Trigger** | Auto (on publish) | Manual (API) | Manual (API) |
|
|
349
|
+
| **Stride Check** | Yes (skips if below threshold) | No (always runs) | No (always runs) |
|
|
350
|
+
| **Interactions** | Window-sized (last k) | Window-sized (last k) | Window-sized (last k) |
|
|
351
|
+
| **Time Range Filter** | No | Yes (optional start/end) | No |
|
|
352
|
+
| **Pre-processing** | None | Deletes existing PENDING user playbooks | None |
|
|
353
|
+
| **Output Status** | CURRENT | PENDING | CURRENT |
|
|
354
|
+
| **Scope** | Single user | Batch (all matching users, with progress) | Batch (all/single user, with progress) |
|
|
355
|
+
| **Use Case** | Normal operation | Test prompt changes | Force regeneration |
|
|
356
|
+
|
|
357
|
+
**Note**: All modes use `window_size` (per-extractor override or global). The key difference is that Regular checks stride_size before running, while Rerun/Manual always run. When no window is configured, rerun/manual falls back to `k=1000`.
|
|
358
|
+
|
|
359
|
+
**Constructor Flags** (`PlaybookGenerationService`):
|
|
360
|
+
- `allow_manual_trigger`: Include `manual_trigger=True` extractors (default: False)
|
|
361
|
+
- `output_pending_status`: Set output user playbooks to PENDING status (default: False)
|
|
362
|
+
|
|
363
|
+
**User Playbook Versioning Workflow**:
|
|
364
|
+
|
|
365
|
+
Similar to profiles, user playbooks support versioning:
|
|
366
|
+
|
|
367
|
+
1. **CURRENT** (status=None): Active user playbooks
|
|
368
|
+
2. **PENDING** (status="pending"): Newly generated user playbooks awaiting review
|
|
369
|
+
3. **ARCHIVED** (status="archived"): Previous version of user playbooks
|
|
370
|
+
|
|
371
|
+
**Rerun Workflow**:
|
|
372
|
+
```
|
|
373
|
+
1. Rerun Playbook Generation → Creates PENDING user playbooks
|
|
374
|
+
2. Review PENDING → Compare new vs current
|
|
375
|
+
3. Upgrade → CURRENT→ARCHIVED, PENDING→CURRENT, delete old ARCHIVED
|
|
376
|
+
4. OR Downgrade → Swap ARCHIVED↔CURRENT
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Agent Success Evaluation
|
|
380
|
+
|
|
381
|
+
**Directory**: `services/agent_success_evaluation/`
|
|
382
|
+
|
|
383
|
+
Key files:
|
|
384
|
+
- `agent_success_evaluation_service.py`: Service orchestrator (tracks run outcome flags: `last_run_result_count`, `has_run_failures()`)
|
|
385
|
+
- `agent_success_evaluator.py`: Evaluates success at session level (all interactions as one group)
|
|
386
|
+
- `agent_success_evaluation_constants.py`: Output schema (`AgentSuccessEvaluationOutput`)
|
|
387
|
+
- `agent_success_evaluation_utils.py`: Message construction utilities
|
|
388
|
+
- `delayed_group_evaluator.py`: `GroupEvaluationScheduler` singleton - min-heap priority queue with daemon thread, defers evaluation until 10 min after last request in session
|
|
389
|
+
- `group_evaluation_runner.py`: `run_group_evaluation()` - fetches all requests/interactions for a session, builds `RequestInteractionDataModel` list, runs evaluation
|
|
390
|
+
|
|
391
|
+
**Flow**: Interactions → (deferred 10 min) → GroupEvaluationScheduler → run_group_evaluation → AgentSuccessEvaluator → AgentSuccessEvaluationResult → Storage
|
|
392
|
+
|
|
393
|
+
**Session-Level Evaluation**: Evaluator treats all `request_interaction_data_models` in a session as a single conversation. Sampling rate checked once per session (not per-request). Result keyed by `session_id` (not `request_id`).
|
|
394
|
+
|
|
395
|
+
**Tool Context**: Reads `tool_can_use` from root `Config` level (shared with playbook extraction).
|
|
396
|
+
|
|
397
|
+
**Shadow Comparison**: Session-level shadow comparison was retracted in F1 because multi-turn shadow content suffers from trajectory contamination (turn 2+ user messages react to the regular response, not the shadow). The `regular_vs_shadow` field on `AgentSuccessEvaluationResult` is preserved as a nullable historical column but is always `None` on newly produced rows. Per-turn shadow comparison lives in a dedicated `services/shadow_comparison/` judge that writes its verdicts to a separate table — see the F1 spec.
|
|
398
|
+
|
|
399
|
+
### Reflection and Async Extraction
|
|
400
|
+
|
|
401
|
+
**Directories**: `services/reflection/`, `services/extraction/`
|
|
402
|
+
|
|
403
|
+
Key files:
|
|
404
|
+
- `reflection/reflection_service.py`: Post-horizon reflection orchestration for synthesizing longer-range memory artifacts
|
|
405
|
+
- `reflection/reflection_extractor.py`: LLM extractor used by the reflection service
|
|
406
|
+
- `extraction/resumable_agent.py`: Resumable extraction agent runtime
|
|
407
|
+
- `extraction/resume_scheduler.py` and `extraction/resume_worker.py`: Background scheduling/worker loop for paused extraction runs
|
|
408
|
+
- `extraction/tools.py` and `extraction/prior_answer_search.py`: Tool surface for async extraction agents
|
|
409
|
+
- `extraction/agent_run_records.py`: Persistence helpers for extraction-agent run state
|
|
410
|
+
|
|
411
|
+
**Pattern**: Synchronous profile/playbook/evaluation services still follow `BaseGenerationService`; async extraction uses resumable agent-run records and worker scheduling so long-running or tool-mediated extraction can continue outside the request path.
|
|
412
|
+
|
|
413
|
+
### Shadow Comparison and Evaluation Overview
|
|
414
|
+
|
|
415
|
+
**Directories**: `services/shadow_comparison/`, `services/evaluation_overview/`
|
|
416
|
+
|
|
417
|
+
Key files:
|
|
418
|
+
- `shadow_comparison/judge.py`: Per-turn regular-vs-shadow judge that writes shadow verdicts through storage
|
|
419
|
+
- `shadow_comparison/outcome.py`: Verdict outcome model helpers
|
|
420
|
+
- `evaluation_overview/service.py`: Aggregates evaluation-page metrics
|
|
421
|
+
- `evaluation_overview/hero_state.py`, `distribution.py`, `group_aggregation.py`, `rule_attribution.py`, `shadow_aggregation.py`: Focused aggregation helpers
|
|
422
|
+
|
|
423
|
+
**Pattern**: Session-level agent success evaluation remains in `agent_success_evaluation/`; dashboard-facing rollups and per-turn shadow verdict analysis live in these companion directories.
|
|
424
|
+
|
|
425
|
+
### Playbook Optimizer and Braintrust
|
|
426
|
+
|
|
427
|
+
**Directories**: `services/playbook_optimizer/`, `services/braintrust/`
|
|
428
|
+
|
|
429
|
+
Key files:
|
|
430
|
+
- `playbook_optimizer/optimizer.py`: Scenario-based playbook optimization loop
|
|
431
|
+
- `playbook_optimizer/scheduler.py` and `rollout.py`: Scheduling and rollout helpers
|
|
432
|
+
- `playbook_optimizer/judge.py`, `models.py`, `scenario_resolver.py`: Evaluation and scenario resolution models
|
|
433
|
+
- `playbook_optimizer/assistant_webhook.py`: Assistant-facing webhook entry point for optimizer runs
|
|
434
|
+
- `braintrust/service.py`, `braintrust/client.py`, `_cron.py`: Braintrust export/sync support
|
|
435
|
+
|
|
436
|
+
**Pattern**: These are evaluation/optimization integrations around the core playbook pipeline. Keep production extraction changes in `services/playbook/`; use optimizer/Braintrust modules for experiments, rollouts, and external eval sync.
|
|
437
|
+
|
|
438
|
+
### Query Reformulator
|
|
439
|
+
|
|
440
|
+
**File**: `services/pre_retrieval/_query_reformulator.py` - `QueryReformulator`
|
|
441
|
+
|
|
442
|
+
Reformulates user search queries into clean, normalized natural language for improved search recall. Resolves conversation context, expands abbreviations, fixes grammar. Enabled per-request via `enable_reformulation` parameter.
|
|
443
|
+
|
|
444
|
+
- Uses `pre_retrieval_model_name` from `llm_model_setting.json` (fast, cheap model)
|
|
445
|
+
- Supports conversation-aware reformulation via `conversation_history` (list of `ConversationTurn`)
|
|
446
|
+
- Plain-text LLM output with robust extraction/validation
|
|
447
|
+
- Falls back to original query on any failure
|
|
448
|
+
- Prompt: `prompt_bank/query_reformulation/`
|
|
449
|
+
|
|
450
|
+
### Unified Search Service
|
|
451
|
+
|
|
452
|
+
**File**: `services/unified_search_service.py` - `run_unified_search()`
|
|
453
|
+
|
|
454
|
+
Searches across all entity types (profiles, agent_playbooks, user_playbooks) in parallel via a two-phase approach:
|
|
455
|
+
|
|
456
|
+
- **Phase A**: Query rewriting + embedding generation (parallel via ThreadPoolExecutor)
|
|
457
|
+
- **Phase B**: Entity searches across all types (parallel via ThreadPoolExecutor, 3 workers)
|
|
458
|
+
|
|
459
|
+
Pre-computed embeddings passed to storage methods via `query_embedding` parameter to avoid redundant embedding calls.
|
|
460
|
+
|
|
461
|
+
### Storage
|
|
462
|
+
|
|
463
|
+
**Directory**: `services/storage/`
|
|
464
|
+
|
|
465
|
+
| File | Purpose |
|
|
466
|
+
|------|---------|
|
|
467
|
+
| `storage_base/` | BaseStorage interface split by domain (`_profiles.py`, `_playbook.py`, `_requests.py`, `_operations.py`, `_agent_run.py`, `_shadow_verdicts.py`, `_stall_state.py`, `_share_links.py`) |
|
|
468
|
+
| `sqlite_storage/` | SQLite-backed implementation split across the same domains |
|
|
469
|
+
| `retention.py`, `retention_mixin.py` | Data retention and cleanup helpers |
|
|
470
|
+
| `constants.py`, `error.py` | Storage constants and shared errors |
|
|
471
|
+
|
|
472
|
+
**Pattern**: **NEVER import storage implementations directly** - Always use `request_context.storage`
|
|
473
|
+
|
|
474
|
+
**Key Methods**:
|
|
475
|
+
- CRUD: profiles, interactions, playbooks, results, requests, playbook aggregation change logs
|
|
476
|
+
- `get_sessions(offset, top_k, session_id)` → `dict[str, list[RequestInteractionDataModel]]` (groups by session_id, supports offset/limit pagination)
|
|
477
|
+
- `get_rerun_user_ids(user_id, start_time, end_time, source, agent_version)` → `list[str]` - Get distinct user IDs matching filters for rerun workflows (pushes filtering to storage layer)
|
|
478
|
+
- `get_feedbacks(status_filter, feedback_status_filter)` - Filter by playbook status and approval status
|
|
479
|
+
- `save_feedbacks()` → returns `list[Feedback]` with `feedback_id` populated (callers can ignore return)
|
|
480
|
+
- Selective playbook operations (used by cluster change detection):
|
|
481
|
+
- `archive_feedbacks_by_ids(feedback_ids)` - Archive specific agent playbooks by ID (skips APPROVED)
|
|
482
|
+
- `restore_archived_feedbacks_by_ids(feedback_ids)` - Restore archived agent playbooks by ID
|
|
483
|
+
- `delete_feedbacks_by_ids(feedback_ids)` - Delete agent playbooks by ID
|
|
484
|
+
- `delete_raw_feedbacks_by_ids(raw_feedback_ids)` - Delete user playbooks by ID
|
|
485
|
+
- Vector search via LiteLLMClient embeddings
|
|
486
|
+
- Operation state: `get_operation_state()`, `upsert_operation_state()`, `get_operation_state_with_new_request_interaction()`, `try_acquire_in_progress_lock()`
|
|
487
|
+
- All operation state interactions are managed through `OperationStateManager` (in `operation_state_utils.py`)
|
|
488
|
+
- Profile status: `Status` enum (CURRENT=None, PENDING, ARCHIVED)
|
|
489
|
+
|
|
490
|
+
### Configurator
|
|
491
|
+
|
|
492
|
+
**Directory**: `services/configurator/`
|
|
493
|
+
|
|
494
|
+
Key files:
|
|
495
|
+
- `configurator.py`: DefaultConfigurator - loads YAML config, creates storage
|
|
496
|
+
- `local_file_config_storage.py`: Local file-based config storage
|
|
497
|
+
**Config Storage Priority** (in `DefaultConfigurator`):
|
|
498
|
+
1. **Local** - If `base_dir` is explicitly provided (testing)
|
|
499
|
+
2. **Local File** - Default fallback
|
|
500
|
+
|
|
501
|
+
**Path Handling**: LocalFileConfigStorage automatically converts relative paths to absolute using `os.path.abspath()`
|
|
502
|
+
|
|
503
|
+
Access: `request_context.configurator`
|
|
504
|
+
|
|
505
|
+
## Architecture Patterns
|
|
506
|
+
|
|
507
|
+
### Request Flow
|
|
508
|
+
```
|
|
509
|
+
API Request (api.py)
|
|
510
|
+
-> API Endpoint (api_endpoints/)
|
|
511
|
+
-> get_reflexio() (cache/)
|
|
512
|
+
-> Reflexio (reflexio_lib.py)
|
|
513
|
+
-> GenerationService
|
|
514
|
+
├─> ProfileGenerationService → Storage
|
|
515
|
+
├─> PlaybookGenerationService → Storage
|
|
516
|
+
└─> GroupEvaluationScheduler (deferred 10 min) → run_group_evaluation → Storage
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
```mermaid
|
|
520
|
+
flowchart TB
|
|
521
|
+
subgraph API["API Layer"]
|
|
522
|
+
A[api.py] --> B[api_endpoints/]
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
B --> C[get_reflexio]
|
|
526
|
+
C --> D[Reflexio]
|
|
527
|
+
D --> E[GenerationService]
|
|
528
|
+
|
|
529
|
+
subgraph ProfileService["ProfileGenerationService"]
|
|
530
|
+
E --> F1[ProfileExtractor 1]
|
|
531
|
+
E --> F2[ProfileExtractor N]
|
|
532
|
+
F1 --> PD[ProfileDeduplicator]
|
|
533
|
+
F2 --> PD
|
|
534
|
+
PD --> PU[ProfileUpdater]
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
subgraph PlaybookService["PlaybookGenerationService"]
|
|
538
|
+
E --> G1[PlaybookExtractor 1]
|
|
539
|
+
E --> G2[PlaybookExtractor N]
|
|
540
|
+
G1 --> FD[PlaybookConsolidator]
|
|
541
|
+
G2 --> FD
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
subgraph EvalService["AgentSuccessEvaluationService"]
|
|
545
|
+
E -.->|deferred 10 min| SCH[GroupEvaluationScheduler]
|
|
546
|
+
SCH --> H1[AgentSuccessEvaluator 1]
|
|
547
|
+
SCH --> H2[AgentSuccessEvaluator N]
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
PU --> I[(Storage)]
|
|
551
|
+
FD --> I
|
|
552
|
+
H1 --> I
|
|
553
|
+
H2 --> I
|
|
554
|
+
|
|
555
|
+
subgraph Support["Supporting Components"]
|
|
556
|
+
J[LiteLLMClient]
|
|
557
|
+
K[PromptManager]
|
|
558
|
+
L[Configurator]
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
J -.-> F1
|
|
562
|
+
J -.-> G1
|
|
563
|
+
J -.-> H1
|
|
564
|
+
J -.-> PD
|
|
565
|
+
J -.-> FD
|
|
566
|
+
K -.-> F1
|
|
567
|
+
K -.-> G1
|
|
568
|
+
K -.-> H1
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Service Pattern
|
|
572
|
+
|
|
573
|
+
All services follow BaseGenerationService:
|
|
574
|
+
1. Load extractor configs from YAML
|
|
575
|
+
2. Load generation service config from request (runtime parameters)
|
|
576
|
+
3. Filter extractors by source, `allow_manual_trigger`, and extractor names (via `extractor_config_utils`)
|
|
577
|
+
4. Create extractors with both configs
|
|
578
|
+
5. Run extractors in parallel (ThreadPoolExecutor)
|
|
579
|
+
6. Process and save results to storage
|
|
580
|
+
|
|
581
|
+
**Extractor Pattern**: Multiple extractors run in parallel, each handling its own data collection. Each extractor:
|
|
582
|
+
- Receives **ExtractorConfig** (from YAML): Static configuration like prompts and settings
|
|
583
|
+
- Receives **GenerationServiceConfig** (from request): Runtime parameters like user_id, source
|
|
584
|
+
- **Collects its own interactions** using `extractor_interaction_utils.py`:
|
|
585
|
+
- Gets per-extractor window_size/stride_size parameters (override or global fallback)
|
|
586
|
+
- Applies source filtering based on `request_sources_enabled`
|
|
587
|
+
- Checks stride_size threshold before running
|
|
588
|
+
- Updates per-extractor bookmark state after processing (via `OperationStateManager`)
|
|
589
|
+
|
|
590
|
+
**Per-Extractor Window Overrides**: Each extractor config can override global window settings:
|
|
591
|
+
- `window_size_override`: Override global `window_size` for this extractor
|
|
592
|
+
- `stride_size_override`: Override global `stride_size` for this extractor
|
|
593
|
+
- Each extractor applies its own override or falls back to global values
|
|
594
|
+
|
|
595
|
+
### Key Rules
|
|
596
|
+
|
|
597
|
+
**Reflexio Instances**:
|
|
598
|
+
- **NEVER instantiate `Reflexio()` directly** in API endpoints
|
|
599
|
+
- **ALWAYS use**: `get_reflexio(org_id)` from `cache/reflexio_cache.py`
|
|
600
|
+
- Cache invalidated automatically on config changes
|
|
601
|
+
|
|
602
|
+
**Storage**:
|
|
603
|
+
- **NEVER import storage implementations directly**
|
|
604
|
+
- **ALWAYS use**: `request_context.storage` (type: BaseStorage)
|
|
605
|
+
|
|
606
|
+
**LLM**:
|
|
607
|
+
- **NEVER import OpenAIClient/ClaudeClient directly**
|
|
608
|
+
- **ALWAYS use**: `LiteLLMClient` (uses LiteLLM for multi-provider support)
|
|
609
|
+
|
|
610
|
+
**Prompts**:
|
|
611
|
+
- **NEVER hardcode prompts**
|
|
612
|
+
- **ALWAYS use**: `request_context.prompt_manager.render_prompt(prompt_id, variables)`
|
|
613
|
+
- Prompts versioned in `prompt_bank/`
|
|
614
|
+
|
|
615
|
+
## See Also
|
|
616
|
+
|
|
617
|
+
- [Code Map (root README)](../README.md) -- high-level overview of all Reflexio components
|
|
618
|
+
- [API Endpoints README](api_endpoints/README.md) -- RequestContext contract and handler/helper map
|
|
619
|
+
- [Services README](services/README.md) -- per-directory index of the business-logic layer
|
|
620
|
+
- [Prompt Bank README](prompt/prompt_bank/README.md) -- versioned prompt template system
|
|
621
|
+
- [Playbook Service README](services/playbook/README.md) -- playbook extraction, aggregation, and deduplication pipeline
|
|
622
|
+
- [Site Variables README](site_var/README.md) -- global configuration and feature flags
|