Segment lifecycle, outcome assessment, and segment analytics.
A session can contain multiple tasks. MOA tracks each task as a segment so learning is based on discrete outcomes instead of whole-session guesses.
Segments answer:
- What task was being attempted?
- Which tools and skills were used?
- How many turns and tokens did it cost?
- What outcome was assessed?
- What learning evidence should be derived from the outcome?
TaskSegment lives in crates/moa-core/src/types/segments.rs; persistent rows live in Postgres task_segments.
Important fields:
idsession_idstorage_partition_iduser_idscopetenant_idsegment_indextask_summarystarted_atended_atoutcomeassessmentoutcome_confidencetools_usedskills_activatedturn_counttoken_costprevious_segment_id
ActiveSegment is the lighter projection stored in session VO state.
Query rewriting produces QueryRewriteResult:
retrieval_querysourcereasonis_new_tasktask_summary
When a turn is prepared, SegmentTracker uses the query rewrite metadata and session events to decide whether to:
- keep the current active segment
- create the first segment
- close the previous segment and start a new one
Segment tracking reads only is_new_task and task_summary. Query rewrite metadata does not define a durable session intent taxonomy and does not choose tools for the agent.
The event log records SegmentStarted and SegmentCompleted events.
During a turn, the orchestrator records:
- tool names used
- skill names activated
- completed turn count
- token cost
The active VO state and task_segments row stay in sync through session store calls.
Segment assessment runs after boundaries such as segment completion, idle turns, cancellation, timeout, or deferred continuation evidence. It does not decide whether the live agent loop continues; deterministic turn state, approvals, cancellation, queued messages, and tool events own that control path.
Assessment combines five signal classes:
| Signal | Meaning |
|---|---|
| Tool outcome | Whether tools completed, failed, or produced useful output |
| Verification | Whether tests/checks/verification commands succeeded |
| Continuation | Whether the next user message indicates success, rework, abandonment, or a new task |
| Self-assessment | Whether the agent response claims completion or uncertainty |
| Structural | Whether turns, cost, and duration are anomalous for the tenant baseline |
The assessor outputs:
resolvedpartialunknownfailedabandoned
Assessment phases:
immediate: when a segment appears idle or completeddeferred: after a later user message gives continuation evidencefinal: when cancellation or timeout closes the segment
Each assessment updates the segment row and appends segment_assessed to learning_log.
After the assessment is persisted, MOA derives an ExperienceRecord from the
segment. The segment remains the measurement boundary; the experience record is
the learning object used for attribution, candidates, and task-conditioned
ranking.
Segment rows drive learning views:
| View | Use |
|---|---|
skill_resolution_rates |
Ranks skills by tenant-level resolution outcomes |
segment_baselines |
Provides structural baselines for segment assessment |
task_strategy_success_rates |
Ranks skills and other strategy components by task fingerprint |
Refresh is handled through the session store's materialized-view refresh path.
Segment events are durable boundaries. History compaction can summarize older events, but segment start/completion records remain part of replay and analytics.
User messages
-> query rewrite
-> segment start/continue/complete
-> tool and skill counters
-> segment assessment
-> experience record
-> attribution records
-> learning candidates
-> learning_log after promotion
-> skill ranking and memory learning
Task segmentation is the measurement layer that makes the rest of MOA's learning pipeline reliable.