Overview
Theworkflows module provides LangGraph-based workflows for entity training, dialog synthesis, relationship analysis, and temporal simulation. Each workflow is a directed acyclic graph (DAG) of nodes with typed state.
Module: workflows/
Architecture:
create_entity_training_workflow()
LangGraph workflow for parallel entity training with progressive resolution elevation. Signature:WorkflowState
Typed state for entity training workflow. Schema:Workflow Nodes
load_graph:- Load NetworkX graph from storage
- Fallback to test graph if not found
- Populate all entities concurrently using asyncio
- Call LLMClient.populate_entity() for each node
- Store results in
entity_populations
- Convert EntityPopulation → Entity
- Preserve orchestrator metadata if present
- Generate TTM tensors
- Merge cognitive tensors with existing data
- Validate all entities using Validator.validate_all()
- Check temporal causality
- Check circadian constraints (M14)
- Check knowledge network flow
- Store violations in state
- Apply PCA/SVD compression for TENSOR_ONLY entities
- Store compressed versions for all entities
- Remove full tensors for TENSOR_ONLY to save space
- Trigger prospection (M15) for eligible entities
- Generate expectations and forecasts
- Refine tensors from prospective states
- Check entities needing resolution elevation (M2.4)
- Elevate based on centrality and query patterns
- Update entities in storage
LangGraph Node Examples
Custom Node: Knowledge Extraction
Custom Node: Relationship Evolution
TemporalAgent
Modal temporal causality agent for time-as-entity modeling. Signature:FORWARD: Standard causality (no anachronisms)PORTAL: Backward inference from endpointDIRECTORIAL: Narrative structure with dramatic arcsCYCLICAL: Time loops and prophecyBRANCHING: Counterfactual what-if scenarios
Main Methods
determine_fidelity_temporal_strategy:Fidelity Templates
Pre-configured fidelity allocation patterns.Minimalist Template
Distribution: 70% TENSOR, 21% SCENE, 7% DIALOG Use case: Token budget limited, broad coverage neededBalanced Template
Distribution: 33% TENSOR, 33% SCENE, 20% GRAPH, 13% DIALOG Use case: Standard simulations, balanced detailPortal Pivots Template
Distribution:- 2 endpoints: TRAINED
- Middle: 50% TENSOR, 25% SCENE, 13% DIALOG
Workflow Utilities
retrain_high_traffic_entities()
Progressive training for high-usage entities. Signature:Dialog Synthesis Functions
synthesize_dialog:Prospection Functions
generate_prospective_state:Counterfactual Functions
create_counterfactual_branch:Modal Strategies
Mode-specific strategy classes for temporal simulation.PortalStrategy
Backward simulation from endpoint to origin.DirectorialStrategy
Narrative-driven simulation with dramatic structure.CyclicalStrategy
Time loops and prophecy.BranchingStrategy
Counterfactual what-if scenarios.Scene Environment Functions
create_environment_entity:Animistic Entity Functions
create_animistic_entity:Best Practices
- Use typed state (TypedDict) for all workflows
- Track mechanisms with @track_mechanism decorator
- Batch LLM calls in parallel nodes
- Validate state between nodes
- Use transactions for multi-table writes
- Cache graphs to avoid reloading
- Monitor token usage via TemporalAgent
- Choose appropriate templates for fidelity allocation
- Handle node failures gracefully
- Log workflow execution for debugging
Example: Custom Workflow
Related
- Orchestrator - Scene compilation
- LLM Client - LLM integration
- Storage - Database persistence
- Schemas - Data models

