|
| 1 | +# Workflow Executor Agent |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +GenAI Workflow Executor Example showcases the capability to handle data/AI workflow operations via LangChain agents to execute custom-defined workflow-based tools. These workflow tools can be interfaced from any 3rd-party tools in the market (no-code/low-code/IDE) such as Alteryx, RapidMiner, Power BI, Intel Data Insight Automation which allows users to create complex data/AI workflow operations for different use-cases. |
| 6 | + |
| 7 | +### Workflow Executor |
| 8 | + |
| 9 | +This example demonstrates a single React-LangGraph with a `Workflow Executor` tool to ingest a user prompt to execute workflows and return an agent reasoning response based on the workflow output data. |
| 10 | + |
| 11 | +First the LLM extracts the relevant information from the user query based on the schema of the tool in `tools/tools.yaml`. Then the agent sends this `AgentState` to the `Workflow Executor` tool. |
| 12 | + |
| 13 | +`Workflow Executor` tool uses `EasyDataSDK` class as seen under `tools/sdk.py` to interface with several high-level API's. There are 3 steps to this tool implementation: |
| 14 | + |
| 15 | +1. Starts the workflow with workflow parameters and workflow id extracted from the user query. |
| 16 | + |
| 17 | +2. Periodically checks the workflow status for completion or failure. This may be through a database which stores the current status of the workflow |
| 18 | + |
| 19 | +3. Retrieves the output data from the workflow through a storage service. |
| 20 | + |
| 21 | +The `AgentState` is sent back to the LLM for reasoning. Based on the output data, the LLM generates a response to answer the user's input prompt. |
| 22 | + |
| 23 | +Below shows an illustration of this flow: |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +### Workflow Serving for Agent |
| 28 | + |
| 29 | +As an example, here we have a Churn Prediction use-case workflow as the serving workflow for the agent execution. It is created through Intel Data Insight Automation platform. The image below shows a snapshot of the Churn Prediction workflow. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +The workflow contains 2 paths which can be seen in the workflow illustrated, the top path and bottom path. |
| 34 | + |
| 35 | +1. Top path - The training path which ends at the random forest classifier node is the training path. The data is cleaned through a series of nodes and used to train a random forest model for prediction. |
| 36 | + |
| 37 | +2. Bottom path - The inference path where trained random forest model is used for inferencing based on input parameter. |
| 38 | + |
| 39 | +For this agent workflow execution, the inferencing path is executed to yield the final output result of the `Model Predictor` node. The same output is returned to the `Workflow Executor` tool through the `Langchain API Serving` node. |
| 40 | + |
| 41 | +There are `Serving Parameters` in the workflow, which are the tool input variables used to start a workflow instance obtained from `params` the LLM extracts from the user query. Below shows the parameter configuration option for the Intel Data Insight Automation workflow UI. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +Manually running the workflow yields the tabular data output as shown below: |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +In the workflow serving for agent, this output will be returned to the `Workflow Executor` tool. The LLM can then answer the user's original question based on this output. |
| 50 | + |
| 51 | +To start prompting the agent microservice, we will use the following command for this use case: |
| 52 | + |
| 53 | +```sh |
| 54 | +curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{ |
| 55 | + "query": "I have a data with gender Female, tenure 55, MonthlyAvgCharges 103.7. Predict if this entry will churn. My workflow id is '${workflow_id}'." |
| 56 | + }' |
| 57 | +``` |
| 58 | + |
| 59 | +The user has to provide a `workflow_id` and workflow `params` in the query. `workflow_id` a unique id used for serving the workflow to the microservice. Notice that the `query` string includes all the workflow `params` which the user has defined in the workflow. The LLM will extract these parameters into a dictionary format for the workflow `Serving Parameters` as shown below: |
| 60 | + |
| 61 | +```python |
| 62 | +params = {"gender": "Female", "tenure": 55, "MonthlyAvgCharges": 103.7} |
| 63 | +``` |
| 64 | + |
| 65 | +These parameters will be passed into the `Workflow Executor` tool to start the workflow execution of specified `workflow_id`. Thus, everything will be handled via the microservice. |
| 66 | + |
| 67 | +And finally here are the results from the microservice logs: |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +## Microservice Setup |
| 72 | + |
| 73 | +### Start Agent Microservice |
| 74 | + |
| 75 | +Workflow Executor will have a single docker image. First, build the agent docker image. |
| 76 | + |
| 77 | +```sh |
| 78 | +git clone https://github.com/opea-project/GenAIExamples.git |
| 79 | +cd GenAIExamples//WorkflowExecAgent/docker_image_build/ |
| 80 | +docker compose -f build.yaml build --no-cache |
| 81 | +``` |
| 82 | + |
| 83 | +Configure `GenAIExamples/WorkflowExecAgent/docker_compose/.env` file with the following. Replace the variables according to your usecase. |
| 84 | + |
| 85 | +```sh |
| 86 | +export SDK_BASE_URL=${SDK_BASE_URL} |
| 87 | +export SERVING_TOKEN=${SERVING_TOKEN} |
| 88 | +export HUGGINGFACEHUB_API_TOKEN=${HF_TOKEN} |
| 89 | +export llm_engine=${llm_engine} |
| 90 | +export llm_endpoint_url=${llm_endpoint_url} |
| 91 | +export ip_address=$(hostname -I | awk '{print $1}') |
| 92 | +export model="mistralai/Mistral-7B-Instruct-v0.3" |
| 93 | +export recursion_limit=${recursion_limit} |
| 94 | +export temperature=0 |
| 95 | +export max_new_tokens=1000 |
| 96 | +export WORKDIR=${WORKDIR} |
| 97 | +export TOOLSET_PATH=$WORKDIR/GenAIExamples/WorkflowExecAgent/tools/ |
| 98 | +export http_proxy=${http_proxy} |
| 99 | +export https_proxy=${https_proxy} |
| 100 | +``` |
| 101 | + |
| 102 | +Launch service by running the docker compose command. |
| 103 | + |
| 104 | +```sh |
| 105 | +cd $WORKDIR/GenAIExamples/WorkflowExecAgent/docker_compose |
| 106 | +docker compose -f compose.yaml up -d |
| 107 | +``` |
| 108 | + |
| 109 | +### Validate service |
| 110 | + |
| 111 | +The microservice logs can be viewed using: |
| 112 | + |
| 113 | +```sh |
| 114 | +docker logs workflowexec-agent-endpoint |
| 115 | +``` |
| 116 | + |
| 117 | +You should be able to see "HTTP server setup successful" upon successful startup. |
| 118 | + |
| 119 | +You can validate the service using the following command: |
| 120 | + |
| 121 | +```sh |
| 122 | +curl http://${ip_address}:9090/v1/chat/completions -X POST -H "Content-Type: application/json" -d '{ |
| 123 | + "query": "I have a data with gender Female, tenure 55, MonthlyAvgCharges 103.7. Predict if this entry will churn. My workflow id is '${workflow_id}'." |
| 124 | + }' |
| 125 | +``` |
| 126 | + |
| 127 | +Update the `query` with the workflow parameters, workflow id, etc based on the workflow context. |
| 128 | + |
| 129 | +## Roadmap |
| 130 | + |
| 131 | +Phase II: Agent memory integration to enable capability to store tool intermediate results, such as workflow instance key. |
0 commit comments