with one click
using-trajectories-sdk
// Use when programmatically creating or managing agent trajectories in TypeScript - provides TrajectoryClient for persistent storage and TrajectoryBuilder for in-memory construction
// Use when programmatically creating or managing agent trajectories in TypeScript - provides TrajectoryClient for persistent storage and TrajectoryBuilder for in-memory construction
Use when coordinating multiple AI agents and need to pick the right orchestration pattern - covers 10 patterns (fan-out, pipeline, hub-spoke, consensus, mesh, handoff, cascade, dag, debate, hierarchical) with decision framework and reflection protocol
Use when writing agent-relay workflows that must fully validate features end-to-end before merging. Covers the 80-to-100 pattern - going beyond "code compiles" to "feature works, tested E2E locally." Includes PGlite for in-memory Postgres testing, mock sandbox patterns, test-fix-rerun loops, verify gates after every edit, and the full lifecycle from implementation through passing tests to commit.
Use when building multi-agent workflows with the relay broker-sdk - covers the WorkflowBuilder API, DAG step dependencies, agent definitions, step output chaining via {{steps.X.output}}, verification gates, evidence-based completion, owner decisions, dedicated channels, dynamic channel management (subscribe/unsubscribe/mute/unmute), swarm patterns, error handling, event listeners, step sizing rules, authoring best practices, and the lead+workers team pattern for complex steps
Use when writing agent-relay workflows that must fully validate features end-to-end before merging. Covers the 80-to-100 pattern - going beyond "code compiles" to "feature works, tested E2E locally." Includes PGlite for in-memory Postgres testing, mock sandbox patterns, test-fix-rerun loops, verify gates after every edit, and the full lifecycle from implementation through passing tests to commit.
Use when building multi-agent workflows with the relay broker-sdk - covers the WorkflowBuilder API, DAG step dependencies, agent definitions, step output chaining via {{steps.X.output}}, verification gates, evidence-based completion, owner decisions, dedicated channels, dynamic channel management (subscribe/unsubscribe/mute/unmute), swarm patterns, error handling, event listeners, step sizing rules, authoring best practices, and the lead+workers team pattern for complex steps
Best practices for structuring prpm.json package manifests with required fields, tags, organization, multi-package management, enhanced file format, eager/lazy activation, and conversion hints
| name | using-trajectories-sdk |
| description | Use when programmatically creating or managing agent trajectories in TypeScript - provides TrajectoryClient for persistent storage and TrajectoryBuilder for in-memory construction |
The agent-trajectories SDK provides two APIs for programmatically capturing agent work trajectories: TrajectoryClient (persistent, async) and TrajectoryBuilder (in-memory, sync).
trail CLI instead)| Need | Use |
|---|---|
| Persist trajectories to disk | TrajectoryClient |
| Build trajectories in memory | TrajectoryBuilder or trajectory() |
| One-liner start | trajectory('title') shorthand |
| Export formats | .toMarkdown(), .toJSON(), .toTimeline(), .toPRSummary() |
npm install agent-trajectories
Use when you need trajectories saved to .trajectories/ on disk.
import { TrajectoryClient } from 'agent-trajectories/sdk';
const client = new TrajectoryClient({ defaultAgent: 'my-agent' });
await client.init(); // Required before use
// Start a trajectory
const session = await client.start('Implement feature X');
// Record work in chapters
await session.chapter('Research');
await session.note('Found existing auth patterns');
await session.finding('Current implementation uses JWT');
await session.chapter('Implementation');
await session.decide(
'JWT vs Session tokens',
'JWT',
'Better for stateless API clients',
[{ option: 'Session tokens', reason: 'Simpler but requires server state' }]
);
// Complete with retrospective
await session.done('Implemented JWT auth', 0.9, {
approach: 'Extended existing auth module',
learnings: ['JWT refresh flow needs careful error handling'],
});
await client.close();
new TrajectoryClient({
dataDir: '.trajectories', // Storage location (default)
defaultAgent: 'agent-name', // Default agent for chapters
autoSave: true, // Auto-persist after each operation (default)
});
| Method | Description |
|---|---|
client.start(title) | Start new trajectory, returns session |
client.resume() | Resume active trajectory |
client.get(id) | Get trajectory by ID |
client.list(query?) | List trajectories with optional filter |
client.search(text) | Full-text search |
| Method | Description |
|---|---|
session.chapter(title, agent?) | Start a new chapter |
session.note(content) | Record a note |
session.finding(content) | Record a finding (medium significance) |
session.reflect(content, confidence?) | Record a reflection (high significance) |
session.error(content) | Record an error (high significance) |
session.decide(question, chosen, reasoning, alts?) | Record a decision |
session.done(summary, confidence, opts?) | Complete trajectory |
session.abandon(reason?) | Abandon trajectory |
Use when you don't need persistence - just building a trajectory data structure.
import { TrajectoryBuilder, trajectory } from 'agent-trajectories/sdk';
// Shorthand
const result = trajectory('Fix auth bug')
.chapter('Investigation', 'claude')
.finding('Null pointer in login handler')
.decide('Fix approach', 'Add null check', 'Simplest correct fix')
.done('Fixed null pointer exception', 0.95);
// Export
console.log(TrajectoryBuilder.create('Task')
.chapter('Work', 'agent')
.note('Did the thing')
.toMarkdown());
Builder is synchronous and chainable. Call .done(), .complete(), or .build() to get the Trajectory object.
Both Client sessions and Builder support:
session.toMarkdown(); // Human-readable markdown
session.toJSON(); // Raw JSON data
session.toJSON(true); // Compact JSON
session.toTimeline(); // Chronological timeline view
session.toPRSummary(); // Optimized for PR descriptions
| Mistake | Fix |
|---|---|
Forgetting await client.init() | Always call init before using client |
| Using Builder when you need persistence | Use TrajectoryClient instead |
Not calling client.close() | Always close when done |
| Starting a trajectory when one is active | Complete or abandon the active one first |
Missing await on session methods | Client session methods are async |