prebuilt.tldr2.state¶
State schema for the News Research Agent.
This module defines the state schema that flows through the agent’s workflow, tracking all necessary data for news research operations.
The state schema extends MessagesState to support conversation history while adding specific fields for news research functionality.
Example
>>> from news_research.state import NewsResearchState
>>> state = NewsResearchState(
... research_topic="AI in healthcare",
... max_sources=10
... )
Note
All computed fields use proper Pydantic v2 patterns with safe property access to avoid initialization errors.
Classes¶
State schema for news research workflow. |
Module Contents¶
- class prebuilt.tldr2.state.NewsResearchState(messages=None, **data)¶
Bases:
haive.core.schema.prebuilt.messages.messages_state.MessagesState
State schema for news research workflow.
This state tracks all data flowing through the news research agent, including search parameters, articles, analysis results, and final reports.
The state extends MessagesState to maintain conversation history while adding specific fields for research operations.
- research_topic¶
Main topic being researched
- search_queries¶
List of queries generated for searching
- current_search_params¶
Current NewsAPI parameters
- past_searches¶
History of all search parameters used
- max_sources¶
Maximum number of sources to check
- max_articles_per_search¶
Maximum articles per search query
- articles_metadata¶
Raw article metadata from NewsAPI
- articles_content¶
Articles with extracted full text
- selected_articles¶
Articles chosen for summarization
- article_summaries¶
Final summarized articles
- search_decision¶
Current decision about search continuation
- analysis¶
Analysis results from all articles
- report¶
Final research report
- errors¶
List of any errors encountered
- Computed Properties:
total_articles_found: Total number of articles discovered total_articles_processed: Articles with extracted content total_sources_checked: Number of unique sources examined has_sufficient_data: Whether enough data for analysis average_relevance: Average relevance score of articles search_iterations: Number of search iterations performed is_complete: Whether the research is complete
Example
>>> state = NewsResearchState( ... research_topic="Impact of AI on healthcare", ... max_sources=15 ... ) >>> state.add_search_query("AI healthcare innovation") >>> print(state.total_articles_found)
Initialize with optional messages parameter for compatibility.
- class Config¶
Pydantic configuration.
- add_article_content(article)¶
Add article with extracted content.
- Parameters:
article (haive.prebuilt.tldr2.models.ArticleContent) – ArticleContent object to add
- Return type:
None
- add_article_metadata(article)¶
Add article metadata if not already processed.
- Parameters:
article (haive.prebuilt.tldr2.models.ArticleMetadata) – ArticleMetadata object to add
- Return type:
None
Note
Checks URL uniqueness to avoid duplicates
- add_error(error_type, message, details=None)¶
Record an error that occurred during processing.
- add_search_query(query)¶
Add a search query to the list.
- Parameters:
query (str) – Search query string to add
- Return type:
None
Example
>>> state.add_search_query("AI healthcare benefits")
- get_search_summary()¶
Get summary statistics of the search process.
- Returns:
Dictionary with search statistics
- Return type:
Dict[str, Any]
Example
>>> summary = state.get_search_summary() >>> print(f"Found {summary['total_articles']} articles")
- get_unprocessed_metadata()¶
Get article metadata that hasn’t been processed yet.
- Returns:
List of ArticleMetadata objects without corresponding content
- Return type:
List[haive.prebuilt.tldr2.models.ArticleMetadata]
- record_search(params)¶
Record search parameters in history.
- Parameters:
params (haive.prebuilt.tldr2.models.NewsApiParams) – NewsApiParams used for the search
- Return type:
None
- property average_relevance: float¶
Calculate average relevance score of summarized articles.
- Return type: