Skip to main content
Version: 0.0.9

agrag.history.tasks.ConversationHistory

ConversationHistory(store:GraphStore, *, project_id:str, agent_id:str, scope:frozenset[str] | None = None) -> None

Durable task state for one project, written on behalf of one agent.

Operations take the project and author from this constructor. Each write takes an optional request_id. A repeated write with the same id and arguments returns the stored result, and the same id with other arguments returns request_id_reused.

Functions:

  • create_task – Create a task, or return the existing task of that name.
  • fetch_event – Read one exact event and its redaction state from this project.
  • get_task – Read the bounded resume view of a task.
  • list_events – Read events of a task in sequence order, one page at a time.
  • list_steps – Read one bounded page of steps, with a name cursor for continuation.
  • record_decision_reads – Persist decision ids delivered to a task without writing an event.
  • record_event – Append one raw event to a task.
  • record_read_keys – Persist document keys delivered to a task without writing an event.
  • record_source_reads – Persist the documents behind history content delivered to a task.
  • set_step – Create or update a step of a task.

Parameters:

  • store (GraphStore) – The graph store that holds conversation history.
  • project_id (str) – The project every operation is scoped to. Use a value from trusted configuration.
  • agent_id (str) – The author recorded on tasks and events.
  • scope (frozenset[str] | None) – Document scope for reads and writes. None allows every task, which keeps direct Python callers working.

create_task​

create_task(task_name:str, goal:str, *, request_id:str | None = None) -> CreateTaskResult

Create a task, or return the existing task of that name.

Parameters:

  • task_name (str) – The task name, unique within the project.
  • goal (str) – The goal. An existing task of the same name must have the same goal.
  • request_id (str | None) – Optional id of at most 64 characters for a safe retry.

Returns:

fetch_event​

fetch_event(task_name:str, seq:int) -> EventLookup

Read one exact event and its redaction state from this project.

get_task​

get_task(task_name:str) -> TaskLookup

Read the bounded resume view of a task.

The view has the goal, status, last event sequence number and the first steps in view order, with counts for every state. It has no event bodies.

Parameters:

  • task_name (str) – The task name.

Returns:

  • TaskLookup – The view when the task exists in this project and is visible under
  • TaskLookup – the scope when the view is read. Otherwise found is false.

list_events​

list_events(task_name:str, *, after_seq:int = 0, limit:int = 50) -> EventPage

Read events of a task in sequence order, one page at a time.

Parameters:

  • task_name (str) – The task name.
  • after_seq (int) – Return events with a larger sequence number than this.
  • limit (int) – Maximum events in the page, between 1 and 200.

Returns:

  • EventPage – The page. When the task is absent or hidden by the scope, found
  • EventPage – is false and the page is empty.

list_steps​

list_steps(task_name:str, state:StepState, *, after_name:str | None = None, limit:int = 50) -> StepPage

Read one bounded page of steps, with a name cursor for continuation.

record_decision_reads​

record_decision_reads(task_name:str, decision_ids:Sequence[str]) -> bool

Persist decision ids delivered to a task without writing an event.

A task hidden by the scope is not attributed. This keeps reads on record when the agent run that received them fails later.

Parameters:

  • task_name (str) – The task the decision content contributed to.
  • decision_ids (Sequence[str]) – Ids of the decisions whose content was delivered.

Returns:

  • bool – True when the ids were recorded. False for a missing or hidden task,
  • bool – and for a task created before decision reads were tracked, which
  • bool – keeps no id list.

record_event​

record_event(task_name:str, kind:EventKind, *, role:str | None = None, name:str | None = None, payload:str, read_document_keys:Sequence[str] = (), request_id:str | None = None) -> RecordEventResult

Append one raw event to a task.

The payload is cut to MAX_PAYLOAD_CHARACTERS when longer, and the event records the hash of the full text. No model is called.

Parameters:

  • task_name (str) – The task the event belongs to.
  • kind (EventKind) – The kind of event.
  • role (str | None) – The speaker role for a message, or None.
  • name (str | None) – The tool or source name for a tool event, or None.
  • payload (str) – The event text.
  • read_document_keys (Sequence[str]) – Document keys the caller read to produce this event. They are persisted on the task for scope checks.
  • request_id (str | None) – Optional id of at most 64 characters for a safe retry.

Returns:

record_read_keys​

record_read_keys(task_name:str, read_document_keys:Sequence[str]) -> bool

Persist document keys delivered to a task without writing an event.

This is the attribution seam used by serving layers that tag a read with a task identity. A task hidden by the scope is not attributed.

Parameters:

  • task_name (str) – The task the read contributed to.
  • read_document_keys (Sequence[str]) – Keys of the documents whose text was delivered.

Returns:

  • bool – True when the keys were recorded, False for a missing or hidden
  • bool – task.

record_source_reads​

record_source_reads(task_name:str, supports:Sequence[SupportInput]) -> bool

Persist the documents behind history content delivered to a task.

The task inherits the documents that the source events and decisions rest on, so copied text stays within their scope. A source without a document list makes this task's list unknown.

Parameters:

  • task_name (str) – The task that received the content.
  • supports (Sequence[SupportInput]) – The events or decisions whose content was delivered.

Returns:

  • bool – True when the documents were recorded, False for a missing or
  • bool – hidden task.

set_step​

set_step(task_name:str, name:str, state:StepState, *, kind:StepKind = StepKind.OTHER, result_event_seq:int | None = None, result_basis:StepResultBasis = StepResultBasis.UNKNOWN, supports:Sequence[SupportInput] = (), fetched_evidence:Sequence[FetchOutcome] = (), request_id:str | None = None) -> SetStepResult

Create or update a step of a task.

Parameters:

  • task_name (str) – The task the step belongs to.
  • name (str) – The step name, unique within the task.
  • state (StepState) – The new state. Use unknown when the outcome is not known.
  • kind (StepKind) – The broad category of the step.
  • result_event_seq (int | None) – The sequence number of the event that holds the result, or None.
  • result_basis (StepResultBasis) – Whether the result is independent, supported, or unknown. Supported results are reusable only while available.
  • supports (Sequence[SupportInput]) – Explicit source references for a supported result.
  • fetched_evidence (Sequence[FetchOutcome]) – Current fetch outcomes for document references.
  • request_id (str | None) – Optional id of at most 64 characters for a safe retry.

Returns:

  • SetStepResult – The step when recorded. A completed step without a result event
  • SetStepResult – gives result_required. Otherwise task_not_found or
  • SetStepResult – event_not_found when result_event_seq names no event.