Skip to content

common/types.hpp

Shared data types for the GNUS NEO SWARM engine.

Namespaces

Name
sgns
sgns::neoswarm

Classes

Name
struct sgns::neoswarm::Task
struct sgns::neoswarm::InferenceResponse
struct sgns::neoswarm::RouteDecision
struct sgns::neoswarm::PromptFeatures
struct sgns::neoswarm::NodeOutput
struct sgns::neoswarm::NodeReputation
struct sgns::neoswarm::KnowledgeFact
struct sgns::neoswarm::CognitiveAsset
struct sgns::neoswarm::ELMContext
struct sgns::neoswarm::ChainStep
struct sgns::neoswarm::ExecutionChain
struct sgns::neoswarm::MemoryContext

Types

Name
enum class uint8_t ExecutionMode
enum class uint8_t RouteTarget
enum class uint8_t ELMRole
enum class uint8_t MemoryObjectType
enum class uint8_t TrustClass { UNVERIFIED = 0, VERIFIED = 1, PREMIUM = 2, REPLICA = 3}
Trust classification for memory objects (GAML v1 — per D-01, D-09)

Types Documentation

enum ExecutionMode

Enumerator Value Description
SingleNode 0 Mode 1 — Core LLM only, fast.
Specialist 1 Mode 2 — Core + Grammar/Math, sequential.
Swarm 2 Mode 3 — Multiple nodes, weighted consensus.
ElmAssisted 3 Mode 2 (doc 07 §9.2) — ELM-assisted sequential chain (Phase 7+)

enum RouteTarget

Enumerator Value Description
CoreOnly 0
CorePlusMath 1
CorePlusGrammar 2
CorePlusCode 3 Future.

enum ELMRole

Enumerator Value Description
Planner 0 Analyses task, determines execution plan.
PrimaryDraft 1 Core draft generation (shared backbone)
Verifier 2 Reviews outputs for correctness.
Arbiter 3 Resolves conflicts between outputs.
Refiner 4 Polishes formatting, style, grammar.
Grounding 5 Fact-checks against knowledge base.
ToolSupport 6 Tool-call formatting (stub in Phase 7)
Math 7 Domain ELM — math.
Code 8 Domain ELM — code.
Science 9 Domain ELM — science (shared-backbone only)

enum MemoryObjectType

Enumerator Value Description
BRIDGE_BLOCK 0 Memory bridge block.
FACT 1 Declarative fact.
POLICY 2 Behavioral policy / rule.
EVENT 3 Temporal event record.
TENANT_OPERATIONAL 4 Tenant operational data.

enum TrustClass

Enumerator Value Description
UNVERIFIED 0 Default privacy stub (D-09)
VERIFIED 1 Fact-validated.
PREMIUM 2 Premium tier.
REPLICA 3 Replicated from remote.

Trust classification for memory objects (GAML v1 — per D-01, D-09)

Source code

#ifndef NEOSWARM_COMMON_TYPES_HPP
#define NEOSWARM_COMMON_TYPES_HPP

#include <chrono>
#include <nlohmann/json.hpp>
#include <optional>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

namespace sgns::neoswarm
{
    // -----------------------------------------------------------------------
    // Execution modes (PTDS §9)
    // -----------------------------------------------------------------------
    enum class ExecutionMode : uint8_t
    {
        SingleNode = 0, 
        Specialist = 1, 
        Swarm = 2,      
        ElmAssisted = 3 
    };

    // -----------------------------------------------------------------------
    // Routing targets (PTDS §6)
    // -----------------------------------------------------------------------
    enum class RouteTarget : uint8_t
    {
        CoreOnly = 0,
        CorePlusMath = 1,
        CorePlusGrammar = 2,
        CorePlusCode = 3 
    };

    // -----------------------------------------------------------------------
    // ELM roles (doc 03 §5.2.1) — Phase 7
    // -----------------------------------------------------------------------
    enum class ELMRole : uint8_t
    {
        Planner = 0,      
        PrimaryDraft = 1, 
        Verifier = 2,     
        Arbiter = 3,      
        Refiner = 4,      
        Grounding = 5,    
        ToolSupport = 6,  
        Math = 7,         
        Code = 8,         
        Science = 9       
    };

    // -----------------------------------------------------------------------
    // Memory object types (GAML v1 — Phase 8 — per D-02)
    // -----------------------------------------------------------------------
    enum class MemoryObjectType : uint8_t
    {
        BRIDGE_BLOCK = 0,       
        FACT = 1,               
        POLICY = 2,             
        EVENT = 3,              
        TENANT_OPERATIONAL = 4  
    };

    enum class TrustClass : uint8_t
    {
        UNVERIFIED = 0,     
        VERIFIED = 1,       
        PREMIUM = 2,        
        REPLICA = 3         
    };

    // -----------------------------------------------------------------------
    // A task coming in from a client
    // -----------------------------------------------------------------------
    struct Task
    {
        std::string m_id;
        std::string m_prompt;
        ExecutionMode m_mode = ExecutionMode::SingleNode;
        uint32_t m_maxTokens = 512;
        float m_temperature = 0.7f;
        std::string m_nodeId; 
    };

    // -----------------------------------------------------------------------
    // What each node returns after inference
    // -----------------------------------------------------------------------
    struct InferenceResponse
    {
        std::string m_output;
        std::string m_taskId;
        ExecutionMode m_modeUsed = ExecutionMode::SingleNode;
        RouteTarget m_routeUsed = RouteTarget::CoreOnly;
        double m_totalLatencyMs = 0.0;
        float m_perplexity = 1.0f;
        double m_latencyMs = 0.0;
        std::string m_nodeId;
        bool m_success = true;
        std::string m_errorMessage;
    };

    // -----------------------------------------------------------------------
    // Routing decision produced by the router
    // -----------------------------------------------------------------------
    struct RouteDecision
    {
        RouteTarget m_target = RouteTarget::CoreOnly;
        float confidence_ = 1.0f;
        std::string m_reasoning;
        ExecutionMode m_mode = ExecutionMode::SingleNode;
    };

    // -----------------------------------------------------------------------
    // Prompt analysis features (PTDS §6.1)
    // -----------------------------------------------------------------------
    struct PromptFeatures
    {
        float numeric_density_ = 0.0f; 
        bool has_code_syntax_ = false;
        float complexity_ = 0.0f; 
        size_t token_count_ = 0;
        bool has_math_keywords_ = false;
        bool has_grammar_request_ = false;
        bool has_grounding_request_ = false;    
        bool has_formatting_request_ = false;   
    };

    // -----------------------------------------------------------------------
    // Node output used in consensus
    // -----------------------------------------------------------------------
    struct NodeOutput
    {
        std::string m_nodeId;
        std::string m_output;
        float m_perplexity = 1.0f;
        double m_latencyMs = 0.0;
        double reputation_ = 0.5;
    };

    // -----------------------------------------------------------------------
    // Reputation data model (PTDS §7.1)
    // -----------------------------------------------------------------------
    struct NodeReputation
    {
        std::string m_identityKey;
        double m_globalScore = 0.5;
        double m_mathScore = 0.5;
        double m_grammarScore = 0.5;
        double m_latencyScore = 0.5;
        double m_consistencyScore = 0.5;
        uint64_t m_taskCount = 0;
        uint64_t m_lastUpdatedMs = 0; 

        static constexpr uint64_t kMinTasksForHighTrust = 10;
    };

    // -----------------------------------------------------------------------
    // Grokipedia fact entry
    // -----------------------------------------------------------------------
    struct KnowledgeFact
    {
        std::string m_source;
        std::string m_content;
        float m_relevanceScore = 0.0f;
    };

    // -----------------------------------------------------------------------
    // GAML v1 Memory Object (Phase 8 — local-only, per D-01)
    // CRDT-ready: m_timestamp + m_sourceNode stored but not merged (D-11)
    // Extra fields (privacy_scope, replication_policy, etc.) deferred to Phase 9-11 (D-03)
    // -----------------------------------------------------------------------
    struct CognitiveAsset
    {
        std::string m_id;                  
        std::string m_entity;              
        MemoryObjectType m_type = MemoryObjectType::FACT;
        nlohmann::json m_payload;          
        int64_t m_timestamp = 0;           
        std::string m_sourceNode;          
        float m_confidence = 0.0f;         
        float m_provenance = 0.0f;         
        TrustClass m_trustClass = TrustClass::UNVERIFIED;  
    };

    // -----------------------------------------------------------------------
    // ELM execution context (Phase 7 — doc 03 §5.2.1)
    //
    // The previous chain step's output is carried exclusively by the `input`
    // parameter of IELM::Process(input, context) — no double-accounting
    // via a context field (per review WR-01).
    // -----------------------------------------------------------------------
    struct ELMContext
    {
        std::string m_originalTask;                                   
        std::vector<std::pair<ELMRole, float>> m_stepConfidences;     
        std::vector<KnowledgeFact> m_groundingFacts;                  
        std::vector<CognitiveAsset> m_memoryFacts;    
        std::vector<CognitiveAsset> m_memoryPolicies;  
    };

    // -----------------------------------------------------------------------
    // Chain step and execution chain (Phase 7 — doc 03 §6.2)
    // -----------------------------------------------------------------------
    struct ChainStep
    {
        ELMRole m_role = ELMRole::PrimaryDraft;
        std::optional<std::string> m_domain; 
    };

    struct ExecutionChain
    {
        std::vector<ChainStep> m_steps;
        std::string m_reasoning;          
        float m_chainConfidence = 0.0f;   
        bool m_needsRetrieval = false;    
    };

    // -----------------------------------------------------------------------
    // Final API response
    // -----------------------------------------------------------------------


    // -----------------------------------------------------------------------
    // Memory context returned by MemoryGovernor (GAML v1 — D-05)
    // -----------------------------------------------------------------------
    struct MemoryContext
    {
        std::vector<CognitiveAsset> m_facts;
        std::vector<CognitiveAsset> m_policies;
    };

} // namespace sgns::neoswarm

#endif // NEOSWARM_COMMON_TYPES_HPP

Updated on 2026-10-09 at 03:59:42 +0000