Skip to content
3 min read · 595 words

Class: Thought

Defined in: src/lib/classes/thought.ts:198

An immutable, validated internal reasoning trace produced by an agent.

Remarks

Represents an agent's internal thinking — distinct from @nhtio/adk!Message (which is part of the visible conversation) and never shown to end users directly. Carries an identity so reasoning traces can be attributed to a specific agent in multi-agent conversations. Constructed from a RawThought via rawThoughtSchema. The content field is always a @nhtio/adk!Tokenizable so token cost can be estimated inline — including when the raw input omitted it or supplied '', which is legal in opaque-replay mode and resolves to an empty @nhtio/adk!Tokenizable.

Constructors

Constructor

ts
new Thought(raw: RawThought): Thought;

Defined in: src/lib/classes/thought.ts:260

Parameters

ParameterTypeDescription
rawRawThoughtThe raw thought input validated against rawThoughtSchema.

Returns

Thought

Throws

@nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE when raw does not satisfy the schema.

Properties

PropertyModifierTypeDefault valueDescriptionDefined in
contentreadonlyTokenizableundefinedThe reasoning content as a @nhtio/adk!Tokenizable for inline token estimation. Remarks Never undefined — an opaque thought constructed without prose carries an empty @nhtio/adk!Tokenizable here, so readers need no presence guard.src/lib/classes/thought.ts:230
createdAtreadonlyDateTimeundefinedWhen this thought was recorded.src/lib/classes/thought.ts:244
idreadonlystringundefinedStable unique identifier for this thought.src/lib/classes/thought.ts:222
identityreadonlyIdentityundefinedThe identity of the agent who produced this thought.src/lib/classes/thought.ts:232
payloadreadonlyunknownundefinedOptional vendor-opaque payload that round-trips back to a matching model wire. See RawThought.payload.src/lib/classes/thought.ts:237
replayCompatibilityreadonlystring | undefinedundefinedOptional wire-shape identifier describing which adapter can safely replay this thought. See RawThought.replayCompatibility.src/lib/classes/thought.ts:242
updatedAtreadonlyDateTimeundefinedWhen this thought was last modified.src/lib/classes/thought.ts:246
schemastaticObjectSchema<RawThought>rawThoughtSchemaValidator schema that accepts a RawThought object. Remarks Reusable fragment for any schema that needs to validate or nest a thought entry.src/lib/classes/thought.ts:205

Methods

[ENCODE_METHOD]()

ts
ENCODE_METHOD: unknown;

Defined in: src/lib/classes/thought.ts:336

Serialise this Thought into an @nhtio/encoder snapshot.

Returns

unknown

A RawThought-shaped snapshot.

Remarks

Emits a RawThought-shaped object; content is the live @nhtio/adk!Tokenizable, identity the live @nhtio/adk!Identity, and the temporal fields live Luxon DateTimes (the encoder recurses into each). The vendor-opaque payload is passed through as-is — if it holds a value the encoder cannot serialise, encode throws (standard encoder behaviour). Round-trips via Thought.[DECODE_METHOD], which re-validates through the constructor.


[DECODE_METHOD]()

ts
static DECODE_METHOD: Thought;

Defined in: src/lib/classes/thought.ts:354

Reconstruct a Thought from a Thought.[ENCODE_METHOD] snapshot.

Parameters

ParameterTypeDescription
dataunknownThe snapshot produced by Thought.[ENCODE_METHOD].

Returns

Thought

A fully-validated Thought.


isThought()

ts
static isThought(value: unknown): value is Thought;

Defined in: src/lib/classes/thought.ts:217

Returns true if value is a Thought instance.

Parameters

ParameterTypeDescription
valueunknownThe value to test.

Returns

value is Thought

true when value is a Thought instance.

Remarks

Uses @nhtio/adk!isInstanceOf for cross-realm safety — instanceof would fail for instances created in a different module copy or VM context.