Spaces:
Sleeping
Sleeping
Download state.py from howcloudy/latentlearn-agent: direct link, hf CLI and curl.
- Browser
- Download file 3.62 kB
-
https://huggingface.co/spaces/howcloudy/latentlearn-agent/resolve/main/state.py
- Command line
-
hf download hf://spaces/howcloudy/latentlearn-agent/state.py
-
curl -L -o state.py https://huggingface.co/spaces/howcloudy/latentlearn-agent/resolve/main/state.py
3.62 kB
| """ | |
| 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] | |