camel icon indicating copy to clipboard operation
camel copied to clipboard

[Question] Workforce and Task management for production reasoning agent

Open wayne-wang-1119 opened this issue 9 months ago • 1 comments

Required prerequisites

Questions

I am trying to build a multi-hop agent where the tasks contain subtasks and i want to use the task in a workforce. however it seems that workforce only operates on one task, and refreshes the states when another sub task is passed in. how should i achieve:

  1. main task 1.1 step1 1.2 step2 1.3 step3

instead of

  1. main task which you should do step 1 and 2 and 3

for more control and reliability?

wayne-wang-1119 avatar Mar 13 '25 07:03 wayne-wang-1119

Hi, you can structure the Workforce to support context sharing by chaining tasks and passing the result of each step into the additional_info of the next task, as shown below:

import textwrap

# Step 1: Initial Task
step1 = Task(
    content="Step 1: Please research and analyze the project.",
    additional_info=proj_content,
    id="1",
)

# Process Step 1
step1_result = workforce.process_task(step1).result

# Step 2: Use result from Step 1 as additional_info
step2_additional_info = textwrap.dedent(f"""\
    Result from Step 1:
    {step1_result}
""")

step2 = Task(
    content="Step 2: Based on the analysis in Step 1, please perform a technical evaluation.",
    additional_info=step2_additional_info,
    id="2",
)

# Process Step 2
step2_result = workforce.process_task(step2).result

# Step 3: Use result from Step 2 as additional_info
step3_additional_info = textwrap.dedent(f"""\
    Result from Step 2:
    {step2_result}
""")

step3 = Task(
    content="Step 3: Now, based on the previous steps, please provide a final summary and evaluation.",
    additional_info=step3_additional_info,
    id="3",
)

# Process Step 3
step3_result = workforce.process_task(step3).result

# Print final result
print("=== Final Summary ===")
print(step3_result)

nitpicker55555 avatar Mar 29 '25 19:03 nitpicker55555