Find answers from the community

Updated 3 months ago

Converting Workflows to Tools

At a glance

The post asks if a workflow can be converted to a tool. The comments discuss this, with a community member providing an example of how to create a FunctionTool from an asynchronous workflow function. Another community member notes that this means workflows can be used as tools in the RouterQueryEngine.

There are also questions about whether workflows must be asynchronous, and if the high-level engines like RouterQueryEngine or ReAct Agent will be reimplemented using workflows in the future. A community member responds that while the individual steps can be synchronous or asynchronous, the workflow itself must be asynchronous. They also suggest that the library could benefit from more documentation and pre-built workflows.

There is no explicitly marked answer in the comments.

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