Skip to content

Agentic parallelization mode: parallel tasks repeat in a loop, aggregator/summary never runs, process never completes #874

@mzazakeith

Description

@mzazakeith

When running agentic parallelization, all parallel tasks start and execute, but the same tasks are repeatedly executed in a loop. The aggregator or summary task that depends on the completion of the parallel tasks is never executed, and the process never completes. The workflow must be killed manually. This occurs even with simple, local tools and no LLM or network dependencies.

Issue #864 not fixed

Environment

  • Provider (select one):
    • Anthropic
    • OpenAI
    • Google Vertex AI
    • AWS Bedrock
    • Other:
  • PraisonAI version:
  • Operating System:

Full Code

# agentic_parallelization_example.py

import asyncio
from praisonaiagents import Agent, Task, PraisonAIAgents

# Define a simple tool for demonstration
def square_number(n: int) -> int:
    """Returns the square of a number."""
    return n * n

# Create three agents, each will square a different number
agent1 = Agent(
    name="SquareAgent1",
    role="Squares numbers",
    goal="Square a given number",
    tools=[square_number],
    verbose=True,
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
)
agent2 = Agent(
    name="SquareAgent2",
    role="Squares numbers",
    goal="Square a given number",
    tools=[square_number],
    verbose=True,
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
)
agent3 = Agent(
    name="SquareAgent3",
    role="Squares numbers",
    goal="Square a given number",
    tools=[square_number],
    verbose=True,
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
)

# Aggregator agent to collect and summarize results
aggregator = Agent(
    name="Aggregator",
    role="Result aggregator",
    goal="Collect and summarize squared numbers",
    verbose=True,
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
)

# Define parallel tasks for each agent
task1 = Task(
    name="square_3",
    description="Square the number 3.",
    expected_output="The square of 3.",
    agent=agent1,
    is_start=True,
    async_execution=True
)
task2 = Task(
    name="square_7",
    description="Square the number 7.",
    expected_output="The square of 7.",
    agent=agent2,
    is_start=True,
    async_execution=True
)
task3 = Task(
    name="square_11",
    description="Square the number 11.",
    expected_output="The square of 11.",
    agent=agent3,
    is_start=True,
    async_execution=True
)

# Aggregator task that depends on the results of the above tasks
aggregate_task = Task(
    name="aggregate_results",
    description="Summarize the results of all square tasks.",
    expected_output="A summary of all squared numbers.",
    agent=aggregator,
    context=[task1, task2, task3]
)

async def main():
    # Set up the workflow manager
    workflow = PraisonAIAgents(
        agents=[agent1, agent2, agent3, aggregator],
        tasks=[task1, task2, task3, aggregate_task],
        process="workflow",
        verbose=True
    )

    # Run the workflow
    results = await workflow.astart()

    # Print results
    print("\nParallel Processing Results:")
    for task_id, result in results["task_results"].items():
        if result:
            print(f"Task {task_id}: {result.raw}")

if __name__ == "__main__":
    asyncio.run(main())

or

# agentic_parallelization_varied_tasks.py

import asyncio
from praisonaiagents import Agent, Task, PraisonAIAgents

# Example tools (replace with real implementations as needed)
def fetch_favorite_article():
    # Simulate fetching your favorite morning article
    return "Your favorite morning article: 'How to Start Your Day Right'"

def search_trending_kenya():
    # Simulate searching for trending news in Kenya
    return "Trending in Kenya: 'Kenya launches new tech hub in Nairobi'"

def fetch_twitter_feed():
    # Simulate fetching Twitter feed
    return "Latest tweet: 'AI is transforming the world!'"

# Agents for each unique task
article_agent = Agent(
    name="ArticleAgent",
    role="Morning Article Fetcher",
    goal="Fetch the user's favorite morning article",
    tools=[fetch_favorite_article],
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
    verbose=True
)

news_agent = Agent(
    name="KenyaNewsAgent",
    role="Kenya News Searcher",
    goal="Search for trending news in Kenya",
    tools=[search_trending_kenya],
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
    verbose=True
)

twitter_agent = Agent(
    name="TwitterAgent",
    role="Twitter Feed Fetcher",
    goal="Fetch the latest Twitter feed",
    tools=[fetch_twitter_feed],
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
    verbose=True
)

aggregator = Agent(
    name="Aggregator",
    role="Result Aggregator",
    goal="Aggregate and summarize all results",
    llm="gemini/gemini-2.5-flash-lite-preview-06-17",
    verbose=True
)

# Tasks for each agent
article_task = Task(
    name="fetch_article",
    description="Fetch the user's favorite morning article.",
    expected_output="The favorite morning article.",
    agent=article_agent,
    is_start=True,
    async_execution=True
)

news_task = Task(
    name="search_kenya_news",
    description="Search for trending news in Kenya.",
    expected_output="Trending news in Kenya.",
    agent=news_agent,
    is_start=True,
    async_execution=True
)

twitter_task = Task(
    name="fetch_twitter",
    description="Fetch the latest Twitter feed.",
    expected_output="Latest Twitter feed.",
    agent=twitter_agent,
    is_start=True,
    async_execution=True
)

# Aggregator task that depends on the above tasks
aggregate_task = Task(
    name="aggregate_results",
    description="Summarize the article, news, and Twitter feed results.",
    expected_output="A summary of all fetched information.",
    agent=aggregator,
    context=[article_task, news_task, twitter_task]
)

async def main():
    workflow = PraisonAIAgents(
        agents=[article_agent, news_agent, twitter_agent, aggregator],
        tasks=[article_task, news_task, twitter_task, aggregate_task],
        process="workflow",
        verbose=True
    )
    results = await workflow.astart()

    print("\nParallel Processing Results:")
    for task_id, result in results["task_results"].items():
        if result:
            print(f"Task {task_id}: {result.raw}")

if __name__ == "__main__":
    asyncio.run(main())

Steps to Reproduce

1.install the library
2.copy the scripts above
3. run the scripts

Expected Behavior

Each parallel task should execute once and complete.
After all parallel tasks are done, the aggregator/summary task should execute.
The workflow should finish and exit cleanly, with all results available.
No repeated execution, no infinite loop, and no need to kill the process manually.

Actual Behavior

All parallel tasks (e.g., squaring numbers, fetching articles, etc.) start and run.
The same tasks are then executed again and again in a loop.
The aggregator/summary task that depends on the parallel tasks is never executed.
The process never completes and must be killed manually.
No user code errors are thrown; only repeated execution and shutdown exceptions after manual interruption.

Additional Context

[01:13:20] INFO     [01:13:20] agent.py:1875 INFO Executing async tool:                      agent.py:1875
                    fetch_favorite_article with arguments: {}                                             
╭─────────────────────────────────── Tool Call ───────────────────────────────────╮
│ Agent ArticleAgent called function 'fetch_favorite_article' with arguments: {}  │
│ Function returned: Your favorite morning article: 'How to Start Your Day Right' │
╰─────────────────────────────────────────────────────────────────────────────────╯
[01:13:21] INFO     [01:13:21] agent.py:1875 INFO Executing async tool:                      agent.py:1875
                    search_trending_kenya with arguments: {}                                              
╭─────────────────────────────────── Tool Call ───────────────────────────────────╮
│ Agent KenyaNewsAgent called function 'search_trending_kenya' with arguments: {} │
│ Function returned: Trending in Kenya: 'Kenya launches new tech hub in Nairobi'  │
╰─────────────────────────────────────────────────────────────────────────────────╯
           INFO     [01:13:21] agent.py:1875 INFO Executing async tool: fetch_twitter_feed   agent.py:1875
                    with arguments: {}                                                                    
╭──────────────────────────────── Tool Call ─────────────────────────────────╮
│ Agent TwitterAgent called function 'fetch_twitter_feed' with arguments: {} │
│ Function returned: Latest tweet: 'AI is transforming the world!'           │
╰────────────────────────────────────────────────────────────────────────────╯
Response generated in 2.0s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Fetch the user's favorite morning article.. Expected Output: The    │
│ favorite morning article.. Please provide only the final result of your work. Do not add any           │
│ conversation or extra explanation.                                                                     │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 2.1s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Search for trending news in Kenya. Input data from previous tasks:. │
│ Expected Output: Trending news in Kenya..                                                              │
│                                                                                                        │
│ Context:                                                                                               │
│                                                                                                        │
│ Previous task fetch_article is not yet completed (status: in progress). Please provide only the final  │
│ result of your work. Do not add any conversation or extra explanation.                                 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
│ .                                                                                                      │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 2.3s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Fetch the latest Twitter feed. Input data from previous tasks:.     │
│ Expected Output: Latest Twitter feed..                                                                 │
│                                                                                                        │
│ Context:                                                                                               │
│                                                                                                        │
│ Previous task search_kenya_news is not yet completed (status: in progress). Please provide only the    │
│ final result of your work. Do not add any conversation or extra explanation.                           │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
[01:13:22] INFO     [01:13:22] llm.py:1117 INFO Getting async response from                    llm.py:1117
                    gemini/gemini-2.5-flash-lite-preview-06-17                                            
[01:13:23] INFO     [01:13:23] llm.py:1117 INFO Getting async response from                    llm.py:1117
                    gemini/gemini-2.5-flash-lite-preview-06-17                                            
           INFO     [01:13:23] agent.py:1875 INFO Executing async tool:                      agent.py:1875
                    fetch_favorite_article with arguments: {}                                             
╭─────────────────────────────────── Tool Call ───────────────────────────────────╮
│ Agent ArticleAgent called function 'fetch_favorite_article' with arguments: {}  │
│ Function returned: Your favorite morning article: 'How to Start Your Day Right' │
╰─────────────────────────────────────────────────────────────────────────────────╯
           INFO     [01:13:23] agent.py:1875 INFO Executing async tool: fetch_twitter_feed   agent.py:1875
                    with arguments: {}                                                                    
╭──────────────────────────────── Tool Call ─────────────────────────────────╮
│ Agent TwitterAgent called function 'fetch_twitter_feed' with arguments: {} │
│ Function returned: Latest tweet: 'AI is transforming the world!'           │
╰────────────────────────────────────────────────────────────────────────────╯
Response generated in 1.4s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Fetch the user's favorite morning article.. Expected Output: The    │
│ favorite morning article.. Please provide only the final result of your work. Do not add any           │
│ conversation or extra explanation.                                                                     │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 1.4s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Fetch the latest Twitter feed. Input data from previous tasks:.     │
│ Expected Output: Latest Twitter feed..                                                                 │
│                                                                                                        │
│ Context:                                                                                               │
│                                                                                                        │
│ Result of previous task search_kenya_news: . Please provide only the final result of your work. Do not │
│ add any conversation or extra explanation.                                                             │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────

and

[01:10:30] INFO     [01:10:30] agent.py:1875 INFO Executing async tool: square_number with   agent.py:1875
                    arguments: {'n': 3}                                                                   
╭───────────────────────────────── Tool Call ─────────────────────────────────╮
│ Agent SquareAgent1 called function 'square_number' with arguments: {'n': 3} │
│ Function returned: 9                                                        │
╰─────────────────────────────────────────────────────────────────────────────╯
           INFO     [01:10:30] agent.py:1875 INFO Executing async tool: square_number with   agent.py:1875
                    arguments: {'n': 7}                                                                   
╭───────────────────────────────── Tool Call ─────────────────────────────────╮
│ Agent SquareAgent2 called function 'square_number' with arguments: {'n': 7} │
│ Function returned: 49                                                       │
╰─────────────────────────────────────────────────────────────────────────────╯
           INFO     [01:10:30] agent.py:1875 INFO Executing async tool: square_number with   agent.py:1875
                    arguments: {'n': 11}                                                                  
╭───────────────────────────────── Tool Call ──────────────────────────────────╮
│ Agent SquareAgent3 called function 'square_number' with arguments: {'n': 11} │
│ Function returned: 121                                                       │
╰──────────────────────────────────────────────────────────────────────────────╯
Response generated in 1.8s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Square the number 3.. Expected Output: The square of 3.. Please     │
│ provide only the final result of your work. Do not add any conversation or extra explanation.          │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 2.3s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Square the number 11. Input data from previous tasks:. Expected     │
│ Output: The square of 11..                                                                             │
│                                                                                                        │
│ Context:                                                                                               │
│                                                                                                        │
│ Previous task square_7 is not yet completed (status: in progress). Please provide only the final       │
│ result of your work. Do not add any conversation or extra explanation.                                 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 2.3s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Square the number 7. Input data from previous tasks:. Expected      │
│ Output: The square of 7..                                                                              │
│                                                                                                        │
│ Context:                                                                                               │
│                                                                                                        │
│ Previous task square_3 is not yet completed (status: in progress). Please provide only the final       │
│ result of your work. Do not add any conversation or extra explanation.                                 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
[01:10:32] INFO     [01:10:32] llm.py:1117 INFO Getting async response from                    llm.py:1117
                    gemini/gemini-2.5-flash-lite-preview-06-17                                            
           INFO     [01:10:32] llm.py:1117 INFO Getting async response from                    llm.py:1117
                    gemini/gemini-2.5-flash-lite-preview-06-17                                            
           INFO     [01:10:32] llm.py:1117 INFO Getting async response from                    llm.py:1117
                    gemini/gemini-2.5-flash-lite-preview-06-17                                            
           INFO     [01:10:32] agent.py:1875 INFO Executing async tool: square_number with   agent.py:1875
                    arguments: {'n': 3}                                                                   
╭───────────────────────────────── Tool Call ─────────────────────────────────╮
│ Agent SquareAgent1 called function 'square_number' with arguments: {'n': 3} │
│ Function returned: 9                                                        │
╰─────────────────────────────────────────────────────────────────────────────╯
[01:10:33] INFO     [01:10:33] agent.py:1875 INFO Executing async tool: square_number with   agent.py:1875
                    arguments: {'n': 11}                                                                  
╭───────────────────────────────── Tool Call ──────────────────────────────────╮
│ Agent SquareAgent3 called function 'square_number' with arguments: {'n': 11} │
│ Function returned: 121                                                       │
╰──────────────────────────────────────────────────────────────────────────────╯
           INFO     [01:10:33] agent.py:1875 INFO Executing async tool: square_number with   agent.py:1875
                    arguments: {'n': 7}                                                                   
╭───────────────────────────────── Tool Call ─────────────────────────────────╮
│ Agent SquareAgent2 called function 'square_number' with arguments: {'n': 7} │
│ Function returned: 49                                                       │
╰─────────────────────────────────────────────────────────────────────────────╯
Response generated in 1.5s
╭───────────────────────────────────────────────── Task ─────────────────────────────────────────────────╮
│ You need to do the following task: Square the number 3.. Expected Output: The square of 3.. Please     │
│ provide only the final result of your work. Do not add any conversation or extra explanation.          │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────── Response ───────────────────────────────────────────────╮
╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Reflecting... 1.1s

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions