Spaces:
Sleeping
Sleeping
File size: 3,622 Bytes
89d813f | 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | """
AgentState โ LangGraph ็ถๆๆบ็ๅ
จๅฑ็ถๆๅฎไน
่ฎพ่ฎก่ฏดๆ๏ผ
- thread_id ๅทฒ้ข็๏ผๅฝๅๅ็ซฏๆฏๆฌก่ฏทๆฑไผ ๅ
ฅๅ
จ้ conversation_path๏ผๆ ็ถๆๆจกๅผ๏ผ
- ๆชๆฅ่ฅ่ฆๆฅๅ
ฅ PostgreSQL/Redis Checkpointer๏ผๅช้ๅจ graph.compile() ๅค
ไผ ๅ
ฅ checkpointer ๅๆฐ๏ผๅ็ซฏๅ FastAPI ่ทฏ็ฑๆ ้ๆนๅจ
"""
from __future__ import annotations
from typing import Literal, NotRequired
from typing_extensions import TypedDict
class DocumentSection(TypedDict):
id: str
title: str
level: int
content: str
class LearningDocument(TypedDict):
type: Literal["file", "topic"]
title: str
content: str
structure: list[DocumentSection]
class BubbleNode(TypedDict):
id: str
parentId: str | None
userQuery: str
aiResponse: str
anchorText: NotRequired[str | None]
resolved: NotRequired[bool]
class QuoteRef(TypedDict):
nodeId: str
text: str
class AnchorLocation(TypedDict):
anchor_text: str | None
section_id: str | None
confidence: float
class DecomposedQuestion(TypedDict):
id: str
query: str
anchor: str | None
reason: str | None
order: int
selected: bool
mountNodeId: NotRequired[str | None]
mountStrategy: NotRequired[str | None]
mountReason: NotRequired[str | None]
section_id: NotRequired[str | None]
class TreeMountDecision(TypedDict):
questionId: str
parentId: str
strategy: str
reason: str
class AgentState(TypedDict):
# โโ ่ฏทๆฑๆ ่ฏ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# ้ข็ thread_id๏ผ็ฎๅๅ็ซฏๆฏๆฌกไผ ๅ
จ้ context๏ผๆ ็ถๆ๏ผ
# ๆชๆฅๆฅๅ
ฅ Checkpointer ๆถ๏ผๅ็ซฏๅฏ็จๆญค ID ๆฃ็ดขๅๅฒ๏ผๅ็ซฏๆ ้ไปปไฝๆนๅจ
thread_id: str # UUID๏ผ็ฑๅ็ซฏ๏ผsessionId๏ผ็ๆๅนถ้ๆฏๆฌก่ฏทๆฑไผ ๅ
ฅ
# โโ ่พๅ
ฅ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
document: LearningDocument
conversation_path: list[BubbleNode] # ไปๆ นๅฐๅฝๅ่็น็ๆฐๆณก่ทฏๅพ๏ผๅซๅฎๆด aiResponse๏ผ
user_query: str
anchor_text: str | None
language: Literal["en", "zh"]
mode: Literal["overview", "followup", "decompose", "tree_writer"]
skip_decomposition: bool
# โโ ไธญ้ดไบง็ฉ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
decomposed_questions: list[DecomposedQuestion] # decomposer ไบงๅบ
needs_decomposition: bool # router ๅคๆญ๏ผๆฏๅฆ้่ฆๆ่งฃ
located_anchor: NotRequired[AnchorLocation] # anchor_locator ไบงๅบ (ๅๆ้ฎๆจกๅผ)
tree_nodes: NotRequired[list[BubbleNode]]
tree_questions: NotRequired[list[DecomposedQuestion]]
current_node_id: NotRequired[str | None]
quote_refs: NotRequired[list[QuoteRef]]
tree_mounts: NotRequired[list[TreeMountDecision]]
# โโ ๆ็ป่พๅบ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
answer: str # ๅฎๆดๅ็ญๆๆฌ๏ผๆตๅผๅบๆฏไธ็ฑ tutor node ๆๅปบ๏ผ
is_off_topic: bool
off_topic_hint: str | None
document_summary: NotRequired[str | None]
|