File size: 1,681 Bytes
0c591a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Workflow execution wrapper with LangSmith tracing.
"""

from langsmith import traceable

from src.workflow.graph import app


@traceable(
    name="Run - Self-Correcting SWOT Analysis",
    tags=["cyclic", "quality-control", "demo"],
    metadata={"purpose": "iterative_improvement"}
)
def run_self_correcting_workflow(
    company_name: str = "Tesla",
    ticker: str = "",
    strategy_focus: str = "Cost Leadership",
    workflow_id: str = None,
    progress_store: dict = None
):
    """
    Execute the complete self-correcting SWOT analysis workflow.

    Args:
        company_name: Name of the company to analyze
        ticker: Stock ticker symbol
        strategy_focus: Strategic focus for analysis
        workflow_id: Optional workflow ID for progress tracking
        progress_store: Optional dict for storing progress updates

    Returns:
        Final workflow state with analysis results
    """
    # Initialize state with default values
    initial_state = {
        "company_name": company_name,
        "ticker": ticker or company_name,
        "strategy_focus": strategy_focus,
        "raw_data": None,
        "draft_report": None,
        "critique": None,
        "revision_count": 0,
        "messages": [],
        "score": 0,
        "data_source": "live",
        "provider_used": None,
        "sources_failed": [],
        "workflow_id": workflow_id,
        "progress_store": progress_store,
        "error": None
    }

    # Execute the workflow
    output = app.invoke(initial_state, config={
        "configurable": {
            "workflow_id": workflow_id,
            "progress_store": progress_store
        }
    })

    return output