Working with generated files in tool calls

I am trying to implement my own analysis functions for the Assistant API to work with.

In order to reduce/eliminate halluzinations with big data files, I would like to interface with generated files directly. I assume this was likely made extra difficult for encapsulation purposes, but I wonder how best to go about it if I still wish to work with those files.

From what I can tell, anything generated with code interpreter stays in the sandbox and is gone once the session is over. You only receive access to a file when the assistant decides to post it as an image or link in its generated message. Only then is it placed into OpenAI storage with an assigned file id - and this file id is unknown to the assistant it came from, so it can’t even use it as an argument for function tool calls.

My current thought is that I will need to get the assistant to always post a link to its generated files to trigger an attached file id. Then it needs to end the run and wait for an automated user-message. In this message, I tell it the file id it can then put into the attribute of the tool call. Finally, in my tool I can use this id to retrieve the file from storage and work with it.

Has anyone tried this before? Is there a better way to do this?