
    i.                        S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	J
r
  SSKJr   " S S\5      r\ " S	 S
5      5       r/ SQr/ SQr/ SQr/ SQr0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_0 S"S_S#S_S$S_S%S_S&S'_S(S'_S)S'_S*S'_S+S'_S,S'_S-S'_S.S'_S/S'_S0S1_S2S1_S3S1_S4S1_Er\R(                  S5\R*                  S6\R,                  S7\R.                  S8\R0                  S7\R2                  S9\R4                  S90r " S: S;5      r\S<:X  a  SSKr\" 5       r/ S=Qr \!" \RD                  5      S':  a6  S>RG                  \RD                  S'S 5      r$\%" \RM                  \$5      5        g\%" S?5        \  HD  r$\RO                  \$5      r(\RS                  \$5      r*\%" S@\(RV                  SA SB\* SC\$SSD  35        MF     gg)Eud  
GENESIS TASK ROUTER
====================
Classifies incoming tasks and routes them to the optimal executor.

Routing table:
  Simple file/text ops       → Claude Haiku       (cost: ~$0.001)
  Standard implementation    → Claude Sonnet       (cost: ~$0.01)
  Complex reasoning/arch     → Claude Opus         (cost: ~$0.10)
  Bulk parallel execution    → Gemini Swarm        (cost: ~$0.002/task)
  100-agent parallelism      → Kimi K2.5           (cost: minimal)
  Browser automation         → Playwright MCP      (cost: 0)
  Memory read/write          → RLM Bloodstream     (cost: 0)
  Research/intelligence      → Research Scout      (Haiku)

Decision logic:
  1. Check for browser keywords → Playwright MCP
  2. Check for memory keywords → RLM
  3. Estimate complexity score → select model tier
  4. If bulk/parallel → Gemini swarm or Kimi
  5. Otherwise → Claude tier based on complexity

Usage:
    from core.task_router import TaskRouter

    router = TaskRouter()
    executor = router.classify_and_route("implement feature X")
    explanation = router.explain_routing("implement feature X")
    N)	dataclass)Enum)DictListOptionalTuple)Pathc                   0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)ExecutorType'   claude-opusclaude-sonnetclaude-haikugemini-swarmkimi-k2
playwrightrlm N)__name__
__module____qualname____firstlineno__CLAUDE_OPUSCLAUDE_SONNETCLAUDE_HAIKUGEMINI_SWARMKIMI_K2
PLAYWRIGHTRLM_BLOODSTREAM__static_attributes__r       %E:\genesis-system\core\task_router.pyr   r   '   s%    K#M!L!LGJOr!   r   c                   V    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   Sr	\\S'   S	r
g
)RoutingDecision1   executor
confidencecomplexity_scorereasonestimated_cost_usd   parallel_workersr   N)r   r   r   r   r   __annotations__floatintstrr,   r    r   r!   r"   r$   r$   1   s*    Kcr!   r$   )loginclickbrowserr   navigatez	form fillwebsitewebpageportal	dashboardghlztelnyx portal
cloudflarezstripe portalscroll
screenshotdomauthenticatezsign inzopen browserzweb automation)memoryr   bloodstreamrememberrecallzknowledge graphz	kg entityaxiomztitan memoryzsession contextsunaiva)researchfindsearchdiscoverscoutexplorezgather intelinvestigatezwhat iszwho iszanalyze market)swarmparallelbatchz
100 agentskimizfan outmultiplezall domainsbulkmassfleetscale	architect   
orchestratdesignrefactorsecuritycryptographoptimizestrategyzmulti-agentdistributed	implement   buildcreatedevelop	integratepipelinesystemapidatabaseasync
concurrentupdater+   fixaddwritelistshowreadformatrenamewhatwhenwheresimpleg333333?g{Gz?gMbP?g~jth?g        c            	           \ rS rSrSr  SS\S\S\S\4S jjrSS\S\S\4S jjr	  SS\S\S\S\
4S	 jjrSS\S
\S\4S jjrS\S\\   S\4S jrS\\\4   4S jrS\\   S\\\\4      4S jrSrg)
TaskRouterr   aE  
Classifies and routes Genesis tasks to the optimal executor.

Implements RULE 9 (Native-First) and RULE 10 (Capability-First):
- Always checks if a simpler/cheaper executor can do the job
- Prefers browser automation over asking Kinan
- Prefers Gemini swarm for bulk work
- Uses Claude Opus only for genuine reasoning tasks
taskcomplexity_hintforce_parallelreturnc                 >    U R                  XU5      nUR                  $ )z
Main routing method. Returns the optimal ExecutorType.

Args:
    task: Natural language task description
    complexity_hint: "low", "medium", "high", "auto"
    force_parallel: If True, prefer swarm/Kimi for parallelism
)_make_routing_decisionr&   )selfr|   r}   r~   decisions        r"   classify_and_routeTaskRouter.classify_and_route}   s"     ..tnU   r!   c                     U R                  X5      nSUR                  R                   SUR                   SUR                  S SUR
                  S SUR                   SUR                   3$ )	z7Returns human-readable explanation of routing decision.z
Executor: z
Complexity: z/10
Confidence: z.0%z
Est. Cost: $z.4fz

Workers: z	
Reason: )r   r&   valuer(   r'   r*   r,   r)   )r   r|   r}   r   s       r"   explain_routingTaskRouter.explain_routing   s    ..tE**001 2#445 6#..s3 4#66s; < 112 3')	
r!   c           	         UR                  5       nU R                  U[        5      (       a0  [        [        R
                  SSS[        [        R
                     S9$ U R                  U[        5      (       a0  [        [        R                  SSS[        [        R                     S9$ U R                  U[        5      (       d  U(       at  SU;   d  S	U;   d  S
U;   a1  [        [        R                  SSS[        [        R                     SS9$ [        [        R                  SSS[        [        R                     SS9$ U R                  U[        5      (       a6  US:X  a0  [        [        R                  SSS[        [        R                     S9$ U R                  X5      nUS:  a4  [        [        R                  SUSU S3[        [        R                     S9$ US:  a4  [        [        R                   SUSU S3[        [        R                      S9$ [        [        R                  SUSU S3[        [        R                     S9$ )zCore routing logic.gffffff?rV   uF   Browser keywords detected — Playwright MCP handles this autonomously)r&   r'   r(   r)   r*   g?r`   u4   Memory/KG operation — RLM bloodstream handles this100rS   rO   g333333?   u@   Massive parallel scale detected — Kimi K2.5 swarm (100 agents)d   )r&   r'   r(   r)   r*   r,      u8   Bulk/parallel work — Gemini swarm executes in parallel
   lowg?uN   Research/discovery task — Haiku research-scout handles this cost-effectively   zHigh complexity (u*   /10) — Opus required for reasoning depthg)\(?zMedium complexity (u+   /10) — Sonnet handles implementation wellgq=
ףp?zLow complexity (u#   /10) — Haiku is cost-optimal here)lower_matches_anyBROWSER_KEYWORDSr$   r   r   COST_ESTIMATESMEMORY_KEYWORDSr   BULK_KEYWORDSr   r   RESEARCH_KEYWORDSr   _estimate_complexityr   r   )r   r|   r}   r~   
task_lower
complexitys         r"   r   !TaskRouter._make_routing_decision   s7    ZZ\
 Z)9::"%00!"_#1,2I2I#J  Z99"%55!"M#1,2N2N#O  Z77>
"g&;v?S&)11#%&]'5l6J6J'K%(  #%22!"Q#1,2K2K#L!#  Z):;;SX@X"%22!"g#1,2K2K#L  ..tE
?"%11!+*:,6`a#1,2J2J#K  1_"%33!+,ZL8cd#1,2L2L#M  #%22!+)*5XY#1,2K2K#L r!   hintc                   ^	 US:X  a  gUS:X  a  gUS:X  a  gUR                  5       m	Sn[        R                  5        H  u  pEUT	;   d  M  X5-  nM     [        UR	                  5       5      nUS:  a  US-  nOUS	:  a  US
-  n/ SQn[        U	4S jU 5       5      nU[        US5      -  n[        S
[        SU5      5      $ )zU
Score task complexity on 1-10 scale.
Uses keyword signals + length + hint override.
high   r   r`   mediumr   rV   r   2   r+   )firstthenfinallyalsozand thenstepc              3   6   >#    U  H  oT;   d  M
  S v   M     g7f)r+   Nr   ).0sr   s     r"   	<genexpr>2TaskRouter._estimate_complexity.<locals>.<genexpr>  s     GOqJOs   		r   )r   COMPLEXITY_SIGNALSitemslensplitsumminmax)
r   r|   r   scorekeywordpoints
word_countstep_indicators
step_countr   s
            @r"   r   TaskRouter._estimate_complexity   s    
 6>5=8ZZ\
  2779OG*$  :
 &
QJE"_QJE SGOGG
Z##1c"en%%r!   textkeywordsc                 .   ^ [        U4S jU 5       5      $ )z-Check if text contains any keyword from list.c              3   ,   >#    U  H	  oT;   v   M     g 7f)Nr   )r   kwr   s     r"   r   *TaskRouter._matches_any.<locals>.<genexpr>  s     1":s   )any)r   r   r   s    ` r"   r   TaskRouter._matches_any  s    1111r!   c                     SSSSSSSS.$ )	z;Returns the full routing table for documentation/debugging.r   r   r   r   r   r   r   )zbrowser/portal/loginzmemory/kg/rlm/bloodstreamzbulk/swarm/parallel/batchz100-agent/fleet/kimizcomplexity 7-10zcomplexity 4-6zcomplexity 1-3r   )r   s    r"   get_routing_tableTaskRouter.get_routing_table  s#     %1).)7$-,-,
 	
r!   tasksc                 R    U Vs/ s H  o"U R                  U5      4PM     sn$ s  snf )z9Route a batch of tasks, returning (task, executor) pairs.)r   )r   r   r|   s      r"   batch_routeTaskRouter.batch_route$  s(    BGH%$t..t45%HHHs   $r   N)autoF)r   )r   r   r   r   __doc__r0   boolr   r   r   r$   r   r/   r   r   r   r   r   r   r   r    r   r!   r"   rz   rz   r   s     &$	!! ! 	!
 
!"

C 

# 

3 

  &$	VV V 	V
 
Vp &  &C  &S  &D2 2S	 2d 2

4S> 

Ic ItE#|:K4L/M Ir!   rz   __main__)z-Login to GHL and activate the review workflowz0Remember this axiom: always check existing firstz:Implement the voice agent registration endpoint in FastAPIzDDesign the multi-agent orchestration architecture for ReceptionistAIz4Batch scrape 500 tradie businesses from Yellow Pagesz!What is the capital of Australia?z4Research Telnyx pricing for Australian phone numbers u+   Genesis Task Router — Routing Table Demo
z  [20sz] (complexity=z) <   ),r   redataclassesr   enumr   typingr   r   r   r   pathlibr	   r   r$   r   r   r   r   r   r   r   r   r   r   r   r   r   rz   r   sysrouter
test_tasksr   argvjoinr|   printr   r   r&   r   r   r   r   r!   r"   <module>r      s  < 
 !  . . 4     
 
 !%-q2<a  !! &0 5? 1	 $Q	  Q !)! .7   $,Q 16q  A  ,Q a  !! &-a 28 A q #A (0  B!  !  $R!  *22! * duu%S  #tI tIn z\FJ 388}qxx%f$$T*+<=D006H//5ECs+>%49+NO ) r!   