OWASP / OWASP/Nest

Duplicate CrewAI Workflow Execution Causes Excessive LLM/API Calls

Open
#4,778 2 comments 0 reactions 1 assignee Claimed by @Nachiket-Roy View on GitHub
bug enhancement question
Dominant language
Python
Stars
451
Forks
707
Avg merge
22h 59m
Merged PRs (30d)
91

Description

**Describe the bug**

A double execution issue exists in the Slack background worker task `generate_ai_reply_if_unanswered`, causing the full CrewAI multi-agent workflow to execute twice for a single user query.

The issue occurs because after generating an AI response using `process_ai_query(query=message.text)`, the generated response (`ai_response_text`) is passed as the first argument to `get_blocks()`:

```python
client.chat_postMessage(
channel=channel_id,
blocks=get_blocks(ai_response_text, channel_id=channel_id),
text=ai_response_text,
thread_ts=message.slack_message_id,
)
```

However, `get_blocks()` treats its first argument as a new user query and internally calls `process_ai_query()` again:

```python
ai_response = process_ai_query(
query.strip(),
images=images,
channel_id=channel_id,
is_app_mention=is_app_mention
)
```

This causes the complete CrewAI pipeline (Query Analyzer → Router Agent → Expert/Collaborative Agents → Synthesizer) to run a second time using the bot's generated response as input.

Impact:

* Doubles LLM/API usage for every background-processed query
* Increases latency and operational cost
* May produce incorrect formatting or clarification-style responses because the generated markdown response is interpreted as a new user question

## Expected behavior

The CrewAI workflow should execute only once per user query.

`get_blocks()` should format the already-generated response without re-processing it through `process_ai_query()`.

---

## Are you going to work on fixing this?

* [x] Yes
* [ ] No

## Additional context

This issue becomes significantly more expensive with collaborative flows and query decomposition enabled because a single query may already trigger multiple agent/tool executions. The unintended second execution compounds token usage, latency, and overall API cost across the entire CrewAI pipeline.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.