Efficient lightweight Python Agent Workflow Engine
高效轻é‡çš„ Python 智能体工ä½
8000
œæµå¼•擎
Support Sync/Async Nodes, Branching Loops, Visual Flowcharts | Build Agent Task Flows Fast
支æŒåŒæ¥/异æ¥èŠ‚ç‚¹ã€åˆ†æ”¯å¾ªçޝã€å¯è§†åŒ–æµç¨‹å›¾ | 快速æå»º Agent 任务æµ
💻 Code → 📊 Log → 🎨 Flowchart - Complete development agent workflow visualization in minutes
💻 代ç → 📊 日志 → 🎨 æµç¨‹å›¾ - 快速开å‘夿‚的智能体工作æµå¯è§†åŒ–
from typing import TypedDict
from agnflow import Node, Flow
# Define state
class State(TypedDict):
message: str
# Define nodes
start = Node(
name="start",
exec=lambda s: ("process", {"message": "Hello"}) # Instantiate Node, specify exec
)
class ProcessNode(Node): # Inherit Node, override exec
def exec(state: State):
# Route to end node and update message state
return "end", {"message": s["message"] + " World"}
process = ProcessNode() # No name specified, automatically gets variable name "process"
end = Node(exec=print) # Print state
# Create workflow
flow = Flow(start >> process >> end)
# Run workflow
state: State = {"message": ""}
flow.run(state) # Output: {'message': 'Hello World'}
🤖 Static Web Chat Room Experience - Visit Backend Interface http://127.0.0.1:8000/en
from agnflow.chatbot.server import Server
server = Server()
server.run()
🧠Structured reasoning with step-by-step thinking process | 💻 Intelligent code generation with detailed explanations
flow.render_mermaid(saved_file="flow.png") # Directly generate image
Complex Connection | Supervisor Agent | Runtime Management |
---|---|---|
n1 >> [n2 >> n3, n3 >> n4] >> n5 |
s1[n1, n2, n3] >> n4 |
flow += new_node flow -= old_node |
# Add/Remove nodes at runtime
flow += new_node
flow -= old_node
# Symmetric connect/disconnect syntax
a >> b >> c # Connect nodes
a - b - c # Symmetrically disconnect
- Sync/Async Mixed:
n = Node(exec=sync_func, aexec=async_func)
- Branch/Loop:
n1 >> [n2, n3] >> n1
(n1 points to n2 and n3, n2 and n3 point to n1) - Swarm Agent:
s = Swarm(); s[n1, n2, n3] >> n4
(n1, n2, n3 are fully connected inside s) - Parallel Flow:
pf = ParallelFlow(); pf[n1, n2, n3]
(Execute child nodes concurrently) - Human Review: CLI/API intervention with
hitl
pip install agnflow
from typing import TypedDict
from agnflow import Node, Flow
# 定义状æ€
class State(TypedDict):
message: str
# 定义节点
start = Node(
name="start",
exec=lambda s: ("process", {"message": "Hello"}) # 实例化 Node,指定 exec
)
class ProcessNode(Node): # 继承 Node,é‡å†™ exec
def exec(state: State):
# 路由到 end 节点,并且更新 message 状æ€ï¼Œ
return "end", {"message": s["message"] + " World"}
process = ProcessNode() # 没有指定 name 属性,自动获å–实例化å˜é‡å "process"
end = Node(exec=print) # æ‰“å° state
# 创建工作æµ
flow = Flow(start >> process >> end)
# è¿è¡Œå·¥ä½œæµ
state: State = {"message": ""}
flow.run(state) # 输出: {'message': 'Hello World'}
2. 🤖 陿€ Web èŠå¤©å®¤ä½“验 - 访问åŽç«¯æŽ¥å£ http://127.0.0.1:8000/zh
from agnflow.chatbot.server import Server
server = Server()
server.run()
flow.render_mermaid(saved_file="flow.png") # 直接生æˆå›¾ç‰‡
夿‚连接 | 监ç£è€…智能体 | è¿è¡ŒæœŸç®¡ç† |
---|---|---|
n1 >> [n2 >> n3, n3 >> n4] >> n5 |
s1[n1, n2, n3] >> n4 |
flow += new_node flow -= old_node |
# è¿è¡ŒæœŸå¢žåˆ 节点
flow += new_node
flow -= old_node
# 对称的连接/æ–å¼€è¯æ³•
a >> b >> c # 建立连接
a - b - c # 对称æ–å¼€
- åŒæ¥/å¼‚æ¥æ··åˆ:
n = Node(exec=sync_func, aexec=async_func)
- 分支/循环:
n1 >> [n2, n3] >> n1
(n1 æŒ‡å‘ n2 å’Œ n3,n2 å’Œ n3 æŒ‡å‘ n1) - 蜂群智能体:
s = Swarm(); s[n1, n2, n3] >> n4
(s 内部的 n1,n2,n3 全互连) - 并行工作æµ:
pf = ParallelFlow(); pf[n1, n2, n3]
ï¼ˆå¹¶å‘æ‰§è¡Œå¤šä¸ªå节点) - äººå·¥å®¡æ ¸: CLI/API 介入
hitl
pip install agnflow
访问我们的文档获å–:
Visit our documentation for:
- 详细教程和示例 Detailed tutorials and examples
- API å‚考 API reference
- 最佳实践 Best practices
- 高级用法 Advanced usage
我们欢迎贡献ï¼è¯·éšæ—¶æäº¤ Pull Request。
We welcome contributions! Please feel free to submit a Pull Request.
本项目基于 MIT 许å¯è¯ - 查看 LICENSE 文件了解详情。
This project is licensed under the MIT License - see the LICENSE file for details.
💬 åŠ å…¥æˆ‘ä»¬çš„ç¤¾åŒºï¼Œå‚ä¸Žè®¨è®ºã€æé—®å’Œå作ï¼
个人微信 直接è”系维护者 |
å¼€å‘者社群 åŠ å…¥æˆ‘ä»¬çš„å¼€å‘者社区 |
æ¬¢è¿Žéšæ—¶è”系我们,æå‡ºé—®é¢˜ã€å»ºè®®æˆ–åªæ˜¯æ‰“个招呼ï¼ðŸ‘‹
å¦‚æžœè¿™ä¸ªé¡¹ç›®å¯¹ä½ æœ‰å¸®åŠ©ï¼Œè¯·ç»™å®ƒä¸€ä¸ª âï¸ Starï¼
Your support is my motivation to keep improving 💪
ä½ çš„æ”¯æŒæ˜¯æˆ‘æŒç»æ”¹è¿›çš„动力 💪