trajectory_ir
Get Started
Trajectory IR LogoTrajectory IR
0.1.x
API Reference

Trajectory Client

The Trajectory dataclass and functions for creating, projecting, and resuming durable agent trajectories.

Overview

The Python client isn't a fluent class, it's a plain Trajectory dataclass paired with a handful of module-level functions in trajectory_ir.runtime. You get a Trajectory instance back from open_trajectory() or resume(), then pass it into everything else.

The Trajectory dataclass

@dataclass
class Trajectory:
    trajectory_id: str
    tenant_id: str
    db_path: str
    mode: str

Fields

FieldTypeDescription
trajectory_idstrUUID identifying this trajectory.
tenant_idstrIdentifier for the tenant/user that owns the trajectory.
db_pathstrPath to the metadata store backing this trajectory.
modestrExecution mode the trajectory was opened with.

There's no constructor to call directly. Instances come from open_trajectory() or resume() below.


open_trajectory()

Creates a new trajectory and its backing metadata store.

def open_trajectory(
    tenant_id: str,
    db_path: str,
    mode: str = "durable",
    trajectory_id: Optional[str] = None,
) -> Trajectory:

Parameters

ParameterTypeDefaultDescription
tenant_idstrrequiredIdentifier for the tenant/user owning the trajectory.
db_pathstrrequiredPath to the metadata store to create or attach to.
modestr"durable"Execution mode for the trajectory.
trajectory_idstr | NoneNoneOptional UUID. Auto-generated if omitted.

Returns: a Trajectory instance.

Example:

from trajectory_ir.runtime import open_trajectory

traj = open_trajectory(tenant_id="demo-user", db_path="~/.trajectory-ir/local.db")
print(traj.trajectory_id)

project()

Replays a trajectory's node log and returns its current semantic state. Useful for checking what's already happened before deciding on the next step.

def project(trajectory: Trajectory) -> dict:

Returns: a dict snapshot of the nodes recorded for the trajectory so far.

Example:

from trajectory_ir.runtime import project

state = project(traj)
print(state["nodes"])

resume()

Reattaches to an existing trajectory after a process restart or crash, picking up wherever the metadata log left off.

def resume(trajectory_id: str, db_path: str) -> Trajectory:

Parameters

ParameterTypeDefaultDescription
trajectory_idstrrequiredID of the trajectory to resume.
db_pathstrrequiredPath to the metadata store the trajectory was originally opened against.

Returns: the reattached Trajectory instance. If the log has a dangling DECISION_SEAL for a NON_IDEMPOTENT_WRITE tool, the trajectory comes back in a BLOCKED_NEEDS_GATE state instead of re-running it.