* feat: introduce hindsight-api-slim and hindsight-all-slim packages Closes #552 - Move all source code from hindsight-api/ to new hindsight-api-slim/ - hindsight-api-slim has heavy ML deps (torch, sentence-transformers, transformers, einops, flashrank, mlx, mlx-lm, safetensors) and pg0-embedded as optional extras: [local-ml], [embedded-db], [all] - hindsight-api becomes a zero-code meta-package depending on hindsight-api-slim[all] for full backward compatibility - Add hindsight-all-slim meta-package: hindsight-api-slim + client + embed - hindsight-all updated to depend on hindsight-api-slim[all] - pg0.py: lazy-import pg0 with clear ImportError pointing to [embedded-db] - Dockerfile: replace sed hack with proper uv sync --extra flags - Update release.yml, test.yml, lint.sh, release.sh, CLAUDE.md and all path references throughout the repo * refactor: rename hindsight/ directory to hindsight-all/ * docs: document hindsight-api-slim and hindsight-all-slim package variants Add package variants table and extras explanation to installation.md * docs: remove emojis from installation.md, use professional tone * docs: link Docker slim variant to pip package variants section * docs: consolidate Docker image variants into single table * ci: fix working-directory paths after package restructure - Replace all hindsight-api → hindsight-api-slim in test.yml - Replace hindsight → hindsight-all in test.yml - Add --extra embedded-db to test-embed API install step * ci: add local-ml and embedded-db extras to API sync steps These extras were previously implicit in the old hindsight-api package (which bundled everything). Now that hindsight-api-slim uses optional extras, we must explicitly request local-ml and embedded-db in CI. * ci: add API install step with embedded-db to test-embed smoke test The smoke test starts hindsight-api as a daemon, which requires pg0-embedded. Add a dedicated install step for hindsight-api-slim with embedded-db extra so the daemon can start successfully. * ci: remove --no-install-project when using optional extras When --no-install-project is combined with --extra, the optional deps are not installed because extras require the project to be active. Remove --no-install-project from steps that need local-ml or embedded-db. * ci: fix ordering of uv sync steps to preserve optional extras When uv sync runs for a different workspace member, it removes optional extras installed for other members. Fix by always running extra-requiring API sync last, after other workspace member syncs. Also remove --no-install-project from embedded-db sync in test-embed, as --no-install-project prevents optional extras from being active. * ci: add local-ml extra to test-embed API install for smoke test The smoke test starts the full API server which needs sentence-transformers for local embeddings (default provider). Add local-ml extra to the install. * ci: simplify extras with --all-extras and add slim pip smoke test - Replace explicit --extra local-ml --extra embedded-db with --all-extras for cleaner, more maintainable sync steps - Add test-pip-slim job: tests hindsight-api-slim[embedded-db] without local ML models, using Cohere for embeddings/reranking (mirrors Docker slim smoke test approach) * ci: simplify slim smoke test to health check only (mirrors Docker test)
143 lines
5.2 KiB
Python
143 lines
5.2 KiB
Python
"""
|
|
Tests for agent management API (profile, disposition).
|
|
"""
|
|
import pytest
|
|
import uuid
|
|
from hindsight_api import MemoryEngine, RequestContext
|
|
from hindsight_api.api import CreateBankRequest, DispositionTraits
|
|
from hindsight_api.engine.memory_engine import Budget
|
|
|
|
|
|
def unique_agent_id(prefix: str) -> str:
|
|
"""Generate a unique agent ID for testing."""
|
|
return f"{prefix}_{uuid.uuid4().hex[:8]}"
|
|
|
|
|
|
class TestAgentProfile:
|
|
"""Tests for agent profile management."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_agent_profile_creates_default(self, memory: MemoryEngine, request_context):
|
|
"""Test that getting a profile for a new agent creates default disposition."""
|
|
bank_id = unique_agent_id("test_profile_default")
|
|
|
|
profile = await memory.get_bank_profile(bank_id, request_context=request_context)
|
|
|
|
assert profile is not None
|
|
assert "disposition" in profile
|
|
|
|
disposition = profile["disposition"]
|
|
assert disposition["skepticism"] == 3
|
|
assert disposition["literalism"] == 3
|
|
assert disposition["empathy"] == 3
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_agent_disposition(self, memory: MemoryEngine, request_context):
|
|
"""Test updating agent disposition traits."""
|
|
bank_id = unique_agent_id("test_profile_update")
|
|
|
|
profile = await memory.get_bank_profile(bank_id, request_context=request_context)
|
|
assert profile["disposition"]["skepticism"] == 3
|
|
|
|
new_disposition = {
|
|
"skepticism": 5,
|
|
"literalism": 4,
|
|
"empathy": 2,
|
|
}
|
|
await memory.update_bank_disposition(bank_id, new_disposition, request_context=request_context)
|
|
|
|
updated_profile = await memory.get_bank_profile(bank_id, request_context=request_context)
|
|
disposition = updated_profile["disposition"]
|
|
assert disposition["skepticism"] == new_disposition["skepticism"]
|
|
assert disposition["literalism"] == new_disposition["literalism"]
|
|
assert disposition["empathy"] == new_disposition["empathy"]
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_agents(self, memory: MemoryEngine, request_context):
|
|
"""Test listing all agents."""
|
|
agent_id_1 = unique_agent_id("test_list")
|
|
agent_id_2 = unique_agent_id("test_list")
|
|
agent_id_3 = unique_agent_id("test_list")
|
|
|
|
await memory.get_bank_profile(agent_id_1, request_context=request_context)
|
|
await memory.get_bank_profile(agent_id_2, request_context=request_context)
|
|
await memory.get_bank_profile(agent_id_3, request_context=request_context)
|
|
|
|
agents = await memory.list_banks(request_context=request_context)
|
|
|
|
agent_ids = [a["bank_id"] for a in agents]
|
|
assert agent_id_1 in agent_ids
|
|
assert agent_id_2 in agent_ids
|
|
assert agent_id_3 in agent_ids
|
|
|
|
for agent in agents:
|
|
assert "bank_id" in agent
|
|
assert "disposition" in agent
|
|
assert "created_at" in agent
|
|
assert "updated_at" in agent
|
|
|
|
|
|
class TestAgentEndpoint:
|
|
"""Tests for agent PUT endpoint logic."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_put_agent_create(self, memory: MemoryEngine, request_context):
|
|
"""Test creating an agent via PUT endpoint."""
|
|
bank_id = unique_agent_id("test_put_create")
|
|
|
|
request = CreateBankRequest(
|
|
disposition=DispositionTraits(
|
|
skepticism=4,
|
|
literalism=5,
|
|
empathy=2
|
|
),
|
|
)
|
|
|
|
profile = await memory.get_bank_profile(bank_id, request_context=request_context)
|
|
|
|
if request.disposition is not None:
|
|
await memory.update_bank_disposition(
|
|
bank_id,
|
|
request.disposition.model_dump(),
|
|
request_context=request_context,
|
|
)
|
|
|
|
final_profile = await memory.get_bank_profile(bank_id, request_context=request_context)
|
|
|
|
assert final_profile["disposition"]["skepticism"] == 4
|
|
assert final_profile["disposition"]["literalism"] == 5
|
|
|
|
|
|
class TestAgentDispositionIntegration:
|
|
"""Tests for disposition integration with other features."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_think_uses_disposition(self, memory: MemoryEngine, request_context):
|
|
"""Test that THINK operation uses agent disposition."""
|
|
bank_id = unique_agent_id("test_think")
|
|
|
|
disposition = {
|
|
"skepticism": 5, # Very skeptical
|
|
"literalism": 4, # High literalism
|
|
"empathy": 2, # Low empathy
|
|
}
|
|
await memory.update_bank_disposition(bank_id, disposition, request_context=request_context)
|
|
|
|
await memory.retain_batch_async(
|
|
bank_id=bank_id,
|
|
contents=[
|
|
{"content": "Traditional painting techniques have been used for centuries"},
|
|
{"content": "Modern digital art is changing the art world"}
|
|
],
|
|
request_context=request_context,
|
|
)
|
|
|
|
result = await memory.reflect_async(
|
|
bank_id=bank_id,
|
|
query="What do you think about traditional vs modern art?",
|
|
budget=Budget.LOW,
|
|
request_context=request_context,
|
|
)
|
|
|
|
assert result.text is not None
|
|
assert len(result.text) > 0
|