Find answers from the community

Updated 3 weeks ago

Converting Workflows to Tools

Can a workflow be converted to a tool?
L
d
4 comments
Plain Text
from llama_index.core.tools import FunctionTool

async def some_workflow(param1: str, param2: int) -> str:
  """Useful for some thing."""
  result = await workflow.run(param1=param1, param2=param2)
  return result

tool= FunctionTool.from_defaults(async_fn=some_workflow)
Awesome, this means I can use a Workflow in RouterQueryEngine as a Tool
I have some queries related to workflows,
  • is it mandatory to have async workflows?
  • will all the high level engines provided by the library like RouterQueryEngine or ReAct Agent be reimplemented using workflows in future?
  1. yes. While the steps themselves can be sync or async, the workflow itself is async. If you need a sync entry point, there are utils in python like asyncio.run() for that
  2. Eh, probably not (although most have examples showing how to do it in the docs). What I'd like more is just increasing the docs focus on workflows, and provided pre-built workflows in the library that make sense
Add a reply
Sign up and join the conversation on Discord