Find answers from the community

Updated last year

task processing chains

More of a pure langchain question but llamaindex may also have its own solution here.
trying to wrap my head around how to do something:
I'm submitting a question via RAG which gets turned into a list of tasks:
  1. do a thing
  2. do some other thing
for each step I am trying to:
  1. figure out if the original question has enough information to complete the task
  2. if it does, perform the task (via the LLM)
  3. pass the original question, the output of the task, and the next step along
  4. see if there is enough information to complete the next task
and kind of stay in that loop until everything is complete. then put itall together and send back to the user.
t
L
33 comments
i have very ugly python that kinda does 1-2 and part of 3 but the "continue and pass forward" part is where i'm falling down
This sounds very vaguely like a react agent loop πŸ™‚

pass the original question, the output of the task, and the next step along what does this mean? You want to use this info in the next task? Or you want to keep this info until all tasks are complete?
the current example is the following
Original prompt: How do I configure my cluster for autoscaling up to a maximum of 10 nodes?
we use RAG to pull a summary document, that document is sent to an LLM for further summarization, and it returns a task list:
Plain Text
    task_list = [
        "1. Determine the maximum number of nodes desired for the cluster.",
        "2. Create a ClusterAutoscaler that specifies the size of the cluster.",
        "3. Create a MachineAutoscaler object to specify which MachineSet should be scale and the minimum and maximum number of replicas.",
    ]
we process the first task --
ask an LLM: is there enough information to do step 1?
oh, yes, there is? OK. actually do it.
Task Output: the maximum number of nodes is 10
(or similar)
then the next step would be "create a cluster autoscaler..."
and we want to pass the original query plus the answer from step 1
given the question 'how do I configure my cluster...' and the following information:
  • the maximum number of nodes is 10
do you have enough information to perform the task:
create a autoscaler...
yes? ok, great. create an autoscaler given blahblah
(interestingly, the create an autoscaler step needs to go to a different YAML generation model, but don't worry about that for now)
task_processor is where some of this logic lives
seems like once you have existing task outputs, you need to switch to a template that also includes the previous tasks+results?
The python looks pretty good btw, easy to understand
thanks. it's my first "real" python project
seems like once you have existing task outputs, you need to switch to a template that also includes the previous tasks+results?
maybe not the previous tasks, but definitely the results
if we back up to less-specific details:

  • i get a question from a user
  • I look up in a document index for a relevant task summary
  • i iterate over the tasks, perform each task (if possible) and then feed all the state to the next task (in case it's relevant)
  • once all tasks are complete, return the whole hot mess to the user
Q. How do I make such and such a sandwich?
RAG: this sandwich requires:
  1. choose bread
  2. gather ingredients
  3. Place ingredients on bread
(some kind of processing loop)
self-Q: Can I figure out what bread is needed?
self-A: yes, it's wheat bread
self-Q: I need wheat bread, and can I figure out what other ingredients I need?
self-A: yes, it's a ham and cheese sandwich.

or something like that
Does this make any sense?
Yea that makes total sense!
By the looks of it, you are nearly there. Just some minor adjustments to the processing loop and it's pretty much ready
so you think that this really is a case for "more python"?
(as opposed to some existing agent)
I think so? This kind of structured flow seems easiest to manage by creating your own chain of prompts to an LLM πŸ€” Some existing frameworks might make this easier, but also it's simple enough you probably don't need more dependencies
generally speaking if i find myself in a situation whre i need to write more code, i automatically expect that i am doing it wrong, and that someone beat me to it
i'll do some more poking around
ha fair enough. There's a trade-off between writing it yourself vs. letting some library hide things from you.

In my personal opinion in this case, hiding the details seems like something that will make things more confusing. Since it's just a prompt + parsing an output to make a decision
dspy could maybe help with some bits, was watching the latest webinar for it
will take a look, thanks
Add a reply
Sign up and join the conversation on Discord