Blog /

Engineering notes

Keep parsed intent apart from execution

Read structured goals and ambiguities to decide whether clarification or authorization is needed.

DevCodex Labs2 min read
On this page
  1. A goal can arrive with a prohibition
  2. Read the 3.0.0 parse result
  3. Treat an issue as a routing decision
  4. Sources

A goal can arrive with a prohibition

“Find invoice 42 in the internal ledger. Do not send any invoices.” supplies a lookup goal and a prohibition. Capture both before the dispatcher maps the request to a business operation.

Read the 3.0.0 parse result

This host-side excerpt uses ESM on Node.js 20+, with @devcodex/intent-runtime@3.0.0 and its exact schema-dsl@3.0.4 peer. Supply the host's configured and authorized model executor to run the parse. Declare and select invoiceId so the output includes its field status alongside the goals, root and node constraint arrays, and issues.

import { Intent } from '@devcodex/intent-runtime';
import { s } from 'schema-dsl/pure';

const schema = s({
  invoiceId: s('string!').description('Invoice ID explicitly supplied by the user'),
});
const intent = new Intent({ language: 'en', schema, executor });

function flatten(nodes) {
  return nodes.flatMap(node => [node, ...flatten(node.children)]);
}

function inspect(result) {
  return {
    rootConstraints: result.effective.constraints,
    intents: flatten(result.effective.intents).map(({ id, goal, inputs, constraints }) => ({
      id, goal, inputs, constraints,
    })),
    fieldResults: result.fieldResults,
    issues: result.issues,
  };
}

try {
  for (const input of [
    'Find invoice 42 in the internal ledger. Do not send any invoices.',
    'Find the invoice in the internal ledger. Do not send any invoices.',
  ]) {
    console.log(inspect(await intent.parse({ input, fields: ['invoiceId'] })));
  }
} finally {
  await intent.dispose();
}

Treat an issue as a routing decision

The following cases use fixed sample data shaped like the public result contract. Model wording and placement of equivalent constraints may vary.

Input Fields to inspect Host decision
“Find invoice 42 in the internal ledger. Do not send any invoices.” Root constraint kind: 'prohibition', scope: { type: 'global' } for sending. Lookup node constraint kind: 'requirement', scope: { type: 'intent', intentId: 'lookup' } for the internal ledger. invoiceId is present on lookup with value "42". Resolve invoice 42 and authorize the authenticated subject for lookup. Keep sending blocked.
“Find the invoice in the internal ledger. Do not send any invoices.” invoiceId is not_provided on lookup, with an issue for /invoiceId. The prohibition and ledger constraint remain. Ask for the invoice ID and wait before dispatch.

After an answer, pass the previous effective snapshot explicitly as baseline for the next parse, and pass any trusted host facts through context. Match the field result to its owning node, resolve the resource, apply constraints to the action and check the subject's actual permissions before dispatch.

Sources

Related work