Custom header from prompt Custom Function
# support
r
Hi, Is it possible, for the header of a custom function, to set the value of the header from the prompt ? For example I will have 2 agent with 2 different prompt, I want to the {header_value} from the prompt as the value for the header when the function will be called
@Vapi
v
@RealKhalass Absolutely, you can set the value of a header for a custom function from the prompt. To achieve this, you would typically extract the
{header_value}
from the prompt context and then pass it as a parameter when calling the function. If you have the specific details or need assistance with how to set this up in your code, please let me know, and I'd be happy to help further!
r
@Vapi yes help me in setting this
v
@RealKhalass Certainly! To set the header value from the prompt for a custom function, you would follow these steps: 1. **Extract the Header Value**: Determine how the
{header_value}
is provided in the prompt. It could be part of the text or structured data. 2. **Pass the Value to the Function**: Once you have the
{header_value}
, you will need to pass it to your custom function as an argument, typically in the form of a parameter. Here's a simplified example of how you might do this in code:
Copy code
javascript
// This is a hypothetical custom function that takes a header value as a parameter
function callCustomFunctionWithHeader(headerValue) {
  // Set up the request with the header
  const requestOptions = {
    headers: {
      'Custom-Header': headerValue
    }
  };
  
  // Make the API call or function call with the requestOptions
  // ...
}

// Extract the header value from the prompt
const headerValueFromPrompt = extractHeaderValue(prompt);

// Call the custom function with the extracted header value
callCustomFunctionWithHeader(headerValueFromPrompt);
In the above example,
extractHeaderValue
would be a function you define to parse the prompt and find the
{header_value}
. Since I don't have the specifics of your setup, this is a general guide. If you can provide more details about how the
{header_value}
is included in the prompt and the nature of the custom function, I can give you more tailored instructions.
@RealKhalass Yes, it is possible to set the value of a header for a custom function from the prompt using dynamic templates. You can define the header value in the prompt using the double curly braces syntax
{{header_value}}
. When you start the call, you can replace
{{header_value}}
with the actual value you want to use for the header based on the specific agent or context. For example, if you have two agents with different prompts, you can customize the header value for each agent like this: Agent 1's prompt might include:
Copy code
"Please use {{header_value}} as the header for this call."
And you would replace
{{header_value}}
with the actual value for Agent 1. Agent 2's prompt might include:
Copy code
"Please use {{header_value}} as the header for this call."
And you would replace
{{header_value}}
with the actual value for Agent 2. When the function is called, the
{{header_value}}
in the prompt will be replaced with the respective value you've set for each agent. This allows you to dynamically set the header value for custom functions based on the prompt or other contextual information.
You can continue this conversation by mentioning me in the message.
r
@Vapi so what do i imput in the headers params of the tool ?
v
@RealKhalass To input the header value in the parameters of the tool, you would typically use a variable or a placeholder that gets replaced with the actual value at runtime. Here's a general approach: 1. Define a placeholder in your tool configuration for the header value (e.g.,
{{header_value}}
). 2. When you prepare to call the tool, replace the placeholder with the actual value you want to use for the header. For example, if your tool configuration accepts parameters like this:
Copy code
json
{
  "headers": {
    "Custom-Header": "{{header_value}}"
  }
}
Before calling the tool, you would replace
{{header_value}}
with the actual value you've obtained from the prompt or context. Here's how you might do it in code:
Copy code
javascript
// Assume 'actualHeaderValue' is the value you extracted from the prompt
const actualHeaderValue = "The value from the prompt";

// Replace the placeholder in the tool configuration
const toolParams = {
  "headers": {
    "Custom-Header": actualHeaderValue
  }
};

// Now 'toolParams' contains the actual header value and can be passed to the tool
If you need to call a function and pass this header value, you would do so by including it in the function call parameters. If you provide the specific details of the tool or function you're working with, I can give you a more precise example.
r
do i put it as a object or a text @Vapi
v
@RealKhalass When setting headers for an API call or a tool, you typically define them as an object, where the keys are the header names and the values are the header values. Here's an example of how you might structure the headers as an object in JSON format:
Copy code
json
{
  "headers": {
    "Custom-Header": "ActualHeaderValue"
  }
}
In this object,
"Custom-Header"
is the name of the header, and
"ActualHeaderValue"
is the value you want to set for that header. You would replace
"ActualHeaderValue"
with the actual value you've obtained from the prompt. When passing this to a function or tool, you would maintain the structure as an object. Here's how you might pass it in JavaScript:
Copy code
javascript
// Define the headers object with the actual header value
const headers = {
  "Custom-Header": actualHeaderValue // Replace with the value from the prompt
};

// Pass the headers object to the function or tool
someFunction({
  headers: headers
});
Remember to replace
actualHeaderValue
with the value you've extracted from the prompt, and
someFunction
with the actual function or tool you're calling. If you're working with a specific API or tool that requires a different format, please let me know, and I can provide more detailed guidance.
s
@RealKhalass You cannot create or update the headers dynamically using the prompt.
Because of no response closing this ticket!!