Foresight.Reflect.CitationSelection (Foresight v0.3.1)

Copy Markdown View Source

Filter the LLM's declared citations (from the terminal done tool's args) down to those that were actually retrieved during the reflect loop.

The agentic path previously cited EVERY retrieved id (process-dict accumulation) — over-citation. With the terminal done tool (llm_core terminal_tool), the model declares which ids it actually used; we keep only the intersection with what was retrieved. This drops both over-citation (retrieved but not cited) and hallucinated citations (cited but never retrieved), mirroring Hindsight's done-tool id filter.

Summary

Types

Retrieved grounding ids, per tier (string ids).

Functions

Select the cited ids per tier, keeping only ids present in retrieved.

Types

retrieved()

@type retrieved() :: %{
  memory: [String.t()],
  observation: [String.t()],
  mental_model: [String.t()]
}

Retrieved grounding ids, per tier (string ids).

Functions

select(terminal_args, retrieved)

@spec select(map(), retrieved()) :: retrieved()

Select the cited ids per tier, keeping only ids present in retrieved.

terminal_args is the raw done tool arguments (string keys "memory_ids" / "observation_ids" / "mental_model_ids"). Results preserve the retrieved order (deterministic, aligns with based_on).