* fix: misc fixes for observations and mental models * feat: improve graph retrieval for observations - Update LinkExpansionRetriever to traverse through source_memory_ids for observation entity connections (avoiding data duplication) - Remove entity link copy from world facts to observations in consolidator - Add tests for link expansion graph retrieval - Add directives_applied field to ReflectResult - Include user's other changes (CLI, docs, client updates) * fix: CI test failures - Add mental_model_id parameter to create_mental_model function - Fix ToolCallTrace not including reason field from ToolCall - Improve test_link_expansion_observation_graph_retrieval to wait for consolidation with retry * chore: reduce link expansion log verbosity * Revert "chore: reduce link expansion log verbosity" This reverts commit 3ce759391cead1012157785fa78fef16ef9bfe3b. * feat: add semantic/temporal/entity links as fallback in graph retrieval - Add fallback query for semantic, temporal, and entity links from memory_links - Check both directions (outgoing and incoming links) - Weight fallback results at 0.5x to prioritize entity links via unit_entities - Fixes graph retrieval returning 0 when data has cross-cluster temporal connections * fix: enable observations fixture for link expansion test - Add enable_observations fixture to ensure observations are created - Increase wait time from 10 to 30 seconds for CI reliability
70 lines
2 KiB
Python
70 lines
2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Directives API examples for Hindsight.
|
|
Run: python examples/api/directives.py
|
|
"""
|
|
import os
|
|
|
|
HINDSIGHT_URL = os.getenv("HINDSIGHT_API_URL", "http://localhost:8888")
|
|
BANK_ID = "directives-example-bank"
|
|
|
|
# =============================================================================
|
|
# Setup (not shown in docs)
|
|
# =============================================================================
|
|
from hindsight_client import Hindsight
|
|
|
|
client = Hindsight(base_url=HINDSIGHT_URL)
|
|
|
|
# Create a test bank
|
|
client.create_bank(bank_id=BANK_ID, name="Test Bank")
|
|
|
|
# =============================================================================
|
|
# Doc Examples
|
|
# =============================================================================
|
|
|
|
# [docs:create-directive]
|
|
# Create a directive (hard rule for reflect)
|
|
directive = client.create_directive(
|
|
bank_id=BANK_ID,
|
|
name="Formal Language",
|
|
content="Always respond in formal English, avoiding slang and colloquialisms."
|
|
)
|
|
|
|
print(f"Created directive: {directive.id}")
|
|
# [/docs:create-directive]
|
|
|
|
directive_id = directive.id
|
|
|
|
# [docs:list-directives]
|
|
# List all directives in a bank
|
|
directives = client.list_directives(bank_id=BANK_ID)
|
|
|
|
for d in directives.items:
|
|
print(f"- {d.name}: {d.content[:50]}...")
|
|
# [/docs:list-directives]
|
|
|
|
# [docs:update-directive]
|
|
# Update a directive (e.g., disable without deleting)
|
|
updated = client.update_directive(
|
|
bank_id=BANK_ID,
|
|
directive_id=directive_id,
|
|
is_active=False
|
|
)
|
|
|
|
print(f"Directive active: {updated.is_active}")
|
|
# [/docs:update-directive]
|
|
|
|
# [docs:delete-directive]
|
|
# Delete a directive
|
|
client.delete_directive(
|
|
bank_id=BANK_ID,
|
|
directive_id=directive_id
|
|
)
|
|
# [/docs:delete-directive]
|
|
|
|
# =============================================================================
|
|
# Cleanup (not shown in docs)
|
|
# =============================================================================
|
|
client.delete_bank(bank_id=BANK_ID)
|
|
|
|
print("directives.py: All examples passed")
|