https://promptfoo.dev/ logo
functionToolCallbacks: include test case context a...
# ❓|questions
o
Hi, I understand that tool calls args are generated purely by the LLM, but most orchestrators 'know' the context/conversation under which the tool call is performed. At the moment, any function in [
functionToolCallbacks
](https://www.promptfoo.dev/docs/providers/openai/#using-functions:~:text=and%20parameters.-,functionToolCallbacks,-A%20map%20of) is invoked with just the param string. Since the callback has no information about the context, it is difficult to emulate the function as closely as one may like to the real implementation, during the eval. Adding context (
testCase.metadata
or
testCase.vars
) allows [function callbacks](https://www.promptfoo.dev/docs/providers/openai/#using-functions:~:text=and%20parameters.-,functionToolCallbacks,-A%20map%20of) to be somewhat stateful. Since there is little control over test case execution order in promptfoo, contextual callbacks cannot be used in cases where ordering is required. I'm not asking for that control. The examples in the doc led me to try this workaround
Copy code
json
{
  type: "function",
  function: {
    name: "get_temperature",
    parameters: {
      type: "object",
        properties: {
          unit: {
            type: "string",
            enum: (vars) => vars.context_id,
          }
        },
    }
  }
}
It might work for the providers that fully support structured
json_schema
. However, I wasn't able to test this (my provider doesn't have this, it violated the schema and generated some nonsense string). I'm curious to hear if this is worthy of inclusion in promptfoo. I'd be happy to contribute if some one can share some pointers. PS: Congrats on the acquisition!
i
this seems like a good idea!