The four operations
Choose the operation for each request. You can use all four on the same agent.
Load your agent once
import { NullProtocol } from 'nullprotocol';
const agent = await NullProtocol.load({
key: process.env.NULLPROTOCOL_KEY,
agentId: 'order-reader'
});The examples on this page use the loaded agent. Each operation receives its saved instructions and included context.
Extract structured fields
Use extract(data, schema) when the application needs data in a specific shape. Shorthand fields are required; use JSON Schema for enums, nullable fields and more detailed constraints.
const result = await agent.extract('Order 42: two blue mugs.', {
orderId: 'number',
quantity: 'number',
item: 'string'
});
if (!result.success) throw new Error(result.error);
console.log(result.data);Summarize supplied text
const result = await agent.summarize(
'The parcel arrived late. One mug was cracked. The buyer wants a replacement.',
{ maxLength: 300, focus: 'problem and requested resolution' }
);
if (!result.success) throw new Error(result.error);
console.log(result.summary, result.keyPoints);maxLength limits the summary in JavaScript string characters. The SDK default is 200; HTTP and Try agent default to 1000. Set it explicitly when comparing results across integrations.
Check a claim against rules
const result = await agent.validate(
'Every claim must agree with the supplied policy.',
'Gift cards are refundable.',
{ reference: 'Gift cards are not refundable.' }
);
if (!result.success) throw new Error(result.error);
console.log(result.recommendation, result.score, result.reasoning);A successful operation returns a recommendation: pass, fail or conditional. A true success means a checked reply was returned; it does not mean the claim passed. The score is the model’s judgement, not a calibrated probability.
Choose the next action
const result = await agent.decide(
'The customer reports damage but has not supplied a photo.',
[
{ action: 'request_photo', description: 'Ask for a photo of the damage.' },
{ action: 'human_review', description: 'Ask a person to review the request.' }
]
);
if (!result.success) throw new Error(result.error);
console.log(result.action, result.parameters, result.reasoning);decide returns a choice and a payload. It does not send a message, query a database or run an external API. Use a registered application action when you want the SDK to validate parameters and execute a handler.
Check the result before using it
Operations return success: false with errorCode and error when they fail or are refused. Invalid model replies get one repair attempt by default. A failure can still consume tokens. Loading an agent can throw, so handle setup failures in your application as well.