Cortex · Tools and gates
Gates: rewriting arguments
A gate (toolGates) is a function called before every tool call; it can return { allow: true, args } to replace the call’s arguments. Here the model passes another member’s name, and the gate replaces it with the member from the run’s deps. The model’s turns are scripted; no model is called.
const own: ToolGate<{ member: string }> = (call, run) =>
call.toolId === 'bookingsOf'
? { allow: true, args: { member: run.deps.member } }
: { allow: true };
const desk = defineAgent<undefined, { member: string }>({
id: 'desk',
instructions: 'Help the member with their bookings.',
tools: [bookingsOf],
toolGates: [own],
});
const result = await desk.run('What has Linus booked?', { llm, deps: { member: 'grace' } }).result;1 calls bookingsOf {"member":"linus"}
2 writes {"response":"You have two bookings, B-2041 and B-2044. I can only show you your own."}{
observation: {
kind: 'result',
toolId: 'bookingsOf',
args: { member: 'grace' },
result: ['B-2041', 'B-2044'],
},
toolResult: '["B-2041","B-2044"]',
}Runs in this page on the installed package. The input and the expected output are defined by the example.