All files / kernel-agents/src/types task.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76                                                                                                                                                       
import type { Logger } from '@metamask/logger';
 
import type { CapabilityRecord } from './capability.ts';
import type { Message, MessageTypeBase, Transcript } from './messages.ts';
 
export type Task<Result> = {
  id: string;
  objective: Objective<Result>;
  context: Context;
  attempts: Attempt<Result, MessageTypeBase, MessageTypeBase>[];
};
 
/**
 * A specification of what a user wants from an agent.
 */
export type Objective<Result> = {
  intent: string;
  // For wonky cases, this criterion can be satisfied by assignment.
  judgment: (result: unknown) => result is Result;
};
 
/**
 * A specification of the context in which an agent is operating.
 */
export type Context = {
  capabilities: CapabilityRecord;
  knowledge?: Record<string, unknown>;
};
 
/**
 * An experience of an agent fulfilling an objective in a particular context.
 */
export type Experience = {
  objective: Objective<unknown>;
  context: Context;
  history: Message<MessageTypeBase>[];
} & (
  | {
      result?: unknown;
      error?: never;
    }
  | {
      result?: never;
      error?: Error;
    }
);
 
/**
 * An attempt by an agent to fulfill an objective in a particular context.
 * Organized for the agent's learning process.
 */
export type Attempt<
  Result,
  Action extends string,
  Observation extends string,
> = {
  history: Transcript<Action | Observation>;
} & (
  | {
      result?: Result;
      error?: never;
    }
  | {
      result?: never;
      error?: Error;
    }
);
 
export type TaskArgs = {
  logger?: Logger;
  seed?: number;
  invocationBudget?: number;
  capabilities?: CapabilityRecord;
  nAttempts?: number;
};