-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat/async-tools #1720
base: main
Are you sure you want to change the base?
feat/async-tools #1720
Conversation
@@ -125,6 +125,8 @@ class Agent(BaseModel): | |||
# forces the model to call that tool. | |||
# "none" is the default when no tools are present. "auto" is the default if tools are present. | |||
tool_choice: Optional[Union[str, Dict[str, Any]]] = None | |||
# Allow async execution of tools | |||
async_tools: bool = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about async_tool_calling
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ysolanky i think async tool calling should be true by default on arun, it doesnt make sense to ask users to select a flag which boots perf
if self.async_tools: | ||
self.model.async_tools = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.async_tools: | |
self.model.async_tools = True | |
self.model.async_tools = self.async_tools |
# -*- Stop function call timer | ||
function_call_timer.stop() | ||
|
||
for function_call_success, fc in zip(results, function_calls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for function_call_success, fc in zip(results, function_calls): | |
for function_call_success, func_call in zip(results, function_calls): |
for function_call_success, fc in zip(results, function_calls): | ||
function_call_output: Optional[Union[List[Any], str]] = "" | ||
if isinstance(fc.result, (GeneratorType, collections.abc.Iterator)): | ||
for item in fc.result: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just cast the generator output to a list.
function_call_timer.stop() | ||
|
||
for function_call_success, fc in zip(results, function_calls): | ||
function_call_output: Optional[Union[List[Any], str]] = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we really return anything?
if self.async_tools: | ||
if ( | ||
await self.ahandle_tool_calls( | ||
assistant_message=assistant_message, | ||
messages=messages, | ||
model_response=model_response, | ||
tool_role=tool_role, | ||
) | ||
is not None | ||
): | ||
return await self.ahandle_post_tool_call_messages(messages=messages, model_response=model_response) | ||
else: | ||
if ( | ||
self.handle_tool_calls( | ||
assistant_message=assistant_message, | ||
messages=messages, | ||
model_response=model_response, | ||
tool_role=tool_role, | ||
) | ||
is not None | ||
): | ||
return await self.ahandle_post_tool_call_messages(messages=messages, model_response=model_response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a helper in the base?
Description
Adds support for Async tool execution
Type of change
Please check the options that are relevant:
Checklist