|
22 | 22 | As an illustrative example, let's consider a naive workflow where a joke is generated and then critiqued.
|
23 | 23 |
|
24 | 24 | ```python
|
25 |
| -from llama_index.core.workflow import ( |
| 25 | +from workflows import Workflow, step |
| 26 | +from workflows.events import ( |
26 | 27 | Event,
|
27 | 28 | StartEvent,
|
28 | 29 | StopEvent,
|
29 |
| - Workflow, |
30 |
| - step, |
31 | 30 | )
|
32 | 31 |
|
33 | 32 | # `pip install llama-index-llms-openai` if you don't already have it
|
@@ -158,12 +157,11 @@ You can also decorate and attach steps to a workflow without subclassing it.
|
158 | 157 | Below is the `JokeFlow` from earlier, but defined without subclassing.
|
159 | 158 |
|
160 | 159 | ```python
|
161 |
| -from llama_index.core.workflow import ( |
| 160 | +from workflows import Workflow, step |
| 161 | +from workflows.events import ( |
162 | 162 | Event,
|
163 | 163 | StartEvent,
|
164 | 164 | StopEvent,
|
165 |
| - Workflow, |
166 |
| - step, |
167 | 165 | )
|
168 | 166 | from llama_index.llms.openai import OpenAI
|
169 | 167 |
|
@@ -196,3 +194,51 @@ async def critique_joke(ev: JokeEvent) -> StopEvent:
|
196 | 194 | response = await llm.acomplete(prompt)
|
197 | 195 | return StopEvent(result=str(response))
|
198 | 196 | ```
|
| 197 | + |
| 198 | +## Examples |
| 199 | + |
| 200 | +To help you become more familiar with the workflow concept and its features, LlamaIndex documentation offers example |
| 201 | +notebooks that you can run for hands-on learning: |
| 202 | + |
| 203 | +- [Common Workflow Patterns](../../examples/workflow/workflows_cookbook.ipynb) walks you through common usage patterns |
| 204 | +like looping and state management using simple workflows. It's usually a great place to start. |
| 205 | +- [RAG + Reranking](../../examples/workflow/rag.ipynb) shows how to implement a real-world use case with a fairly |
| 206 | +simple workflow that performs both ingestion and querying. |
| 207 | +- [Citation Query Engine](../../examples/workflow/citation_query_engine.ipynb) similar to RAG + Reranking, the |
| 208 | +notebook focuses on how to implement intermediate steps in between retrieval and generation. A good example of how to |
| 209 | +use the [`Context`](#working-with-global-context-state) object in a workflow. |
| 210 | +- [Corrective RAG](../../examples/workflow/corrective_rag_pack.ipynb) adds some more complexity on top of a RAG |
| 211 | +workflow, showcasing how to query a web search engine after an evaluation step. |
| 212 | +- [Utilizing Concurrency](../../examples/workflow/parallel_execution.ipynb) explains how to manage the parallel |
| 213 | +execution of steps in a workflow, something that's important to know as your workflows grow in complexity. |
| 214 | + |
| 215 | +RAG applications are easy to understand and offer a great opportunity to learn the basics of workflows. However, more complex agentic scenarios involving tool calling, memory, and routing are where workflows excel. |
| 216 | + |
| 217 | +The examples below highlight some of these use-cases. |
| 218 | + |
| 219 | +- [ReAct Agent](../../examples/workflow/react_agent.ipynb) is obviously the perfect example to show how to implement |
| 220 | +tools in a workflow. |
| 221 | +- [Function Calling Agent](../../examples/workflow/function_calling_agent.ipynb) is a great example of how to use the |
| 222 | +LlamaIndex framework primitives in a workflow, keeping it small and tidy even in complex scenarios like function |
| 223 | +calling. |
| 224 | +- [CodeAct Agent](../../examples/agent/from_scratch_code_act_agent.ipynb) is a great example of how to create a CodeAct Agent from scratch. |
| 225 | +- [Human In The Loop: Story Crafting](../../examples/workflow/human_in_the_loop_story_crafting.ipynb) is a powerful |
| 226 | +example showing how workflow runs can be interactive and stateful. In this case, to collect input from a human. |
| 227 | +- [Reliable Structured Generation](../../examples/workflow/reflection.ipynb) shows how to implement loops in a |
| 228 | +workflow, in this case to improve structured output through reflection. |
| 229 | +- [Query Planning with Workflows](../../examples/workflow/planning_workflow.ipynb) is an example of a workflow |
| 230 | +that plans a query by breaking it down into smaller items, and executing those smaller items. It highlights how |
| 231 | +to stream events from a workflow, execute steps in parallel, and looping until a condition is met. |
| 232 | +- [Checkpointing Workflows](../../examples/workflow/checkpointing_workflows.ipynb) is a more exhaustive demonstration of how to make full use of `WorkflowCheckpointer` to checkpoint Workflow runs. |
| 233 | + |
| 234 | +Last but not least, a few more advanced use cases that demonstrate how workflows can be extremely handy if you need |
| 235 | +to quickly implement prototypes, for example from literature: |
| 236 | + |
| 237 | +- [Advanced Text-to-SQL](../../examples/workflow/advanced_text_to_sql.ipynb) |
| 238 | +- [JSON Query Engine](../../examples/workflow/JSONalyze_query_engine.ipynb) |
| 239 | +- [Long RAG](../../examples/workflow/long_rag_pack.ipynb) |
| 240 | +- [Multi-Step Query Engine](../../examples/workflow/multi_step_query_engine.ipynb) |
| 241 | +- [Multi-Strategy Workflow](../../examples/workflow/multi_strategy_workflow.ipynb) |
| 242 | +- [Router Query Engine](../../examples/workflow/router_query_engine.ipynb) |
| 243 | +- [Self Discover Workflow](../../examples/workflow/self_discover_workflow.ipynb) |
| 244 | +- [Sub-Question Query Engine](../../examples/workflow/sub_question_query_engine.ipynb) |
0 commit comments