Skip to main content

Message-driven workflows with observable flows for emergent AI

Project description

ClearFlow

Coverage Status PyPI PyPI Downloads Python License llms.txt

Message-driven orchestration of AI workflows. Type-safe, immutable, 100% coverage.

Why ClearFlow?

  • Message-driven architecture – Commands trigger actions, Events record facts
  • 100% test coverage – Every path proven to work
  • Type-safe flows – Full static typing with pyright strict mode
  • Deep immutability – All state transformations create new immutable data
  • Minimal dependencies – Only Pydantic for validation and immutability
  • Single completion – Exactly one end message type per flow
  • AI-Ready Documentation – llms.txt for optimal coding assistant integration

How It Works

ClearFlow uses Messages to orchestrate AI workflows:

Command → Node → Event → Node → Event → End
  • Commands request actions: "analyze this portfolio"
  • Events record what happened: "risk assessment completed"
  • Nodes process messages and emit new ones
  • Flows route messages between nodes based on type

Every message knows where it came from (causality tracking), making complex AI workflows debuggable and testable.

Quick Start

pip install clearflow

Note: ClearFlow is in alpha. Pin your version in production (clearflow==0.x.y) as breaking changes may occur in minor releases.

Real-World Examples

Example What It Shows
Chat Message routing between user and AI
Portfolio Analysis Multi-language model coordination with Events
RAG Document processing pipeline with causality tracking

AI Assistant Integration

ClearFlow provides comprehensive documentation in llms.txt format for optimal AI assistant support.

Claude Code Setup

Add ClearFlow documentation to Claude Code with one command:

claude mcp add-json clearflow-docs '{
    "type":"stdio",
    "command":"uvx",
    "args":["--from", "mcpdoc", "mcpdoc", "--urls", "ClearFlow:https://raw.githubusercontent.com/artificial-sapience/clearflow/main/llms.txt"]
}'

For IDEs (Cursor, Windsurf), see the mcpdoc documentation.

ClearFlow vs PocketFlow

Aspect ClearFlow PocketFlow
Architecture Message-driven (Commands/Events) State-based transformations
State Immutable messages with causality tracking Mutable, passed via shared param
Routing Message type-based explicit routes Action-based graph edges
Completion Single end message type Multiple exits allowed
Type safety Full static typing with pyright strict Dynamic (no annotations)

ClearFlow provides message-driven orchestration with immutable causality tracking and type safety. PocketFlow emphasizes brevity and flexibility with minimal overhead.

Development

Install uv

curl -LsSf https://astral.sh/uv/install.sh | sh

Clone and set up development environment

git clone https://github.com/artificial-sapience/clearflow.git
cd clearflow
uv sync --all-extras     # Creates venv and installs deps automatically
./quality-check.sh       # Run all checks

License

MIT

Acknowledgments

Inspired by PocketFlow's Node-Flow-State pattern.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clearflow-0.2.0.tar.gz (86.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clearflow-0.2.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file clearflow-0.2.0.tar.gz.

File metadata

  • Download URL: clearflow-0.2.0.tar.gz
  • Upload date:
  • Size: 86.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clearflow-0.2.0.tar.gz
Algorithm Hash digest
SHA256 73a639f8a282c198a4cc1e964e343c78933018c2e5d56f287655653d8cce300e
MD5 258bf202d24b46488db99be93760e3ba
BLAKE2b-256 a85cac9df328eb85648a721acca7993f14b3049a44912b59a77f8c56fbe52b44

See more details on using hashes here.

Provenance

The following attestation bundles were made for clearflow-0.2.0.tar.gz:

Publisher: release.yml on artificial-sapience/clearflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clearflow-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: clearflow-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clearflow-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46da40ee0040df5cd83dc6a2acdf8dfb2354b6f42c0fca2aacf0adf36ce98388
MD5 ac0faf7bbca8a1e36831e4bda7e4094d
BLAKE2b-256 881703ff5d4f641b95158f171c67a7af6fa2d2603af241c58ca191f54f820d38

See more details on using hashes here.

Provenance

The following attestation bundles were made for clearflow-0.2.0-py3-none-any.whl:

Publisher: release.yml on artificial-sapience/clearflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page