File size: 2,503 Bytes
afd56bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
from schemas import AgentState, SupervisorDecision
from core.llm_router import get_llm


def supervisor_node(state: AgentState):
    """
    Supervisor (Router) z 2026 r. zintegrowany z Blackboard.
    Kieruje wiadomo艣ci lub wywo艂uje wykonanie kolejnego zdefiniowanego kroku w task_plan.
    """
    if not state.messages:
        return {"current_agent": "planner"}

    # Check if there is an active plan in blackboard to execute
    if state.task_plan and len(state.task_plan) > 0:
        next_task = state.task_plan[0].lower()
        if "profil" in next_task:
            return {"current_agent": "profiler"}
        elif "dopasowa" in next_task or "match" in next_task:
            return {"current_agent": "matcher"}
        # Logika oparta na planie b臋dzie o wiele bardziej rozbudowana w produkcji.

    last_msg = (
        state.messages[-1].get("content", "")
        if isinstance(state.messages[-1], dict)
        else getattr(state.messages[-1], "content", "")
    )

    prompt = f"""
    Jeste艣 supervisorem (dyrektorem) systemu 'GrantForge AI'.
    Mamy nast臋puj膮ce dzia艂y (agent贸w):
    - planner: planowanie dzia艂a艅
    - profiler: zbieranie danych firmy z KRS/chatu
    - researcher: eksploracja dotacji
    - matcher: dopasowanie znanych dotacji
    - verifier: sprawdzanie formalne
    - wizard: pisanie wniosku, wymy艣lanie tre艣ci
    - risk_scoring: punktowanie szans i ryzyk wniosku
    - document_gap_analyzer: analiza brak贸w dokumentu
    - compliance_guardian: sprawdzanie RODO
    - end: koniec procesu, oddanie g艂osu klientowi
    
    Na podstawie ostatniej wiadomo艣ci opisz kr贸tko pow贸d (reason) i wska偶 jednoznaczn膮 warto艣膰 next_agent z listy powy偶ej.
    Wiadomo艣膰 z systemu klienta: {last_msg}
    """

    try:
        llm = get_llm(task_type="standard", structured_output_schema=SupervisorDecision)
        decision = llm.invoke(prompt)

        valid_agents = [
            "planner",
            "profiler",
            "researcher",
            "matcher",
            "verifier",
            "wizard",
            "risk_scoring",
            "document_gap_analyzer",
            "compliance_guardian",
            "end",
        ]
        if decision.next_agent in valid_agents:
            # W przysz艂o艣ci reason mo偶na wykorzysta膰 do logowania logiki routing-u
            return {"current_agent": decision.next_agent}
    except Exception as e:
        print(f"B艂膮d supervisora LLM: {str(e)}")

    return {"current_agent": "end"}