Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -11,6 +11,222 @@ app_port: 7860
|
|
| 11 |
|
| 12 |
# FlowGraph
|
| 13 |
|
| 14 |
-
A lightweight workflow orchestration engine for building agent pipelines.
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# FlowGraph
|
| 13 |
|
| 14 |
+
A lightweight, async-first workflow orchestration engine for building agent pipelines in Python.
|
| 15 |
|
| 16 |
+

|
| 17 |
+

|
| 18 |
+

|
| 19 |
+
|
| 20 |
+
A minimal but powerful graph-based workflow engine similar to [LangGraph](https://github.com/langchain-ai/langgraph). Define sequences of steps (nodes), connect them with edges, maintain shared state, and run workflows via REST APIs.
|
| 21 |
+
|
| 22 |
+
**Live Demo:** https://kbsss-flowgraph.hf.space/docs
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## Features
|
| 27 |
+
|
| 28 |
+
| Feature | Description |
|
| 29 |
+
|---------|-------------|
|
| 30 |
+
| Nodes | Python functions that read and modify shared state |
|
| 31 |
+
| Edges | Define which node runs after which |
|
| 32 |
+
| Branching | Conditional routing based on state values |
|
| 33 |
+
| Looping | Run nodes repeatedly until conditions are met |
|
| 34 |
+
| Async | Full async/await support for scalability |
|
| 35 |
+
| WebSocket | Real-time execution streaming |
|
| 36 |
+
| Visualization | Auto-generated Mermaid diagrams |
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## Quick Start
|
| 41 |
+
|
| 42 |
+
### With Docker (Recommended)
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
git clone https://github.com/kbss0000/flowgraph.git
|
| 46 |
+
cd flowgraph
|
| 47 |
+
docker compose up -d
|
| 48 |
+
curl http://localhost:8000/health
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### Without Docker
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
python3 -m venv venv
|
| 55 |
+
source venv/bin/activate
|
| 56 |
+
pip install -r requirements.txt
|
| 57 |
+
python run.py
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
**Access Points:**
|
| 61 |
+
- API: http://localhost:8000
|
| 62 |
+
- Swagger Docs: http://localhost:8000/docs
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## API Reference
|
| 67 |
+
|
| 68 |
+
### Graph Endpoints
|
| 69 |
+
|
| 70 |
+
| Method | Endpoint | Description |
|
| 71 |
+
|--------|----------|-------------|
|
| 72 |
+
| `POST` | `/graph/create` | Create a new workflow graph |
|
| 73 |
+
| `GET` | `/graph/` | List all graphs |
|
| 74 |
+
| `GET` | `/graph/{graph_id}` | Get graph details + Mermaid diagram |
|
| 75 |
+
| `POST` | `/graph/run` | Execute a graph |
|
| 76 |
+
| `GET` | `/graph/state/{run_id}` | Get execution state |
|
| 77 |
+
|
| 78 |
+
### Tool Endpoints
|
| 79 |
+
|
| 80 |
+
| Method | Endpoint | Description |
|
| 81 |
+
|--------|----------|-------------|
|
| 82 |
+
| `GET` | `/tools/` | List all registered tools |
|
| 83 |
+
| `POST` | `/tools/register` | Register a new tool dynamically |
|
| 84 |
+
|
| 85 |
+
### WebSocket
|
| 86 |
+
|
| 87 |
+
| Endpoint | Description |
|
| 88 |
+
|----------|-------------|
|
| 89 |
+
| `/ws/run/{graph_id}` | Execute with real-time streaming |
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## Sample Workflow: Code Review
|
| 94 |
+
|
| 95 |
+
The included demo workflow analyzes Python code quality:
|
| 96 |
+
|
| 97 |
+
```
|
| 98 |
+
Extract Functions -> Check Complexity -> Detect Issues --+--> END (pass)
|
| 99 |
+
|
|
| 100 |
+
+--> Improve -> (loop back)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### Try It
|
| 104 |
+
|
| 105 |
+
```bash
|
| 106 |
+
curl -X POST "https://kbsss-flowgraph.hf.space/graph/run" \
|
| 107 |
+
-H "Content-Type: application/json" \
|
| 108 |
+
-d '{
|
| 109 |
+
"graph_id": "code-review-demo",
|
| 110 |
+
"initial_state": {
|
| 111 |
+
"code": "def hello():\n print(\"world\")",
|
| 112 |
+
"quality_threshold": 6.0
|
| 113 |
+
}
|
| 114 |
+
}'
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
## Architecture
|
| 120 |
+
|
| 121 |
+
```
|
| 122 |
+
flowgraph/
|
| 123 |
+
βββ app/
|
| 124 |
+
β βββ main.py # FastAPI entry point
|
| 125 |
+
β βββ config.py # Configuration
|
| 126 |
+
β βββ api/
|
| 127 |
+
β β βββ schemas.py # Pydantic models
|
| 128 |
+
β β βββ routes/
|
| 129 |
+
β β βββ graph.py # Graph CRUD + execution
|
| 130 |
+
β β βββ tools.py # Tool management
|
| 131 |
+
β β βββ websocket.py # Real-time streaming
|
| 132 |
+
β βββ engine/
|
| 133 |
+
β β βββ state.py # Immutable state management
|
| 134 |
+
β β βββ node.py # Node definitions + decorators
|
| 135 |
+
β β βββ graph.py # Graph structure + validation
|
| 136 |
+
β β βββ executor.py # Async workflow executor
|
| 137 |
+
β βββ tools/
|
| 138 |
+
β β βββ registry.py # Tool registry
|
| 139 |
+
β β βββ builtin.py # Built-in tools
|
| 140 |
+
β βββ workflows/
|
| 141 |
+
β β βββ code_review.py # Demo workflow
|
| 142 |
+
β βββ storage/
|
| 143 |
+
β βββ memory.py # In-memory storage
|
| 144 |
+
βββ tests/ # Test suite
|
| 145 |
+
βββ Dockerfile
|
| 146 |
+
βββ docker-compose.yml
|
| 147 |
+
βββ requirements.txt
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
---
|
| 151 |
+
|
| 152 |
+
## Design Decisions
|
| 153 |
+
|
| 154 |
+
| Decision | Rationale |
|
| 155 |
+
|----------|-----------|
|
| 156 |
+
| Immutable state | Predictable flow, easier debugging, clear state transitions |
|
| 157 |
+
| Async-first | Scalability for long-running or I/O-bound workflows |
|
| 158 |
+
| Tool registry | Decouples node logic from handlers, enables dynamic registration |
|
| 159 |
+
| Named conditions | Clean serialization, human-readable graph definitions |
|
| 160 |
+
| In-memory storage | Simplicity first; easily swappable for Redis/PostgreSQL |
|
| 161 |
+
| Max iterations | Safety guard against infinite loops |
|
| 162 |
+
|
| 163 |
+
---
|
| 164 |
+
|
| 165 |
+
## Testing
|
| 166 |
+
|
| 167 |
+
```bash
|
| 168 |
+
# Run tests in Docker
|
| 169 |
+
docker compose exec workflow-engine pytest tests/ -v
|
| 170 |
+
|
| 171 |
+
# Run locally
|
| 172 |
+
pytest tests/ -v
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
---
|
| 176 |
+
|
| 177 |
+
## What I Would Improve
|
| 178 |
+
|
| 179 |
+
With more time, I would add:
|
| 180 |
+
|
| 181 |
+
1. Persistent Storage - PostgreSQL/Redis for production
|
| 182 |
+
2. Parallel Execution - Run independent nodes concurrently
|
| 183 |
+
3. Checkpointing - Save/restore execution state
|
| 184 |
+
4. Retry Logic - Automatic retry on node failures
|
| 185 |
+
5. Metrics - Prometheus/Grafana integration
|
| 186 |
+
6. Authentication - API key / JWT support
|
| 187 |
+
7. Visual Editor - Web UI for building workflows
|
| 188 |
+
|
| 189 |
+
---
|
| 190 |
+
|
| 191 |
+
## Creating Custom Workflows
|
| 192 |
+
|
| 193 |
+
### 1. Define a Node Handler
|
| 194 |
+
|
| 195 |
+
```python
|
| 196 |
+
from app.tools.registry import register_tool
|
| 197 |
+
|
| 198 |
+
@register_tool("my_processor")
|
| 199 |
+
def my_processor(data: str) -> dict:
|
| 200 |
+
return {"result": data.upper()}
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
### 2. Create via API
|
| 204 |
+
|
| 205 |
+
```json
|
| 206 |
+
POST /graph/create
|
| 207 |
+
{
|
| 208 |
+
"name": "my_workflow",
|
| 209 |
+
"nodes": [
|
| 210 |
+
{"name": "step1", "handler": "my_processor"},
|
| 211 |
+
{"name": "step2", "handler": "another_tool"}
|
| 212 |
+
],
|
| 213 |
+
"edges": {"step1": "step2"},
|
| 214 |
+
"entry_point": "step1"
|
| 215 |
+
}
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
### 3. Run It
|
| 219 |
+
|
| 220 |
+
```json
|
| 221 |
+
POST /graph/run
|
| 222 |
+
{
|
| 223 |
+
"graph_id": "returned_graph_id",
|
| 224 |
+
"initial_state": {"data": "hello"}
|
| 225 |
+
}
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
---
|
| 229 |
+
|
| 230 |
+
## License
|
| 231 |
+
|
| 232 |
+
MIT License - see [LICENSE](LICENSE) for details.
|