bee-agent-framework icon indicating copy to clipboard operation
bee-agent-framework copied to clipboard

Allow CustomTool to work with files

Open Tomas2D opened this issue 1 year ago • 9 comments

Is your feature request related to a problem? Please describe. Python Code Interpreter (accessible through PythonTool in the framework) can work with files, whereas Custom Python Function (CustomTool) cannot.

Describe the solution you'd like Add the ability to a CustomTool to work files.

Tomas2D avatar Oct 04 '24 16:10 Tomas2D

How it could work:

  • in the Python definition of a custom tool, we introduce a new possible type File which is just an alias to str
  • function can specify an argument to be of type File (or list[File] etc.)
  • when converting File to JSON Schema, we place a placeholder item at that location
  • once constructing the custom tool, we replace the placeholder with the list of available files as an enum
  • for fields that are of type File, we upload the file to the working folder in addition to passing the string to the function

So the custom tool could look like:

import pathlib

def my_function(my_file: File):
   pathlib.Path(my_file).read(...) # my_file would be something like "file.txt", and it would be present in the workdir

@Tomas2D Does this sound reasonable? Should we also try to implement file output, somehow?

JanPokorny avatar Nov 04 '24 18:11 JanPokorny

Perhaps I missed something, but what about reusing the storage concept we use for PythonTool?

Tomas2D avatar Nov 08 '24 09:11 Tomas2D

@Tomas2D Yes, the files will work the same, but will additionally need some extra semantics due to how the users and the LLM expect them to work with regards to input and output of the custom tool. Plus there will be actually two types of files -- "dynamic" (passed in by the caller) and "static" (pre-determined by the tool creator -- many users requested this use-case).

JanPokorny avatar Nov 11 '24 13:11 JanPokorny

Also, I realized that instead of introducing our custom File, we could just piggyback the semantics on top of pathlib.Path.

JanPokorny avatar Nov 11 '24 14:11 JanPokorny

@Tomas2D can you enumerate some examples/use cases that this feature unlocks? cc: @jenna-winkler @sarahmilleribm

geneknit avatar Nov 27 '24 21:11 geneknit

Having file support in a custom tool unlocks a lot of features. For instance, you can build a tool that converts files from one format to another (PDF to DOCX) and so on.

Tomas2D avatar Nov 28 '24 11:11 Tomas2D

@geneknit I'd say that there are three main groups of use cases, split by essentially three different features all falling under the "work with files" umbrella:

  • Static files (supplied by creator, used internally by tool code)
    • SQLite database to query
    • Machine learning model to use
    • ...
  • Input files (supplied by the Bee agent as tool input)
    • File processing / conversion
    • Analysis (summarization etc.)
    • ...
  • Output files (files created by the custom tool, returned to the agent)
    • File processing / conversion
    • Obtaining external files
    • ...

JanPokorny avatar Nov 28 '24 12:11 JanPokorny

What is the current status?

Tomas2D avatar Jan 02 '25 15:01 Tomas2D

@Tomas2D It's going to be a easier to implement with the recent JSONSchema-related improvements in bee-code-interpreter, but no direct progress was made

JanPokorny avatar Jan 02 '25 19:01 JanPokorny

The code interpreter package is not actively maintained; therefore, closing this. cc @jenna-winkler

Tomas2D avatar Jul 10 '25 08:07 Tomas2D