|
|
""" |
|
|
src/states/intelligenceAgentState.py |
|
|
Intelligence Agent State - Competitive Intelligence & Profile Monitoring |
|
|
FIXED: Added custom reducer for domain_insights to prevent InvalidUpdateError |
|
|
""" |
|
|
|
|
|
import operator |
|
|
from typing import Optional, List, Dict, Any, Union |
|
|
from typing_extensions import TypedDict, Annotated |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reduce_domain_insights( |
|
|
existing: List[Dict], new: Union[List[Dict], str] |
|
|
) -> List[Dict]: |
|
|
"""Custom reducer for domain_insights to handle concurrent updates""" |
|
|
if isinstance(new, str) and new == "RESET": |
|
|
return [] |
|
|
current = existing if isinstance(existing, list) else [] |
|
|
if isinstance(new, list): |
|
|
return current + new |
|
|
return current |
|
|
|
|
|
|
|
|
class IntelligenceAgentState(TypedDict, total=False): |
|
|
""" |
|
|
State for Intelligence Agent. |
|
|
Monitors competitors, profiles, product reviews, competitive intelligence. |
|
|
""" |
|
|
|
|
|
|
|
|
generated_tasks: List[Dict[str, Any]] |
|
|
current_task: Optional[Dict[str, Any]] |
|
|
tasks_for_workers: List[Dict[str, Any]] |
|
|
worker: Optional[List[Dict[str, Any]]] |
|
|
|
|
|
|
|
|
worker_results: Annotated[List[Dict[str, Any]], operator.add] |
|
|
latest_worker_results: Annotated[List[Dict[str, Any]], operator.add] |
|
|
|
|
|
|
|
|
last_alerts_hash: Optional[int] |
|
|
change_detected: bool |
|
|
|
|
|
|
|
|
social_media_results: Annotated[List[Dict[str, Any]], operator.add] |
|
|
|
|
|
|
|
|
profile_feeds: Dict[str, List[Dict[str, Any]]] |
|
|
competitor_feeds: Dict[str, List[Dict[str, Any]]] |
|
|
product_review_feeds: Dict[str, List[Dict[str, Any]]] |
|
|
local_intel: List[Dict[str, Any]] |
|
|
global_intel: List[Dict[str, Any]] |
|
|
|
|
|
|
|
|
llm_summary: Optional[str] |
|
|
structured_output: Dict[str, Any] |
|
|
|
|
|
|
|
|
final_feed: str |
|
|
feed_history: Annotated[List[str], operator.add] |
|
|
|
|
|
|
|
|
domain_insights: Annotated[List[Dict[str, Any]], reduce_domain_insights] |
|
|
|
|
|
|
|
|
aggregator_stats: Dict[str, Any] |
|
|
dataset_path: str |
|
|
|