@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
23 lines • 955 B
JavaScript
import { ModelBehaviorError } from "../errors.mjs";
import { addErrorToCurrentSpan } from "../tracing/context.mjs";
export function ensureToolCallerAllowed(toolCall, allowedCallers, toolName, agent) {
const caller = 'caller' in toolCall && toolCall.caller?.type === 'program'
? 'programmatic'
: 'direct';
const effectiveAllowedCallers = allowedCallers ?? ['direct'];
if (effectiveAllowedCallers.includes(caller)) {
return;
}
const message = `Model invoked tool ${toolName} with caller ${caller}, but the tool allows only ${JSON.stringify(effectiveAllowedCallers)}.`;
addErrorToCurrentSpan({
message,
data: {
agent_name: agent.name,
tool_name: toolName,
tool_call_id: 'callId' in toolCall ? toolCall.callId : undefined,
tool_caller: caller,
},
});
throw new ModelBehaviorError(message);
}
//# sourceMappingURL=toolCaller.mjs.map