Skip to content

Architecture C++ Engine

Devrajsinh Gohil edited this page Aug 30, 2026 · 1 revision

C++ Engine Internals

The core execution engine is implemented in Phase1/python_adapter/agentmesh_pybind.cpp.


Core Data Structures

FastNode

Represents an immutable node definition in the compiled DAG:

struct FastNode {
    std::string id;
    PyObject* callable{nullptr};
    PyObject* router{nullptr};
    std::vector<int> staticSuccessorIndices;
    int inDegree{0};
};

WaveItem

Represents a scheduled unit of execution:

struct WaveItem {
    int nodeIndex{-1};
    PyObject* customArg{nullptr}; // Non-null for Send() dynamic map-reduce
};

Execution Loop Mechanics

py::dict run(py::dict initialState, int maxLoops = 100) {
    PyObject* stateObj = initialState.ptr();
    std::vector<WaveItem> currentWave = { WaveItem{.nodeIndex = entryIndex_, .customArg = nullptr} };

    int loopCount = 0;
    while (!currentWave.empty() && loopCount < maxLoops) {
        loopCount++;

        // 1. Execute wave items concurrently
        std::vector<std::pair<int, PyObject*>> waveResults;
        executeWave(currentWave, stateObj, waveResults);

        // 2. State Reduction & Command Routing Extraction
        std::vector<WaveItem> nextWave;
        for (auto& [nodeIdx, resultObj] : waveResults) {
            // Apply updates to stateObj via reducers...
        }

        // 3. Resolve downstream transitions (Routers & Barrier Joins)
        // ...
        currentWave = nextWave;
    }
    return initialState;
}
```\n

Clone this wiki locally