Option
guards of agent
Checks that the person's message, the answers of tools from outside the app and the agent's own answer must pass.
Value
{ in?, out?, refused? }. in and out are lists of guards; refused is the text the person is answered where a guard does not pass, and That cannot be answered here. when it is left out (the word guarded of option.agent.words). Left out, nothing is guarded.
A guard is a function or a flow whose input is { text, from } and whose answer is { pass: boolean, why?: text }, written by the builder; a judge (word.judge), which passes where its score reaches its pass, handed the person's message of the turn as the task and the text as the answer, and named in its steps by its model; or one of the engine's own: word.noOtherPeople and word.noPersonal. from is 'person', 'tool' or 'assistant'. A model of any kind is a guard as a judge.
- Each
inguard runs before the first model step, on the person's message, and on the answer of each tool that came from outside the app before the model reads it, and on its error, which carries the tool's own words, also where the model calls it by its name withcall: a tool of an outside server or of a source, code, apython, a plain body that calls a service, an action,files.textorhear, and a query over a table that others than a row's owner may write. Its step isguard in 1 <guard>for the message, andguard in N.M <guard>for the answer of the tool calltool N.M. - Each
outguard runs on the final answer, with its typed value where the agent statesoutput, before it is kept in memory or sent, in the stepguard out <guard>; on what the model writes beside its tool calls, and so on the text of a hand-over, in the stepguard out N <guard>; and on a question to the person before it is shown, in the stepguard out N.M <guard>. Whereoutguards stand, the text of the answer is not sent to whoever follows the run as it is written. An answer that a sequence made meets them too, and a run withoutputthat ends in prose keeps none of it.
A guard that does not pass, or that fails, fails its step with code.T7131, which names the guard and its why. The turn ends there: the run is done, its answer is { text: refused } with no value, the conversation keeps that text and nothing the model wrote, and the answer of a tool that a guard refused is kept as refused, so the model never reads it. A guard runs as the starter of the run, and its model calls count on the run's perRun.
Example
export const careful = agent('careful', {
model: writer,
instructions: 'Answer with care.',
tools: [news, myOrders],
limits: { steps: 6, perRun: { tokensOut: 50000 } },
guards: { in: [tone], out: [tone, noOtherPeople], refused: 'Sorry, that is not something I can answer.' },
})Errors
code.T7131: a guard did not pass.
See also
word.agent, word.noOtherPeople, word.noPersonal, option.agent.output