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

feat/async-tools #1720

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

feat/async-tools #1720

wants to merge 7 commits into from

Conversation

ysolanky
Copy link
Contributor

@ysolanky ysolanky commented Jan 8, 2025

Description

Adds support for Async tool execution

Type of change

Please check the options that are 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)
  • Model update
  • Infrastructure change

Checklist

  • My code follows Phidata's style guidelines and best practices
  • I have performed a self-review of my code
  • I have added docstrings and comments for complex logic
  • My changes generate no new warnings or errors
  • I have added cookbook examples for my new addition (if needed)
  • I have updated requirements.txt/pyproject.toml (if needed)
  • I have verified my changes in a clean environment

@@ -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
Copy link
Contributor

@dirkbrnd dirkbrnd Jan 9, 2025

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?

Copy link
Contributor

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

Comment on lines +525 to +526
if self.async_tools:
self.model.async_tools = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Contributor

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]] = ""
Copy link
Contributor

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?

Comment on lines +783 to +804
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)
Copy link
Contributor

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?

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.

3 participants