Refactor Pipeline Agent Lite: Intent, Discovery & Enrichment

Merged Phạm Thúc Trường Sơn requested to merge refactor/enrichment-agent into main

Branch 1 — refactor/intent-agent

Tích hợp intent schema

  • Thêm intent_schema.py với JSON schema chuẩn hóa cho trích xuất intent (country, industry, keywords, khoảng nhân sự, tín hiệu funding/tech/security, v.v.).
  • Refactor intent_node, lite_intent_node, discovery_node, và các lite discovery/enrichment node để dùng parsing và sanitization theo schema.
  • Payload intent giờ có cấu trúc và nhất quán xuyên suốt pipeline.

Lite enrichment — xử lý field động

  • Các field enrichment được sinh động từ input schema.
  • EnrichedCompanyData hỗ trợ field bổ sung với validation giá trị thiếu tốt hơn.
  • Sinh query bao gồm các field còn thiếu trong search terms.

Branch 2 — refactor/discovery-agent

Cải thiện discovery query

  • Tăng số lượng discovery query từ 3–5 lên 4–8, với giới hạn động theo input người dùng.
  • Thêm phân phối search tool và giới hạn kết quả theo từng query.
  • Thêm supplemental discovery queries và hỗ trợ discovery nhiều lượt.
  • Cải thiện messaging event search tool để log nhất quán khi gọi tool.

Refactor discovery node — kiến trúc subagent

  • Đơn giản hóa lite_discovery_node thành coordinator ủy quyền cho các discovery subagent.
  • Package mới discovery_subagents/:
    • orchestrator.py — điều phối discovery pipeline
    • query_expansion_subagent.py — mở rộng và bổ sung query
    • search_engine_subagent.py, job_board_subagent.py, news_sources_subagent.py — nguồn tìm kiếm chuyên biệt
    • extraction_subagent.py — trích xuất company profile từ search context
    • search_runner.py — chạy và gộp kết quả subagent

Gated field handling & intent resolution

  • Field tìm kiếm enrichment được gate theo tín hiệu ICP (ví dụ fundingStage, estimatedValue chỉ khi intent yêu cầu).
  • Thêm revenue intent resolution để điều chỉnh query liên quan doanh thu động.

Xử lý địa lý

  • Intent parsing chuẩn hóa tên quốc gia từ ngôn ngữ địa phương (ví dụ Nhật Bản → Japan, Việt Nam → Vietnam).
  • Phát hiện đề cập địa lý chỉ kích hoạt khi người dùng nói rõ — không gán mặc định sai.
  • Sinh query có search terms bản địa hóa cho Nhật Bản và locale khác.
  • Discovery orchestrator dùng locale_native_search_language() cho query ngôn ngữ bản địa.

Branch 3 — refactor/enrichment-agent

Bing-only cho tìm website chính thức

  • Thay DuckDuckGo bằng Bing khi tìm website công ty chính thức.
  • Thêm fetch_bing_search_hits() và _bing_result_rows() để parse kết quả Bing có cấu trúc.
  • Cập nhật fast_search.py với tooling ưu tiên Bing và logic phân phối engine.
  • Enrichment và discovery node dùng Bing độc quyền cho website discovery.

Tích hợp LinkedIn profile

  • Thay contact query builder theo role bằng hàm LinkedIn contact query tổng quát.
  • Thêm utility gắn LinkedIn profile cho contact từ search context.
  • Enrichment gắn LinkedIn URL cho contact khi có.

Sửa routing backfill

  • Sửa backfill kích hoạt sớm trong discovery khi chưa có qualified companies.
  • Thêm route_after_discovery() và route_after_enrichment() trong lead_backfill.py để quyết định routing rõ ràng hơn.
  • Thêm counter discovery_round trong state để theo dõi số lần discovery.
  • Routing đúng: discovery → enrichment → lead scoring → rank output; backfill chỉ khi số lead có nội dung dung vẫn dưới limit.

Merge request reports