Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(context): resolve review issues in temporal awareness PR
KaifAhmad1c483352d7a9b
diff --git a/semantica/context/agent_context.py b/semantica/context/agent_context.pyindex 9b66d966..bb16db46 100644--- a/semantica/context/agent_context.py+++ b/semantica/context/agent_context.py@@ -1828,7 +1828,13 @@ class AgentContext:raise KeyError(f"Unknown checkpoint label: {label}")if self._temporal_version_manager is None:- self._temporal_version_manager = TemporalVersionManager()+ try:+ self._temporal_version_manager = TemporalVersionManager()+ except Exception as exc:+ raise RuntimeError(+ "flush_checkpoint requires a TemporalVersionManager. "+ "Pass one via temporal_version_manager= at construction time."+ ) from excreturn self._temporal_version_manager.create_snapshot(self._checkpoints[label],@@ -1840,11 +1846,11 @@ class AgentContext:def _capture_checkpoint_state(self) -> Dict[str, Any]:"""Capture a serializable snapshot of the current graph state."""if self.knowledge_graph and hasattr(self.knowledge_graph, "state_at"):- return self.knowledge_graph.state_at(datetime.now())+ return self.knowledge_graph.state_at(datetime.utcnow())if self.knowledge_graph and hasattr(self.knowledge_graph, "to_dict"):graph_dict = self.knowledge_graph.to_dict()return {- "timestamp": datetime.now().isoformat(),+ "timestamp": datetime.utcnow().isoformat(),"nodes": graph_dict.get("nodes", []),"edges": graph_dict.get("edges", []),"entities": graph_dict.get("nodes", []),@@ -1860,7 +1866,7 @@ class AgentContext:],}return {- "timestamp": datetime.now().isoformat(),+ "timestamp": datetime.utcnow().isoformat(),"nodes": [],"edges": [],"entities": [],diff --git a/semantica/context/causal_analyzer.py b/semantica/context/causal_analyzer.pyindex 962bcedd..4ffc1a9d 100644--- a/semantica/context/causal_analyzer.py+++ b/semantica/context/causal_analyzer.py@@ -165,7 +165,7 @@ class CausalChainAnalyzer:if direction not in ["upstream", "downstream"]:raise ValueError("Direction must be 'upstream' or 'downstream'")if not (1 <= max_depth <= 100):- raise ValueError("max_depth must be between 1 and 20")+ raise ValueError("max_depth must be between 1 and 100")if hasattr(self.graph_store, "nodes") and hasattr(self.graph_store, "edges"):return self._trace_at_time_from_context_graph(event_id, cutoff, direction, max_depth)@@ -181,7 +181,7 @@ class CausalChainAnalyzer:"""results = self.graph_store.execute_query(query,- {"decision_id": event_id, "at_time": cutoff.isoformat()},+ {"decision_id": event_id, "at_time": cutoff.strftime("%Y-%m-%dT%H:%M:%S") + "Z"},)records = self._extract_records(results)decisions: List[Decision] = []diff --git a/semantica/context/context_graph.py b/semantica/context/context_graph.pyindex 7a3ba29a..28ed4c11 100644--- a/semantica/context/context_graph.py+++ b/semantica/context/context_graph.py@@ -155,7 +155,9 @@ def _normalize_temporal_input(value: Optional[Union[str, int, float, datetime]])return datetime.fromtimestamp(value, tz=timezone.utc).replace(tzinfo=None).isoformat()if isinstance(value, str):parsed = _parse_iso_dt(value)- return parsed.isoformat() if parsed is not None else value+ if parsed is None:+ raise ValueError(f"Temporal value {value!r} is not a valid ISO datetime string")+ return parsed.isoformat()raise ValueError("Temporal values must be datetime, epoch seconds, ISO strings, or None")@@ -1545,7 +1547,7 @@ class ContextGraph:target_id=target_decision_id,edge_type=relationship_type,weight=1.0,- metadata={"recorded_at": datetime.now().isoformat()},+ metadata={"recorded_at": datetime.utcnow().isoformat()},)self._add_internal_edge(edge)@@ -2055,7 +2057,7 @@ class ContextGraph:"entities": entities,"decision_maker": decision_maker,"timestamp": timestamp,- "recorded_at": datetime.now().isoformat(),+ "recorded_at": datetime.utcnow().isoformat(),"valid_from": normalized_valid_from,"valid_until": normalized_valid_until,"metadata": metadata or {},