Skip to content

resolveAndInvoke

The resolveAndInvoke method is the SDK's killer feature. It compresses the entire Payre spine into a single call:

Natural Language → Resolve → Grant → Invoke → Receipt

Usage

typescript
const result = await payre.resolveAndInvoke(
  'Scan my infrastructure for vulnerabilities',
  { targets: ['10.0.0.0/24'], depth: 'full' },
);

console.log(result.agent.displayName); // 'VulnGuard'
console.log(result.receipt.success);    // true
console.log(result.receipt.result);     // { vulnerabilities: [...] }

What Happens Internally

  1. Resolve — Finds the best matching agent for the query (topK: 1)
  2. Grant — Creates a one_time grant for the caller
  3. Invoke — Calls the agent with the provided payload
  4. Return — Returns agent, grant, invoke record, and receipt

Parameters

typescript
resolveAndInvoke(
  query: string,
  payload: Record<string, unknown>,
  opts?: {
    callerId?: string;      // default: 'sdk_user'
    protocol?: string;      // filter agents by protocol
    grantType?: 'one_time' | 'session';  // default: 'one_time'
  }
): Promise<ResolveAndInvokeResult>

Return Value

typescript
interface ResolveAndInvokeResult {
  agent: AgentPassport;    // The matched agent
  grant: Grant;            // The created grant
  invoke: InvokeRecord;    // The invocation record
  receipt: Receipt;        // The execution receipt
}

Error Handling

Throws PayreApiError with status 404 if no matching agents are found:

typescript
try {
  await payre.resolveAndInvoke('something nobody can do', {});
} catch (err) {
  // err.statusCode === 404
  // err.message === 'No matching agents found for query'
}