How do I access _memory_ from a function?
1) First I tried passing in memory into the input variable of a function, but memory is not available from the variable selector.
2a) Tico says memory already is available from inside a function:
"memory
is an internal object, so we don’t surface it in the variable-picker. The good news is you don’t have to map it – every Function (and JavaScript) step already runs in the same scope, so you can read it directly inside your code."
and said to use:
const history = memory.history;
2b) But when I look in Debug Variables, I don't see memory having a .history so I tried both the above and the below:
const history = memory;
The above are not working for me. How do I access memory from a function? Thanks so much!
2 Replies
Here’s what’s going on 👇
•
_memory_
is an internal system object – it is not surfaced to your Function code. That’s why you don’t see it (or a .history
field) in the Debug panel and why const history = _memory_
fails.
• Voiceflow exposes the conversation history through the normal variable vf_memory
(a single-string transcript of the last n turns). vf_memory
is the piece you can work with.
How to use it in a Function
1. In the Function interface add an input variable, e.g. history
.
2. On the Function step, map that input to the project variable vf_memory
.
3. Inside your code grab it from args.inputVars
:
(Functions don’t automatically inherit every project variable; only what you map in inputVars
is available.)
If you just need to read the memory inside a JavaScript step (not a Function), you can reference it directly:
Key takeaway: work with vf_memory
, not _memory_
. 🟢
Docs: https://docs.voiceflow.com/docs/memoryi already tried working with vf_memory before i posted this. it does not work for me because i do not see a straightforward way to pull out a user response or an assistant response. splitting by newlines does not work well because the response itself can contain newlines. in contrast, memory would work well because of its array format. i want to work with memory