Spaces:
Paused
Paused
| """GovOn LangGraph state schema. | |
| v4 ์ํคํ ์ฒ: ReAct ๊ธฐ๋ฐ messages-only state. | |
| ๋ชจ๋ ๋๊ตฌ ๊ฒฐ๊ณผ๋ messages(ToolMessage)๋ก ๋์ ๋์ ๋๋ฉฐ, | |
| ํน์ ๋๊ตฌ๋ช ์ state์ ํ๋์ฝ๋ฉํ์ง ์๋๋ค. | |
| """ | |
| from __future__ import annotations | |
| from enum import Enum | |
| from typing import Annotated, Any, Dict, List, Optional, Sequence | |
| from langchain_core.messages import AnyMessage | |
| from langgraph.graph.message import add_messages | |
| from typing_extensions import TypedDict | |
| def _merge_dicts(a: Dict[str, Any], b: Dict[str, Any]) -> Dict[str, Any]: | |
| """๋ dict๋ฅผ ๋ณํฉํ๋ reducer. | |
| LangGraph state์์ ์ฌ๋ฌ ๋ ธ๋๊ฐ ๋์ผ ํค์ ๊ฐ์ ๋ฐํํ ๋ ์ฌ์ฉํ๋ค. | |
| ํํ dict(b)์ ๊ฐ์ด ์ ํ dict(a)๋ฅผ ๋ฎ์ด์ด๋ค. | |
| """ | |
| merged = dict(a) if a else {} | |
| if b: | |
| merged.update(b) | |
| return merged | |
| def _append_list(a: List, b: List) -> List: | |
| """๋ฆฌ์คํธ๋ฅผ appendํ๋ reducer (๊ธฐ์กด ํญ๋ชฉ ๋ณด์กด).""" | |
| return (a or []) + (b or []) | |
| class ApprovalStatus(str, Enum): | |
| """human-in-the-loop ์น์ธ ์ํ.""" | |
| PENDING = "pending" | |
| APPROVED = "approved" | |
| REJECTED = "rejected" | |
| class GovOnGraphState(TypedDict, total=False): | |
| """GovOn LangGraph graph state (v4). | |
| ReAct ๋ฃจํ ๊ธฐ๋ฐ. ๋ชจ๋ ๋๊ตฌ ํธ์ถ/๊ฒฐ๊ณผ๋ messages์ ๋์ ๋๋ค. | |
| """ | |
| # --- ์ธ์ ์๋ณ --- | |
| session_id: str | |
| request_id: str | |
| # --- LangGraph ํต์ฌ: messages ๋์ (ReAct ๋ฃจํ) --- | |
| messages: Annotated[Sequence[AnyMessage], add_messages] | |
| # --- Human-in-the-Loop --- | |
| approval_status: str # ApprovalStatus.value | |
| # --- ์ต์ข ์ถ๋ ฅ --- | |
| final_text: str | |
| evidence_items: List[Dict[str, Any]] | |
| # --- ์๋ฌ/์ธํฐ๋ฝํธ --- | |
| error: Optional[str] | |
| interrupt_reason: Optional[str] | |
| # --- ๋ ์ดํด์ ๊ณ์ธก --- | |
| node_latencies: Annotated[Dict[str, float], _merge_dicts] | |
| # --- ReAct v3 ๋ฃจํ ์ ์ด --- | |
| iteration_count: int # ํ์ฌ agentโtools ์ฌ์ดํด ํ์ (0๋ถํฐ ์์) | |
| max_iterations: int # ์ต๋ ํ์ฉ iteration ์ (๊ธฐ๋ณธ 10) | |
| # --- v3 ๋๊ตฌ ํธ์ถ ๋ฉํ๋ฐ์ดํฐ --- | |
| tool_call_history: Annotated[List[Dict[str, Any]], _append_list] | |
| # ๊ฐ ํญ๋ชฉ: {"iteration": int, "tool": str, "latency_ms": float, "success": bool, "timestamp": str} | |
| # --- v3 ์ํ๋ ๊ธฐ๋ฐ ์น์ธ ์ ์ฑ --- | |
| pending_tool_calls: List[Dict[str, Any]] # agent๊ฐ ์์ฑํ tool_calls (OpenAI format) | |