i-am-bee / bee-agent-framework

The framework for building scalable agentic applications.
https://i-am-bee.github.io/bee-agent-framework/
Apache License 2.0
1.06k stars 99 forks source link

Show a better error message for certain custom tool failures #163

Open JanPokorny opened 6 days ago

JanPokorny commented 6 days ago

Custom tool:

def get_matching_resume(job_description: str) -> list:
        """Useful to match and fetch resumes matching the job description.
           The input to this tool should be a string which will be used to get a list of candidate emails

           :param job_description: str, job description that will be used to fetch resumes
           """
        import sys
        import subprocess
        def install(package):
             subprocess.run(f"python -m pip install {package}", shell=True)

        install('pandas')
        install("fuzzywuzzy")

        try:
            from fuzzywuzzy import fuzz
            from sentence_transformers import SentenceTransformer

            import pandas as pd

            print("JD",job_description)
            csv_file = "/Users/username/bee-python/bee-python-sdk/examples/resume.csv"

            data=pd.read_csv(csv_file)
            data["similarity"]=data.apply(lambda x:fuzz.partial_ratio(job_description,x['Category']),axis=1)
            data.sort_values(by=['similarity'],inplace=True,ascending=False)
            data['Full_Resume']="Category : "+data['Category'] +"\n " + "Experience + Skills:" +"\n " + data['Resume']

            return data.head(5)['Email'].values.tolist()

        except Exception as e:
            print("tttt",job_description)
            print(str(e))
            return "Error with the input for the tool."

Log:

| {"level":"warn","time":"2024-11-11T13:07:40.983Z","hostname":"ef2d9f7cd277","name":"bee-api","runId":"run_67320173cf05af8fd2c3f6eb","successCall":{"thought":"The function call was again unsuccessful. I will try to use the function again with a different job description.","tool_name":"get_matching_resume","tool_input":{"job_description":"Python developer with 10+ years of experience"},"tool_caption":"Fetching resumes of Python developers with 10+ years of experience.","tool_output":"The function has failed; the error log is shown below. If the function cannot accomplish what you want, use a different function or explain why you can't use it.\n\nToolError: Tool \"get_matching_resume\" has occurred an error!\n    ConnectError: [unknown] Unexpected <class 'json.decoder.JSONDecodeError'>: Expecting value: line 1 column 1 (char 0)"},"msg":"Agent finished step with missing run step"}
bee-api-1  | {"level":"error","time":"2024-11-11T13:07:41.054Z","hostname":"ef2d9f7cd277","name":"bee-api","runId":"run_67320173cf05af8fd2c3f6eb","err":{"type":"BeeAgentError","message":"Agent was not able to resolve the task in 10 iterations.","stack":"BeeAgentError: Agent was not able to resolve the task in 10 iterations.","aggregateErrors":[],"isFatal":true,"isRetryable":true,"context":{},"name":"BeeAgentError"},"msg":"Run execution failed"}
bee-api-1  | {"level":"info","time":"2024-11-11T13:07:41.061Z","hostname":"ef2d9f7cd277","name":"bee-api","queueName":"runs","job":{"id":"run_67320173cf05af8fd2c3f6eb","name":"runs","data":{"runId":"run_67320173cf05af8fd2c3f6eb"}},"msg":"Job done"}

The actual problem in the user supplied code is that it's trying to access a non-existent file. However, it causes a JSON parsing error. This might actually be an issue with bee-code-interpreter, needs investigation.

Tomas2D commented 5 days ago

I would say that errors are propagated correctly from the framework, but the API does not properly handle them. Please try to reproduce the error in the framework directly without an API.

This can be useful: https://i-am-bee.github.io/bee-agent-framework/#/errors