agents
agents copied to clipboard
Support for function calls that does not wait for the response
The proposal is to be able to define a function like this one:
import time
class TestFunctionContext(llm.FunctionContext):
@llm.ai_callable(wait_for_response=False)
def long_function(self):
# simulate a long running task
time.sleep(10)
⚠️ No Changeset found
Latest commit: 9769a54ac944bc3bce027fa7e8ce2b4d1318b812
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
It seems like you could achieve this by tracking the task yourself; e.g.
def __init__(self):
self._tasks = set()
@llm.ai_callable(wait_for_response=False)
def long_function(self):
# simulate a long running task
task = asyncio.create_task(time.sleep(10)) #wrap your long function in a task.
self._tasks.add(task)
task.add_done_callback(self._tasks.discard)