Skip to content

Conversation

ShyamSathish005
Copy link

Fixes #63

Fix the TypeError: cannot pickle 'generator' object by updating the LongRunningFunctionTool and Runner class to handle list objects instead of generator objects.

  • src/google/adk/tools/long_running_tool.py

    • Update LongRunningFunctionTool to handle list objects instead of generator objects.
    • Add run_async method to convert generator results to list.
  • src/google/adk/tests/unittests/tools/test_long_running_tool.py

    • Add unit tests for LongRunningFunctionTool to ensure it handles list objects and generator objects properly.
  • src/google/adk/tests/unittests/runners/test_runner.py

    • Add unit tests for Runner class to ensure it accounts for list objects in its run_async method.

Fixes google#63

Fix the `TypeError: cannot pickle 'generator' object` by updating the `LongRunningFunctionTool` and `Runner` class to handle list objects instead of generator objects.

* **src/google/adk/tools/long_running_tool.py**
  - Update `LongRunningFunctionTool` to handle list objects instead of generator objects.
  - Add `run_async` method to convert generator results to list.

* **src/google/adk/tests/unittests/tools/test_long_running_tool.py**
  - Add unit tests for `LongRunningFunctionTool` to ensure it handles list objects and generator objects properly.

* **src/google/adk/tests/unittests/runners/test_runner.py**
  - Add unit tests for `Runner` class to ensure it accounts for list objects in its `run_async` method.
@Jeroen-Beljaars
Copy link

Won't adding this make it wait for the generator to be completely done?

@ShyamSathish005
Copy link
Author

Well... Yes, converting the generator to a list does mean we’ll have to wait for the generator to finish completely before the code can continue. It’s necessary to fix that TypeError: cannot pickle 'generator' object since lists can be pickled but generators can’t. Will come up with a better sol.

@Jeroen-Beljaars
Copy link

Yes that's true. However that would beat the purpose of the LongRunningFunctionTool right. Where each yielded result should be fed back to the LLM right away.

Nonetheless, i've also looked into the code but from what I am seeing, quite a few things have been missed for the LongRunningFunctionTool to work.

@boyangsvl
Copy link
Collaborator

LongRunningTool document has been updated with details. It used to suggest returning a generator which was not the proper way of using long running tools. I will close this PR as it no longer applies. See here for more info: https://google.github.io/adk-docs/tools/function-tools/#2-long-running-function-tool

@boyangsvl boyangsvl closed this May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: cannot pickle 'generator' object
3 participants