Skip to content

script_analyzer_graph

script_analyzer_graph

compile_script_analyzer_graph

compile_script_analyzer_graph() -> CompiledStateGraph

Compile the LangGraph workflow for script analysis.

Returns:

Type Description
CompiledStateGraph

The compiled graph.

Source code in src/crew_dcs/integrations/agents/script_analyzer/script_analyzer_graph.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def compile_script_analyzer_graph() -> CompiledStateGraph:
    """Compile the LangGraph workflow for script analysis.

    Returns:
        The compiled graph.
    """
    workflow = StateGraph(PythonAnalysisState)

    workflow.add_node("code_analyzer", run_code_analysis)
    workflow.add_node("pattern_matcher", run_pattern_matching)
    workflow.add_node("recommendations", run_recommendations)

    workflow.add_edge(START, "code_analyzer")
    workflow.add_edge("code_analyzer", "pattern_matcher")
    workflow.add_edge("pattern_matcher", "recommendations")
    workflow.add_edge("recommendations", END)

    return workflow.compile()

run_workflow

run_workflow(script: str) -> dict[str, Any]

Run the compiled workflow against a Python script and return output state.

Parameters:

Name Type Description Default
script str

Python source text to analyse.

required

Returns:

Type Description
dict[str, Any]

The final graph state as a plain dict.

Raises:

Type Description
ScriptAnalysisError

If any graph node raises; the original error is chained.

Source code in src/crew_dcs/integrations/agents/script_analyzer/script_analyzer_graph.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def run_workflow(script: str) -> dict[str, Any]:
    """Run the compiled workflow against a Python script and return output state.

    Args:
        script: Python source text to analyse.

    Returns:
        The final graph state as a plain dict.

    Raises:
        ScriptAnalysisError: If any graph node raises; the original error is chained.
    """
    graph = compile_script_analyzer_graph()
    initial: PythonAnalysisState = {"python_script": script}
    try:
        result = graph.invoke(initial)
    except Exception as exc:
        raise ScriptAnalysisError(
            message="Script analyzer graph failed",
            exception=exc,
            function_name="run_workflow",
        ) from exc
    return dict(result)