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

Allow to use async tools within the task pipeline #550

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

Conversation

tg1482
Copy link

@tg1482 tg1482 commented May 2, 2024

Introduces a way to use async tools seamlessly within a crew task.

@tg1482 tg1482 changed the title async Allow to use async tools within the task pipeline May 2, 2024
@joaomdmoura
Copy link
Owner

Interesting, would love to hear more about the use case that prompted this given the async_exec attribute on task :)

@joaomdmoura
Copy link
Owner

@tg1482
Copy link
Author

tg1482 commented May 2, 2024

Wow thanks for your promptness. One of the things we wanted to do was to give the agents the ability to talk to the users to ask clarifying questions directly using the websockets that we provide them. So we made a tool that allows the agent to ask questions and wait for a response from the user. But we don't want to exit the task pipeline since that will take a little longer + more openai api calls.

This is also helpful for some tools where the agent prepares a draft email for instance, but wants to wait for the user confirmation before proceeding to send it. The tool has to await a response before proceeding - so this async allows for that. Its not just for the task to be async, but rather the Tools to be async.

Ideally we could just make the the default kickoff with the async code that I added - since that can be used with async tool and regular old sync tools. So far in our product, we've been doing exactly that - so it saves us a lot of redundancy. But for that, every other crewai user will have to change crew.kickoff to await crew.kickoff which is why it seemed more prudent to just create a new method called akickoff.

@joaomdmoura
Copy link
Owner

Oh got it, something more complex then the current human input on execution? basically that but over sockets.
I assume in this case the new task could be processed while the current one awaits the input?

@tg1482
Copy link
Author

tg1482 commented May 2, 2024

Yes exactly - we can do as many new tasks while waiting for a response on a previous task.

I see that the human input was added recently - you guys are working at 🚀 speed - I'll take a look at it deeper.

But the basic idea of having async tools remains the same - opening up the crew to use a lot more complex tools - including taking over sockets / performing non-blocking api requests / etc.

@joaomdmoura
Copy link
Owner

got it! Any chance you would make this socket human input tool public? :D no pressure but I'd love to add it to crewai-tool or find a way to bring them into the main package somehow

@joaomdmoura
Copy link
Owner

This is a big change so I'll test is a little myself before merging just in case but I like the problem it aims to solve

@tg1482
Copy link
Author

tg1482 commented May 2, 2024

Amazing - appreciate any feedback on it and ideas on how to make the code a little less redundant - since most of it is just about adding an await in the right places. And detecting whether the tool is a coroutine or not and then deciding to use _run or await _run.

@tg1482
Copy link
Author

tg1482 commented May 2, 2024

And certainly, I'll try and add the socket human input in a following PR but that part is a little more coupled with my current infra setup haha so could be tough. But I agree, would be a great addition to the crewai toolkit

@tg1482
Copy link
Author

tg1482 commented May 2, 2024

I've added a quick crew_test but I'm unable to get it to run locally. But hopefully it'll be quick enough for you to take a look + adding some resiliency! Thanks again! Please let me know if I can help in any way!

@davidlandais
Copy link

Hello! I just came across this MR. I found out about CrewAI from a video on agentic workflow. I'm also interested in being able to intervene during a workflow. I prefer that the AI asks me questions, probes me so that I myself can be an agent influencing the final outcome. Have you considered using messaging tools like Slack, Discord, or Telegram? I assume your websocket tool is homemade? Would a workflow that uses a database to save its state to resume its process later be an interesting topic to explore for CrewAI?

@tg1482
Copy link
Author

tg1482 commented May 2, 2024

Yep the reason I wanted to add async tools was so that I can connect my agents to websockets that connect to Slack + RetellAI voice. So I give each agent a tool AskUserQuestionTool which is an async tool and initialize that with a websocket. So if the agent needs any info from the user, it uses that tool and waits for a response. It can then ask a question either on Slack / Discord or if we have a voice connection, can speak the question etc.

@thehapyone
Copy link
Contributor

I think this native support for async will be really nice to have considering most of the LLM already supports this. I was hoping to integrate CrewAI has the Agent framework for Sage https://github.com/thehapyone/Sage
but the lack of async support is a bit blocking.

Alternatively, asyncify is one hack package that can be used to create a sync version of this

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.

None yet

4 participants