hindsight-api 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. hindsight_api/admin/cli.py +59 -0
  2. hindsight_api/alembic/versions/h3c4d5e6f7g8_mental_models_v4.py +112 -0
  3. hindsight_api/alembic/versions/i4d5e6f7g8h9_delete_opinions.py +41 -0
  4. hindsight_api/alembic/versions/j5e6f7g8h9i0_mental_model_versions.py +95 -0
  5. hindsight_api/alembic/versions/k6f7g8h9i0j1_add_directive_subtype.py +58 -0
  6. hindsight_api/alembic/versions/l7g8h9i0j1k2_add_worker_columns.py +109 -0
  7. hindsight_api/alembic/versions/m8h9i0j1k2l3_mental_model_id_to_text.py +41 -0
  8. hindsight_api/alembic/versions/n9i0j1k2l3m4_learnings_and_pinned_reflections.py +134 -0
  9. hindsight_api/alembic/versions/o0j1k2l3m4n5_migrate_mental_models_data.py +113 -0
  10. hindsight_api/alembic/versions/p1k2l3m4n5o6_new_knowledge_architecture.py +194 -0
  11. hindsight_api/alembic/versions/q2l3m4n5o6p7_fix_mental_model_fact_type.py +50 -0
  12. hindsight_api/alembic/versions/r3m4n5o6p7q8_add_reflect_response_to_reflections.py +47 -0
  13. hindsight_api/alembic/versions/s4n5o6p7q8r9_add_consolidated_at_to_memory_units.py +53 -0
  14. hindsight_api/alembic/versions/t5o6p7q8r9s0_rename_mental_models_to_observations.py +134 -0
  15. hindsight_api/alembic/versions/u6p7q8r9s0t1_mental_models_text_id.py +41 -0
  16. hindsight_api/alembic/versions/v7q8r9s0t1u2_add_max_tokens_to_mental_models.py +50 -0
  17. hindsight_api/api/http.py +1119 -93
  18. hindsight_api/api/mcp.py +11 -191
  19. hindsight_api/config.py +145 -45
  20. hindsight_api/engine/consolidation/__init__.py +5 -0
  21. hindsight_api/engine/consolidation/consolidator.py +859 -0
  22. hindsight_api/engine/consolidation/prompts.py +69 -0
  23. hindsight_api/engine/cross_encoder.py +114 -9
  24. hindsight_api/engine/directives/__init__.py +5 -0
  25. hindsight_api/engine/directives/models.py +37 -0
  26. hindsight_api/engine/embeddings.py +102 -5
  27. hindsight_api/engine/interface.py +32 -13
  28. hindsight_api/engine/llm_wrapper.py +505 -43
  29. hindsight_api/engine/memory_engine.py +2090 -1089
  30. hindsight_api/engine/mental_models/__init__.py +14 -0
  31. hindsight_api/engine/mental_models/models.py +53 -0
  32. hindsight_api/engine/reflect/__init__.py +18 -0
  33. hindsight_api/engine/reflect/agent.py +933 -0
  34. hindsight_api/engine/reflect/models.py +109 -0
  35. hindsight_api/engine/reflect/observations.py +186 -0
  36. hindsight_api/engine/reflect/prompts.py +483 -0
  37. hindsight_api/engine/reflect/tools.py +437 -0
  38. hindsight_api/engine/reflect/tools_schema.py +250 -0
  39. hindsight_api/engine/response_models.py +130 -4
  40. hindsight_api/engine/retain/bank_utils.py +79 -201
  41. hindsight_api/engine/retain/fact_extraction.py +81 -48
  42. hindsight_api/engine/retain/fact_storage.py +5 -8
  43. hindsight_api/engine/retain/link_utils.py +5 -8
  44. hindsight_api/engine/retain/orchestrator.py +1 -55
  45. hindsight_api/engine/retain/types.py +2 -2
  46. hindsight_api/engine/search/graph_retrieval.py +2 -2
  47. hindsight_api/engine/search/link_expansion_retrieval.py +164 -29
  48. hindsight_api/engine/search/mpfp_retrieval.py +1 -1
  49. hindsight_api/engine/search/retrieval.py +14 -14
  50. hindsight_api/engine/search/think_utils.py +41 -140
  51. hindsight_api/engine/search/trace.py +0 -1
  52. hindsight_api/engine/search/tracer.py +2 -5
  53. hindsight_api/engine/search/types.py +0 -3
  54. hindsight_api/engine/task_backend.py +112 -196
  55. hindsight_api/engine/utils.py +0 -151
  56. hindsight_api/extensions/__init__.py +10 -1
  57. hindsight_api/extensions/builtin/tenant.py +5 -1
  58. hindsight_api/extensions/operation_validator.py +81 -4
  59. hindsight_api/extensions/tenant.py +26 -0
  60. hindsight_api/main.py +16 -5
  61. hindsight_api/mcp_local.py +12 -53
  62. hindsight_api/mcp_tools.py +494 -0
  63. hindsight_api/models.py +0 -2
  64. hindsight_api/worker/__init__.py +11 -0
  65. hindsight_api/worker/main.py +296 -0
  66. hindsight_api/worker/poller.py +486 -0
  67. {hindsight_api-0.3.0.dist-info → hindsight_api-0.4.0.dist-info}/METADATA +12 -6
  68. hindsight_api-0.4.0.dist-info/RECORD +112 -0
  69. {hindsight_api-0.3.0.dist-info → hindsight_api-0.4.0.dist-info}/entry_points.txt +1 -0
  70. hindsight_api/engine/retain/observation_regeneration.py +0 -254
  71. hindsight_api/engine/search/observation_utils.py +0 -125
  72. hindsight_api/engine/search/scoring.py +0 -159
  73. hindsight_api-0.3.0.dist-info/RECORD +0 -82
  74. {hindsight_api-0.3.0.dist-info → hindsight_api-0.4.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,14 @@
1
+ """
2
+ Mental models module for Hindsight.
3
+
4
+ Mental models contain directives - hard rules that are injected into reflect prompts.
5
+ Directives are user-defined and their observations are user-provided (not LLM-generated).
6
+
7
+ Other types of consolidated knowledge are handled by:
8
+ - Learnings: Automatic bottom-up consolidation from facts
9
+ - Pinned Reflections: User-curated living documents
10
+ """
11
+
12
+ from .models import MentalModel, MentalModelSubtype
13
+
14
+ __all__ = ["MentalModel", "MentalModelSubtype"]
@@ -0,0 +1,53 @@
1
+ """
2
+ Pydantic models for mental models.
3
+ """
4
+
5
+ from datetime import datetime, timezone
6
+ from enum import Enum
7
+
8
+ from pydantic import BaseModel, Field
9
+
10
+
11
+ class MentalModelSubtype(str, Enum):
12
+ """Subtype of mental model.
13
+
14
+ Currently only DIRECTIVE is supported. Other types of consolidated knowledge
15
+ are handled by:
16
+ - Learnings: Automatic bottom-up consolidation from facts
17
+ - Pinned Reflections: User-curated living documents
18
+ """
19
+
20
+ DIRECTIVE = "directive" # User-defined hard rules, observations user-provided
21
+
22
+
23
+ class MentalModel(BaseModel):
24
+ """
25
+ A mental model representing synthesized understanding.
26
+
27
+ Mental models are the agent's consolidated knowledge. Unlike raw facts,
28
+ mental models provide:
29
+ - A one-liner description for quick scanning/retrieval
30
+ - A full summary for deep understanding
31
+ - Links to related mental models
32
+ """
33
+
34
+ id: str = Field(description="Unique identifier within the bank")
35
+ bank_id: str = Field(description="Bank this mental model belongs to")
36
+ subtype: MentalModelSubtype = Field(description="How this model was created")
37
+ name: str = Field(description="Human-readable name")
38
+ description: str = Field(description="One-liner for quick scanning and retrieval matching")
39
+ summary: str | None = Field(default=None, description="Full synthesized understanding")
40
+
41
+ # References
42
+ entity_id: str | None = Field(default=None, description="Reference to entities table when type=entity")
43
+ source_facts: list[str] = Field(default_factory=list, description="Fact IDs used to generate summary")
44
+ links: list[str] = Field(default_factory=list, description="Related mental model IDs")
45
+
46
+ # Tags for scoped visibility (similar to document tags)
47
+ tags: list[str] = Field(default_factory=list, description="Tags for scoped visibility filtering")
48
+
49
+ # Timestamps
50
+ last_updated: datetime | None = Field(default=None, description="When summary was last regenerated")
51
+ created_at: datetime = Field(
52
+ default_factory=lambda: datetime.now(timezone.utc), description="When this model was created"
53
+ )
@@ -0,0 +1,18 @@
1
+ """
2
+ Reflect agent module for agentic reflection with tools.
3
+
4
+ The reflect agent uses an iterative loop with tools to:
5
+ 1. Lookup mental models (existing knowledge)
6
+ 2. Recall facts (semantic + temporal search)
7
+ 3. Expand memories (get chunk/document context)
8
+ """
9
+
10
+ from .agent import ReflectAgentResult, run_reflect_agent
11
+ from .models import ReflectAction, ReflectActionBatch
12
+
13
+ __all__ = [
14
+ "run_reflect_agent",
15
+ "ReflectAgentResult",
16
+ "ReflectAction",
17
+ "ReflectActionBatch",
18
+ ]