Skip to content

[BUG] Workflow parent tasks are not passing result to dependent task #734

@Ksaurabh75

Description

@Ksaurabh75

Checks

  • I have updated to the latest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched [./issues](./issues?q=) and there are no duplicates of my issue

Strands Version

1.5.0

Python Version

3.12.4

Operating System

macOS 15.3.1

Installation Method

other

Steps to Reproduce

Run the following code in agent.py:

import os
import uuid
from strands import Agent, tool
from strands_tools import workflow
from strands.models.openai import OpenAIModel

openAIKey = os.getenv("OPENAI_API_KEY")

model = OpenAIModel(
    client_args={
        "api_key": openAIKey,
    },
    model_id="gpt-4o",
    params={
        "max_tokens": 1000,
        "temperature": 0.7,
    }
)

@tool
def get_city_name(state: str) -> str:
    """Get the name of a city in a state.

    Args:
        state: The name of the state
    """
    print(f"Getting the name of the city in {state}")
    return {"content": f"The name of the city in {state} is Jaipur."}

@tool
def get_city_famous_for(city: str) -> str:
    """Get the famous thing about a city.

    Args:
        city: The name of the city
    """
    return {"content": f"The famous thing about {city} is the Hawa Mahal."}

@tool 
def get_city_population(city: str) -> str:
    """Get the population of a city.

    Args:
        city: The name of the city
    """
    return {"content": f"The population of {city} is 1000000."}

# Create an agent with workflow capability
agent = Agent(tools=[get_city_name, get_city_famous_for, get_city_population, workflow], model=model)

# Create a multi-agent workflow
agent.tool.workflow(
    action="create",
    workflow_id="data_analysis",
    tasks=[
        {
            "task_id": "get_city_name",
            "description": "Get the name of a city in a state.",
            "system_prompt": "Your task is to call the get_city_name tool to get the name of a city in a Rajasthan State.",
            "priority": 1,
            "model_provider": "openai",
            "model_settings": {"model_id": "o4-mini", "params": {}},
        },
        {
            "task_id": "get_city_famous_for",
            "description": "Get the famous thing about a city.",
            "dependencies": ["get_city_name"],
            "system_prompt": "use the result of `get_city_name` step, which gives you the city name, then call the `get_city_famous_for` tool to get the famous thing about the city.",
            "priority": 2,
            "model_provider": "openai",
            "model_settings": {"model_id": "o4-mini", "params": {}},
        },
        {
            "task_id": "get_city_population",
            "description": "Get the population of a city.",
            "dependencies": ["get_city_name"],
            "system_prompt": "use the result of `get_city_name` step, which gives you the city name, then call the `get_city_population` tool to get the population of the city.",
            "priority": 2,
            "model_provider": "openai",
            "model_settings": {"model_id": "o4-mini", "params": {}},
        }
    ]
)

# Check results
status = agent.tool.workflow(action="status", workflow_id="data_analysis")

# Execute workflow (parallel processing where possible)
agent.tool.workflow(action="start", workflow_id="data_analysis")

Expected Behavior

The workflow steps should be able to access the tools defined in parent agent and able to call them respectively.

Expected output:

Tool #1: get_city_name
Getting the name of the city in Rajasthan
A city in Rajasthan is Jaipur.
Tool #1: get_city_population

Tool #1: get_city_famous_for
The population of Jaipur is approximately 1,000,000.The famous thing about Jaipur is the Hawa Mahal

Actual Behavior

agent-core-test % python -u my_agent/agent.py

Actual output:

Tool #1: get_city_name
Getting the name of the city in Rajasthan
The city in Rajasthan is Jaipur.Sure—could you please tell me which city you have in mind? If you'd like me to pick a city from a particular state, let me know the state name and I can look up a notable city there and then fetch its population.Sure—could you tell me which U.S. state you're interested in? I'll look up a city in that state and then find out what it's famous for.

Additional Context

The issue happens because when result does not have content attribute, it defaults to [] rather than throwing exception, which means the content is always empty array.

Below is the problematic code:

try:
    content = result.get("content", []) if hasattr(result, "get") else getattr(result, "content", [])
except AttributeError:
    content = [{"text": str(result)}]

Usually the result is output of agent (Previous task agent) which contains a message attribute, which internally contains content. There is no directly property "content" available.

Possible Solution

content = result.get("content") if hasattr(result, "get") else getattr(result, "content")

It should not default to empty array if the respective properties are not present.

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions