mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2026-06-18 07:19:35 +00:00
Platform Services Layer (10 modules) — برج التحكم بالنمو - event_bus: 27 typed events (whatsapp/email/calendar/lead/payment/review/social/partner/sheet/crm/action) - identity_resolution: cross-channel merge (phone+email+CRM+social) with confidence scoring - channel_registry: 11 channels (WA, Gmail, Calendar, Moyasar, LinkedIn, X, IG, GBP, Sheets, CRM, Forms) with capabilities/risk/PDPL notes - action_policy: 9 rules (block_cold_whatsapp, block_payment_no_confirm, block_secrets, external_send_needs_approval, calendar_insert_needs_approval, social_dm_needs_explicit, unknown_source_review, high_value_deal_review, draft_only_safe) - tool_gateway: single execution chokepoint, env-flag-gated live actions (default OFF) - unified_inbox: 8 card types, ≤3 buttons enforced, Arabic - action_ledger: requested→approved→executed audit trail - proof_ledger: leads/meetings/drafts/sends/payments/revenue/risks_blocked/time_saved per channel - service_catalog: 12 sellable services - router api/routers/platform_services.py — 13 endpoints under /api/v1/platform/ Intelligence Layer (10 modules) — الشبكة العصبية للنمو - growth_brain: per-customer Brain + is_ready_for_autopilot() (≥30 signals + ≥40% accept) - command_feed: 9 daily card types (opportunity/revenue_leak/partner_suggestion/meeting_prep/review_response/competitive_move/customer_reactivation/ai_visibility_alert/action_required) - action_graph: 10 typed edges (signal→action→outcome) with what_works_summary - mission_engine: 7 missions, KILL FEATURE first_10_opportunities (10 فرص في 10 دقائق) - decision_memory: learns from accept/skip/edit/block, returns preferences (channels, tones, sectors, rejected actions, accept_rate) - trust_score: composite 0-100 (source+opt_in+channel+content+freq+approval) → safe/needs_review/blocked - revenue_dna: best_channel/segment/angle + common_objection + avg_cycle_days - opportunity_simulator: 9 Saudi sectors, expected_replies/meetings/deals/pipeline_sar + risk_score - competitive_moves: 8 move types with Arabic recommended_action_ar - board_brief: weekly Founder Shadow Board (3 decisions + 3 opportunities + 3 risks + relationship + experiment + metric) - router api/routers/intelligence_layer.py — 12 endpoints under /api/v1/intelligence/ Tests - tests/unit/test_platform_services.py — 31 tests covering catalog/channels/events/policy/gateway/identity/inbox/ledger/proof - tests/unit/test_intelligence_layer.py — 29 tests covering brain/feed/graph/missions/memory/trust/dna/simulator/competitive/brief - 60/60 new tests pass; full suite 587 passed, 2 skipped Docs - docs/PLATFORM_SERVICES_STRATEGY.md (Arabic) - docs/INTELLIGENCE_LAYER_STRATEGY.md (Arabic) - docs/DEALIX_100_PERCENT_LAUNCH_PLAN.md — added §32 Platform Services + §33 Intelligence Layer Safety - No live send by default (all WA/Gmail/Calendar/Moyasar guarded by env flags, all OFF) - All external actions go through Tool Gateway → Action Policy → draft/approval_required - No secrets allowed in payloads (block_secrets policy) - PDPL-aware: cold WhatsApp without consent is hard-blocked - Existing 477+ tests untouched (no breaking changes) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
"""Decision Memory — learn the operator's preferences from Accept/Skip/Edit."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections import Counter
|
|
from dataclasses import dataclass, field
|
|
from typing import Any
|
|
|
|
|
|
VALID_DECISIONS: tuple[str, ...] = ("accept", "skip", "edit", "block")
|
|
|
|
|
|
@dataclass
|
|
class DecisionMemory:
|
|
"""Per-customer Accept/Skip/Edit history and aggregates."""
|
|
|
|
customer_id: str
|
|
raw_decisions: list[dict[str, Any]] = field(default_factory=list)
|
|
|
|
def append(
|
|
self,
|
|
*,
|
|
decision: str,
|
|
action_type: str,
|
|
channel: str,
|
|
sector: str | None = None,
|
|
tone: str | None = None,
|
|
objection_id: str | None = None,
|
|
) -> None:
|
|
if decision not in VALID_DECISIONS:
|
|
raise ValueError(f"unknown decision: {decision}")
|
|
self.raw_decisions.append({
|
|
"decision": decision,
|
|
"action_type": action_type,
|
|
"channel": channel,
|
|
"sector": sector,
|
|
"tone": tone,
|
|
"objection_id": objection_id,
|
|
})
|
|
|
|
def preferences(self) -> dict[str, Any]:
|
|
if not self.raw_decisions:
|
|
return {
|
|
"samples": 0,
|
|
"preferred_channels": [],
|
|
"preferred_tones": [],
|
|
"preferred_sectors": [],
|
|
"rejected_action_types": [],
|
|
"accept_rate": 0.0,
|
|
}
|
|
ch_counter: Counter[str] = Counter()
|
|
tone_counter: Counter[str] = Counter()
|
|
sector_counter: Counter[str] = Counter()
|
|
rejected: Counter[str] = Counter()
|
|
accepts = 0
|
|
for d in self.raw_decisions:
|
|
if d["decision"] == "accept":
|
|
accepts += 1
|
|
ch_counter[d.get("channel", "")] += 1
|
|
if d.get("tone"):
|
|
tone_counter[d["tone"]] += 1
|
|
if d.get("sector"):
|
|
sector_counter[d["sector"]] += 1
|
|
elif d["decision"] in ("skip", "block"):
|
|
rejected[d.get("action_type", "")] += 1
|
|
return {
|
|
"samples": len(self.raw_decisions),
|
|
"preferred_channels": [c for c, _ in ch_counter.most_common(3)],
|
|
"preferred_tones": [t for t, _ in tone_counter.most_common(2)],
|
|
"preferred_sectors": [s for s, _ in sector_counter.most_common(3)],
|
|
"rejected_action_types": [a for a, _ in rejected.most_common(3) if a],
|
|
"accept_rate": round(accepts / len(self.raw_decisions), 4),
|
|
}
|
|
|
|
|
|
def learn_from_decision(
|
|
*,
|
|
memory: DecisionMemory,
|
|
decision: str,
|
|
action_type: str,
|
|
channel: str,
|
|
sector: str | None = None,
|
|
tone: str | None = None,
|
|
objection_id: str | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Record a decision + return updated preferences."""
|
|
memory.append(
|
|
decision=decision, action_type=action_type, channel=channel,
|
|
sector=sector, tone=tone, objection_id=objection_id,
|
|
)
|
|
return {
|
|
"customer_id": memory.customer_id,
|
|
"added": True,
|
|
"preferences": memory.preferences(),
|
|
}
|