Concepts
Bridgic has two core concepts:
- Worker: the basic execution unit in Bridgic.
- Automa: an entity that manages and orchestrates a group of workers. An Automa itself is also a Worker, which enables the nesting of Automa instances within each other.
Worker¶
A worker is the basic execution unit in the Bridgic framework, representing a specific task node.
A worker typically corresponds to a function (which can be synchronous or asynchronous) that performs an independent business logic or processing step. Workers are automatically linked through dependencies to form a complete workflow. The design of Workers makes task decomposition, reuse, and composition simple and flexible, serving as the core foundation for implementing automated processing and complex business orchestration.
There are two ways to define worker:
- Use the
@workerdecorator to decorate member methods (regular or asynchronous) of aGraphAutomaclass, thereby registering them as Workers. - Inherit from the
Workerbase class and implement itsrunorarunmethod.
GraphAutoma¶
GraphAutoma is an implementation of Automa based on Dynamic Directed Graph (abbreviated as DDG). It is the core class in Bridgic. It is not just a simple task scheduler, but a highly abstracted workflow engine that helps developers organize, manage, and run complex asynchronous or synchronous task flows in a declarative manner. Compared to traditional flow control or manual orchestration, GraphAutoma offers the following significant advantages:
-
Declarative Dependency Modeling
With the@workerdecorator, developers can define each node (worker) and its dependencies as if building blocks, without writing tedious scheduling logic. Each worker can be a synchronous or asynchronous function, and GraphAutoma will automatically recognize dependencies and construct the complete task graph. -
Call-based Branch Management
In addition to automatic scheduling based on dependencies, GraphAutoma also supports "active jump" or "call-based branching" control via theferry_tomethod. Developers can callferry_to(worker_key, *args, **kwargs)inside any worker to directly switch the control flow to the specified worker and pass parameters. This mechanism is similar to "goto" or "event-driven jump", but operates at the granularity of complete workers, while still maintaining asynchronous safety and context consistency. This feature is suitable for complex scenarios requiring dynamic branching, making it easy for developers to create logic orchestration programs that depend on runtime conditions. The call toferry_tois not constrained by dependencies; the target worker will be scheduled for asynchronous execution in the next dynamic step, greatly enhancing the flexibility and controllability of the workflow. -
Automatic Driving and Scheduling
Once dependencies are defined, GraphAutoma will automatically drive the execution of each worker according to the dependency topology. As long as dependencies are satisfied, workers will be automatically scheduled, eliminating the need for developers to manually manage execution order or state transitions, thus greatly reducing error rates and maintenance costs. -
Asynchronous and Concurrent Support
GraphAutoma natively supports asynchronous workers, fully leveraging Python's async features for efficient concurrent execution. For I/O-intensive tasks, it can also be combined with thread pools to achieve true parallel processing and improve overall throughput. -
Human Interaction and Event Mechanism
In complex business scenarios, some nodes may need to wait for manual input or external events. GraphAutoma has a built-in human interaction mechanism, supporting task pausing and resuming after receiving user feedback. At the same time, it integrates Bridgic's event system, enabling real-time communication between workers and the application layer, greatly enhancing the system's interactivity and flexibility. -
Serialization and Persistence
GraphAutoma supports complete serialization and deserialization, allowing the current workflow state to be persisted to disk or a database, enabling advanced features such as checkpointing and fault recovery. This is especially important for long-running or highly reliable business processes. -
Dynamic Topology Changes
Supports dynamically adding or removing workers at runtime, flexibly adapting to changes and expansion needs in business processes. There is no need to restart or refactor the entire workflow, greatly improving system maintainability and scalability. -
Layerizable and Editable
GraphAutoma supports deep customization through inheritance and secondary development. Developers can flexibly add new worker nodes based on existing GraphAutoma subclasses to extend their behavior and functionality, enabling personalized customization of business processes. By inheriting, you can reuse existing dependencies and scheduling logic, and then stack new business nodes on top, quickly building more complex automated workflows. This layered and editable design allows GraphAutoma to be continuously expanded and evolved like Lego blocks, greatly enhancing the system's maintainability and evolutionary capability. -
Nestable and Reusable
GraphAutoma is not just a top-level workflow engine; it can itself act as a "super worker" and be nested within another, larger GraphAutoma. Each GraphAutoma instance can be scheduled, passed parameters, and reused just like a regular worker, enabling recursive composition and hierarchical management of workflows. This nesting mechanism allows developers to use the composition pattern to orchestrate even larger and more complex business processes.
In summary, GraphAutoma enables developers to quickly build robust, flexible, interactive, and persistent complex workflow systems with minimal mental overhead, making it a powerful cornerstone for modern automation and intelligent application development.