Implementation:ALwrity ALwrity TaskMemoryService record task outcome
| Knowledge Sources | |
|---|---|
| Domains | Daily_Workflow, Memory, Semantic_Indexing |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for recording task outcomes to a database and a txtai semantic index with debounced saving, enabling self-learning deduplication for the daily workflow pipeline.
Description
The TaskMemoryService.record_task_outcome method is stage 6 of the Daily Workflow Generation pipeline. When a task reaches a terminal status (completed, dismissed, rejected, skipped), it records the outcome in two stores: (1) a TaskHistory row in the per-user database (with a SHA-256 hash of the title+description for deduplication), and (2) a TxtaiIntelligenceService.index_content call that upserts the task text and metadata into the user's txtai embeddings index for semantic search. The index save is debounced — upserts are coalesced and flushed to disk at most once per TASK_MEMORY_SAVE_BATCH_SIZE upserts or TASK_MEMORY_SAVE_DEBOUNCE_SEC seconds (default 5.0), avoiding a disk write per task. A fallback path directly upserts into embeddings if index_content is unavailable.
Usage
Import this service when:
- A task's outcome must be recorded for future self-learning and dedup.
- The txtai index should be updated without a disk write per task.
- A SHA-256 hash is needed to detect duplicate tasks across days.
Code Reference
Source Location
- Repository: ALwrity
- File: backend/services/task_memory_service.py (L33-120+)
Signature
class TaskMemoryService:
"""Manages the long-term memory of user tasks."""
def __init__(self, user_id: str, db: Session):
self.user_id = user_id
self.db = db
self.intelligence = TxtaiIntelligenceService(user_id)
def _compute_hash(self, title: str, description: str) -> str:
"""Compute a consistent SHA-256 hash for task deduplication."""
async def record_task_outcome(
self,
task: DailyWorkflowTask,
feedback_score: int = 0,
feedback_text: str = None,
) -> None:
"""
Record a task's final status into DB and txtai index.
Args:
task: DailyWorkflowTask with title, description, status, pillar_id.
feedback_score: Optional numeric feedback.
feedback_text: Optional textual feedback.
"""
Import
from services.task_memory_service import TaskMemoryService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| task | DailyWorkflowTask | Yes | title, description, status, pillar_id, metadata_json |
| feedback_score | int | No | Numeric feedback (default 0) |
| feedback_text | str | No | Textual feedback |
Outputs
| Name | Type | Description |
|---|---|---|
| side effect | DB | TaskHistory row committed |
| side effect | txtai index | Task text + metadata upserted; disk save debounced |
Usage Examples
Recording a completed task
from services.task_memory_service import TaskMemoryService
service = TaskMemoryService(user_id="clerk_user_123", db=db_session)
await service.record_task_outcome(
task=completed_task, # DailyWorkflowTask with status="completed"
feedback_score=5,
feedback_text="Great task, very relevant.",
)
# Task is now in DB (TaskHistory) and the txtai index (debounced save)
Forcing a flush
# Force-save any pending index upserts (e.g. on shutdown)
flushed = await service.flush()
print(f"Flushed {flushed} pending upsert(s) to disk")
Related Pages
Implements Principle
- Principle:ALwrity_ALwrity_Semantic_Indexing_Self_Learning
- Principle:ALwrity_ALwrity_Committee_Agent_Generation