Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function tool callback #16637

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JoseLuckmann
Copy link
Contributor

Description

This is a feature that allows applying some human-in-the-loop concepts in FunctionTool.

Basically, a callback function is added that enables the developer to request user input in the middle of an agent interaction, as well as allowing any programmatic action.

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran make format; make lint to appease the lint gods

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 22, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

"""Async Call."""
tool_output = self._fn(*args, **kwargs)
final_output_content = str(tool_output)
callback_output = self._run_callback(tool_output)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the callback should be async? Otherwise this will block the event loop (probably not ideal)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my view, yes. We developed this feature so that when a FunctionTool is called, it can request user input that will influence the result or execution of that function.

That said, it makes sense for it not to be asynchronous. However, in our case, we use synchronous calls. If you believe it should be handled asynchronously, I can change it without any problems.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in a lot of use cases, people are using something like fastapi to serve APIs, and you wouldn't want this callback to halt the entire server.

It probably makes sense to let the user provide either a sync or async callback, and llama-index handles converting it either way (if a sync function is provided, we can make it a "fake" async function with a wrapper. If an async function is provided, we can make it sync using from llama_index.core.utils import asyncio_run and using callback_output = asyncio.run(async_fn(tool_output))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopping to evaluate this point, the person who uses an asynchronous call in this case really doesn't make sense conceptually to stop the application.
So whoever uses the asynchronous callback in the asynchronous call will be in a different situation.
I will make the adjustment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants