grantforge-api / backend /agents /supervisor.py
GrantForge Bot
Deploy to Hugging Face
afd56bc
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"}