HarborFlow: Declarative graph orchestration atop LangGraph
Project description
HarborFlow
基于 LangGraph v1.0 的轻量语法糖层,让“写图编排”退化为“写普通 Python 类与函数”。
为什么选择 HarborFlow
- 代码即图:使用
@graph声明类、@node声明方法,即可自动编译成可运行的状态图。 - 返回即路由:节点统一返回
Route(goto=..., update=...),直接决定下一步与状态更新。 - 与 LangGraph 100% 兼容:编译后返回原生
CompiledStateGraph(或轻量包装),可直接invoke/stream/checkpoint。 - 最小侵入与清晰心智模型:不重造底层运行时,只在 API 表面做减法,减少样板与心智负担。
安装
pip install harborflow
快速开始
以下示例展示如何用 HarborFlow 声明一张图并运行:
from typing_extensions import TypedDict
from harborflow import graph, node, Route, END
class State(TypedDict):
messages: list[tuple[str, str]]
@graph(state=State, start="agent", finish=END, name="SimpleChat")
class SimpleChat:
@node
def agent(self, state: State) -> Route:
last = state["messages"][-1][1] if state["messages"] else "none"
reply = f"echo: {last}"
return {"messages": [("assistant", reply)]}
@node
def done(self, state: State) -> Route:
return Route(goto=END, update={})
if __name__ == "__main__":
app = SimpleChat().compile()
result = app.invoke({"messages": [("user", "hello")]} )
print(result)
动态路由示例(返回即路由)
from harborflow import Route, END
from typing import Literal
def agent(state: dict) -> Route[Literal["tool", END]]:
need_tool = state.get("need_tool", False)
if need_tool:
return Route(goto="tool", update={"messages": [("assistant", "using tool...")]})
return Route(goto=END, update={"messages": [("assistant", "bye")]})
核心抽象
graph:类级图声明装饰器,提供state、start、finish、name等配置,编译后返回 LangGraphCompiledStateGraph。node:方法级节点声明装饰器,节点函数应接收state并返回Route或dict(顺序更新)。Route:动态路由+状态更新的统一返回对象,语义等价于 LangGraphCommand(goto, update)。END:LangGraph 的结束哨兵常量,表示流程结束。
设计原则(摘自架构与蓝图)
- 统一“返回即路由”心智模型:读节点函数的
return即可读懂流程如何前进。 - 编译期尽可能多做事:自动推断节点类型(顺序/动态),为顺序节点生成静态边;动态节点不生成静态边,避免与
goto混用。 - 保持 LangGraph 能力透明:
invoke/stream/ainvoke/checkpoint与 Studio/观测生态无缝对接。 - v1.0 边界:不内建 Guard/错误处理 DSL/复杂调度,只做极薄封装,保持可演进空间。
API 速览
@graph(state, start, finish=END, name=...)@node(name=None)Route(goto: str|END, update: Mapping|Any)compile() -> CompiledStateGraph- 运行:
app.invoke(initial_state)/app.stream(...)/app.ainvoke(...)
版本与发布
- 目标对齐 LangGraph
>= 1.0.0。 - 使用 GitHub Actions + PyPI Trusted Publishing 自动发布。
- 版本语义:在功能稳定前以
0.x迭代,小版本发布修复与小增强。
贡献指南
- 欢迎通过 Issue / PR 参与,建议基于 Docstring(L3)与测试协作,保持实现与契约一致。
- 重要行为变更请记录到
specs/DEVELOPMENT_DIARY.md(若启用)。
许可证
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file harborflow-0.1.2.tar.gz.
File metadata
- Download URL: harborflow-0.1.2.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4569cd414707634f4495e15356c62032ab5d3837eaf3e199ab5cce6a5a75d8e1
|
|
| MD5 |
953f847bc85de014ee18ef92a724a288
|
|
| BLAKE2b-256 |
c51a06a50094cdebad5c7b54784b2c5954188c0d42efd61270c8c97e745ff011
|
Provenance
The following attestation bundles were made for harborflow-0.1.2.tar.gz:
Publisher:
release.yml on ailijian/harbor-flow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
harborflow-0.1.2.tar.gz -
Subject digest:
4569cd414707634f4495e15356c62032ab5d3837eaf3e199ab5cce6a5a75d8e1 - Sigstore transparency entry: 718485472
- Sigstore integration time:
-
Permalink:
ailijian/harbor-flow@019dc4efb4c72225a688ed25f24d80b7e19b28c7 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/ailijian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@019dc4efb4c72225a688ed25f24d80b7e19b28c7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file harborflow-0.1.2-py3-none-any.whl.
File metadata
- Download URL: harborflow-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9eb6e604090db06f8bde244446ee89b84214fe6b9a8b3b446ccb9fcb7995b9a2
|
|
| MD5 |
b7c9ff05d76d7afee036910dffa6cf81
|
|
| BLAKE2b-256 |
4fd117fff2e1be7adf30f1f1e9d0b768435c54d25a7d0039f96d1a06df878f3f
|
Provenance
The following attestation bundles were made for harborflow-0.1.2-py3-none-any.whl:
Publisher:
release.yml on ailijian/harbor-flow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
harborflow-0.1.2-py3-none-any.whl -
Subject digest:
9eb6e604090db06f8bde244446ee89b84214fe6b9a8b3b446ccb9fcb7995b9a2 - Sigstore transparency entry: 718485483
- Sigstore integration time:
-
Permalink:
ailijian/harbor-flow@019dc4efb4c72225a688ed25f24d80b7e19b28c7 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/ailijian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@019dc4efb4c72225a688ed25f24d80b7e19b28c7 -
Trigger Event:
push
-
Statement type: