Skip to content

Commit 9a86d33

Browse files
authored
add docs on function parameter variable extraction (#653)
1 parent a44cb51 commit 9a86d33

File tree

1 file changed

+67
-7
lines changed

1 file changed

+67
-7
lines changed

fern/tools/handoff.mdx

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ Control what conversation history is passed to the next assistant:
321321

322322
## Variable Extraction
323323

324-
Extract and pass structured data during handoff:
324+
Extract and pass structured data during handoff. Variables extracted by the handoff tool are available to all subsequent assistants in the conversation chain.
325+
When a handoff extracts a variable with the same name as an existing one, the new value replaces the previous value.
326+
327+
### 1. `variableExtractionPlan` in destinations
328+
This extraction method will make an OpenAI structured output request to extract variables. Use this method if you have multiple destinations, each with different variables that need to be extracted.
325329

326330
```json
327331
{
@@ -331,12 +335,8 @@ Extract and pass structured data during handoff:
331335
"destinations": [
332336
{
333337
"type": "assistant",
334-
"assistantId": "order-processing-assistant",
338+
"assistantName": "order-processing-assistant",
335339
"description": "customer is ready to place an order",
336-
"contextEngineeringPlan": {
337-
"type": "lastNMessages",
338-
"maxMessages": 5
339-
},
340340
"variableExtractionPlan": {
341341
"schema": {
342342
"type": "object",
@@ -377,6 +377,66 @@ Extract and pass structured data during handoff:
377377
}
378378
```
379379

380+
### 2. `tool.function`
381+
We will also extract variables in the tool call parameters from the LLM tool call (in addition to sending these parameters to your server in a `handoff-destination-request` in a dynamic handoff). Be sure to include the `destination` parameter with the assistant names or IDs in `enum`, as that is how Vapi determines where to handoff the call to. The `destination` parameter will not be extracted as a variable. Also, remember to add `destination` and all other variables that are required to the JsonSchema's `required` array.
382+
383+
```json
384+
{
385+
"tools": [
386+
{
387+
"type": "handoff",
388+
"destinations": [
389+
{
390+
"type": "assistant",
391+
"assistantName": "order-processing-assistant",
392+
"description": "customer is ready to place an order",
393+
}
394+
],
395+
"function": {
396+
"name": "handoff_to_order_processing_assistant",
397+
"parameters": {
398+
"type": "object",
399+
"properties": {
400+
"description": {
401+
"type": "string",
402+
"description": "The destination to handoff the call to.",
403+
"enum": ["order-processing-assistant"]
404+
},
405+
"customerName": {
406+
"type": "string",
407+
"description": "Full name of the customer"
408+
},
409+
"email": {
410+
"type": "string",
411+
"format": "email",
412+
"description": "Customer's email address"
413+
},
414+
"productIds": {
415+
"type": "array",
416+
"items": {
417+
"type": "string"
418+
},
419+
"description": "List of product IDs customer wants to order"
420+
},
421+
"shippingAddress": {
422+
"type": "object",
423+
"properties": {
424+
"street": { "type": "string" },
425+
"city": { "type": "string" },
426+
"state": { "type": "string" },
427+
"zipCode": { "type": "string" }
428+
}
429+
}
430+
},
431+
"required": ["destination", "customerName", "email"]
432+
}
433+
}
434+
},
435+
]
436+
}
437+
```
438+
439+
380440
## Custom Function Definitions
381441

382442
Override the default function definition for more control. You can overwrite the function name for each tool to put into the system prompt or pass custom parameters in a dynamic handoff request.
@@ -387,7 +447,7 @@ Override the default function definition for more control. You can overwrite the
387447
{
388448
"type": "handoff",
389449
"function": {
390-
"name": "transfer_to_department",
450+
"name": "handoff_to_department",
391451
"description": "Transfer the customer to the appropriate department based on their needs. Only use when explicitly requested or when the current assistant cannot help.",
392452
"parameters": {
393453
"type": "object",

0 commit comments

Comments
 (0)