UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

59 lines (58 loc) • 4.37 kB
/** * The model's VIEW of the leg's tool table — the tools one request shows it. * * ONE rule: a tool whose every call the run's deny rules refuse is not shown, except a leg's verdict tool (`legVerdicts`): it stays * shown and its call meets the gate — the reference adds its structured-output tool after the deny filter the same way. The reference removes a tool a whole-tool deny * rule names from the tool pool before the model sees it (built-in and protocol tools alike; a deny wins, no allow is * consulted). Here every face that can refuse a model's call answers by its own whole-tool reading, the one its refusal of a * call already takes: the leg's effective policy (the fold the gate runs — the caller policy, the session and ancestor rules, * the inherited parent policies; {@link ToolPolicy.wholeToolRefusals}), and the stored rules — the person's persisted rows and * the org's rows, over one read of the store (`PermissionRuleLanes.wholeToolRefusals`). Only a WHOLE-TOOL rule speaks here: a * rule about some calls of a tool (a command, a path, a value) leaves the tool shown, and its calls meet the gate. * * Read once per request, every reading side by side, each settled by the fold's own law ({@link toolPolicyWholeToolRefusals}): * one that cannot answer (it throws, it does not answer in time) refuses nothing here, and the readings beside it stand — its * calls still meet the gate, which is where a refusal is decided. The leg's tools stay * mounted: a call the model makes anyway (a name it learned elsewhere) meets the gate and its rule's refusal. The view and * the gate never decide the same question: the view says what the model is shown, the gate whether a call runs. */ import type { Context, StreamFn } from "../../internal/llm.js"; import type { TurnPromptSnapshot } from "../../prompt-assembly/turn-snapshot.js"; import type { LegVerdicts } from "../../agents/tool-filter.js"; import { type ToolRoster } from "../tool-roster.js"; import { type ToolPolicy } from "../tool-policy.js"; /** The faces the view reads, the roster whose face the gate stamps on a call of a tool, and the leg's turn snapshot (it * names the tools ACTUALLY sent). */ export interface ToolTableViewFaces { readonly policy: Pick<ToolPolicy, "wholeToolRefusals"> | undefined; /** The stored rules — the person's rows and the org's, one read of the store for both. */ readonly stored: Pick<ToolPolicy, "wholeToolRefusals"> | undefined; readonly roster: { readonly current: ToolRoster | undefined; }; /** The leg's verdict tools (`legVerdicts`; the view reads only which tools they are): never hidden — a whole-tool deny that reaches one * is met by the gate at its call, which the run records (`TaskResult.verdictRefused`); hidden, the leg would end with no outcome and no * trace of why. */ readonly verdicts: Pick<LegVerdicts, "has">; readonly turnSnapshotRef: { current?: TurnPromptSnapshot; }; } export interface ToolTableView { /** The request `context` as the model is shown it: its tools block without the tools the faces refuse whole (the same * object when none is) — over one read of every face. */ request(context: Context, signal?: AbortSignal): Promise<Context>; /** The same view of `context`, from the same reading, with nothing moved: the leg's prefix seats and {@link shows} keep * what the last request showed (a rendering of a request that may never be sent). */ render(context: Context, signal?: AbortSignal): Promise<Context>; /** Whether the last request showed the tool (before any request: every tool) — the search space of a lane that answers the * model about tools between requests (ToolSearch: a tool the model is not shown is no tool it can find). */ shows(toolName: string): boolean; } /** The leg's view — `undefined` when no face reads a whole-tool rule (every request then shows the tools block as built). */ export declare function createToolTableView(faces: ToolTableViewFaces): ToolTableView | undefined; /** A request stream that rides the view: its tools block shows what {@link ToolTableView.request} shows. A leg whose view is * not seated yet rides unchanged. */ export declare function streamShowingView(seat: { readonly current?: ToolTableView; }, stream: StreamFn): StreamFn;