Skip to content

Intent methods

Intent methods let you configure a request before it runs. The available methods depend on the kind of intent:

Tier What it is Methods
Askable<T> an extractor or call intent, resolved through ask .withRetry(n) · .withModel(nameOrModel) · .withParams({…}) · .withTimeout(ms)
Intent<T> what calling an infer function returns — also PromiseLike<T> the four above, plus .detached()
tuned.tsi
export infer function tuned(.text: string) {
const a = ask (..`the title`: string).withRetry(2);
const b = ask (..`the body`: string).withModel("careful");
const c = ask (..`a creative tagline`: string).withParams({ temperature: 0.9, maxOutputTokens: 200 });
const d = ask (..`a one-paragraph summary`: string).withTimeout(10_000);
return { a, b, c, d };
}
  • .withRetry(n) allows n additional attempts at the whole ask, with no backoff. For call intents, an attempt includes running the function, so use this only when repetition is safe. The provider-level withRetry retries provider requests instead; see Resilience.
  • .withModel(nameOrModel) — the dynamic form of ask with; accepts a configured name or a LanguageModel object.
  • .withParams({ temperature, maxOutputTokens, providerOptions }) sets request parameters. Fields override earlier values on the intent, while providerOptions merges by key. Parameters contribute to the request fingerprint, so changing them requires a separate replay entry. See Record and replay.
  • .withTimeout(ms) limits the intent’s provider requests. Within an existing invocation, the intent and invocation deadlines both apply; the earlier one wins. 0 removes the intent’s own limit. When the intent starts a root invocation, this setting becomes the invocation timeout.

Awaiting an infer function’s intent from TypeScript starts a new invocation. Its .withTimeout(ms) setting replaces the configured invocation timeout.

When one infer function calls another with ask, the child normally inherits the caller’s context. Use .detached() to give the child only its own context. It has no effect when awaiting from plain TypeScript because there is no parent context to inherit.

person.tsi
export interface Person { name: string; age: number }
export infer function extractPerson(.message: string) {
return ask `the person described in the text`: Person;
}
main.ts
import { extractPerson } from "./person.tsi";
const text = "Alice Smith, 32, is a staff engineer at Acme Corp.";
const person = await extractPerson(text).withTimeout(30_000);
console.log(person);
brief.tsi
import { extractPerson } from "./person.tsi";
export infer function brief(.text: string, .audience: string) {
// extractPerson runs with its own context only — brief's .text/.audience are not composed into its prompts
const person = ask extractPerson(text).detached();
const intro = ask `a one-line introduction of the person for this audience`: string;
return { person, intro };
}
  • .withTimeout(ms) overrides ask.timeoutMs when starting a root invocation; 0 disables that timeout. Within a parent invocation, it limits the callee while the parent deadline still applies. Timeouts cover provider requests only. See Ask options.
  • .detached() — resolve without inheriting the caller frame’s context. Useful when one infer function asks another and you do not want the caller’s contextual parameters composed into the callee’s prompts.

Each method returns a new, unstarted intent and leaves the original unchanged. An intent resolves at most once. Chain the options you need, then resolve the returned intent.

Next: TypeScript interop