diff --git a/agents/paradigm_agent.py b/agents/paradigm_agent.py index 30c7dfc..1f785c1 100644 --- a/agents/paradigm_agent.py +++ b/agents/paradigm_agent.py @@ -263,7 +263,9 @@ def _build_structure_prompt(signals: dict) -> str: continue sections.append(f"\n## {title}") for row in rows[:10]: - sections.append(f"- {json.dumps(row, ensure_ascii=True)[:220]}") + # Postgres rows carry datetime objects (SQLite returns strings); + # default=str keeps prompt building backend-agnostic. + sections.append(f"- {json.dumps(row, ensure_ascii=True, default=str)[:220]}") return "\n".join(sections) diff --git a/tests/test_paradigm_prompt.py b/tests/test_paradigm_prompt.py new file mode 100644 index 0000000..e514e86 --- /dev/null +++ b/tests/test_paradigm_prompt.py @@ -0,0 +1,39 @@ +"""_build_structure_prompt must handle DB rows from both backends. + +Postgres returns datetime objects in signal rows where SQLite returns +strings; prompt building must not crash on either.""" + +from __future__ import annotations + +import os +import unittest +from datetime import datetime + +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment + + +class StructurePromptTest(unittest.TestCase): + def test_rows_with_datetime_values(self): + from agents.paradigm_agent import _build_structure_prompt + + signals = { + "entity_overlaps": [], + "pattern_matches": [], + "contradiction_clusters": [], + "taxonomy_map": [], + "hidden_variable_bridges": [ + { + "entity": "gaussian splatting", + "node_a": "cv.3d", + "node_b": "cv.sfm", + "created_at": datetime(2026, 6, 12, 12, 0, 0), + } + ], + } + prompt = _build_structure_prompt(signals) + self.assertIn("gaussian splatting", prompt) + self.assertIn("2026-06-12", prompt) + + +if __name__ == "__main__": + unittest.main()