workflow tool not stream output in chat workflow #5527

Closed
opened 2026-02-21 18:11:28 -05:00 by yindo · 2 comments
Owner

Originally created by @kenneth-bro on GitHub (Sep 10, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

The workflow tool does not need to be output in a stream in the Chat workflow. It can only be output by blocking.
image

✔️ Expected Behavior

Can be stream output

Actual Behavior

No response

Originally created by @kenneth-bro on GitHub (Sep 10, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce The workflow tool does not need to be output in a stream in the Chat workflow. It can only be output by blocking. ![image](https://github.com/user-attachments/assets/c18aa4e0-8a85-427a-84e1-6baf531407b1) ### ✔️ Expected Behavior Can be stream output ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:11:28 -05:00
yindo closed this issue 2026-02-21 18:11:28 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 10, 2024):

I found a similar unsolved discussion: How can I disable streaming output for tools/steps with a provider not supporting streaming? [1].

Additionally, the default behavior for output streaming in the Dify workflow tool is "streaming" mode. This behavior is configured in the request body of the POST /workflows/run endpoint, where the response_mode parameter is set to "streaming" [2].

To modify the output behavior from streaming to blocking, you can adjust the response_mode parameter in your API request. Here is an example of how to set it to "blocking":

curl -X POST '${props.appDetail.api_base_url}/workflows/run' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {},
    "response_mode": "blocking",
    "user": "abc-123"
}'

In the codebase, this logic is implemented in the createChatMessage method of the ChatClient class and the sendRequest method of the DifyClient class. Here is the relevant code snippet from the ChatClient class:

export class ChatClient extends DifyClient {
  createChatMessage(
    inputs,
    query,
    user,
    stream = false,
    conversation_id = null,
    files = null
  ) {
    const data = {
      inputs,
      query,
      user,
      response_mode: stream ? "streaming" : "blocking",
      files,
    };
    if (conversation_id) data.conversation_id = conversation_id;

    return this.sendRequest(
      routes.createChatMessage.method,
      routes.createChatMessage.url(),
      data,
      null,
      stream
    );
  }
}

And the sendRequest method in the DifyClient class:

async sendRequest(
  method,
  endpoint,
  data = null,
  params = null,
  stream = false,
  headerParams = {}
) {
  const headers = {
    ...{
      Authorization: `Bearer ${this.apiKey}`,
      "Content-Type": "application/json",
    },
    ...headerParams
  };

  const url = `${this.baseUrl}${endpoint}`;
  let response;
  if (stream) {
    response = await axios({
      method,
      url,
      data,
      params,
      headers,
      responseType: "stream",
    });
  } else {
    response = await axios({
      method,
      url,
      ...(method !== "GET" && { data }),
      params,
      headers,
      responseType: "json",
    });
  }

  return response;
}

By setting the response_mode to "blocking" in your API request, you can ensure that the workflow tool does not output in a stream in the chat workflow [3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 10, 2024): <!-- Answer --> I found a similar unsolved discussion: [How can I disable streaming output for tools/steps with a provider not supporting streaming?](https://github.com/langgenius/dify/discussions/7109) <sup>[[1]](https://github.com/langgenius/dify/discussions/7109)</sup>. Additionally, the default behavior for output streaming in the Dify workflow tool is "streaming" mode. This behavior is configured in the request body of the `POST /workflows/run` endpoint, where the `response_mode` parameter is set to "streaming" <sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/components/develop/template/template_workflow.en.mdx)</sup>. To modify the output behavior from streaming to blocking, you can adjust the `response_mode` parameter in your API request. Here is an example of how to set it to "blocking": ```bash curl -X POST '${props.appDetail.api_base_url}/workflows/run' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ --data-raw '{ "inputs": {}, "response_mode": "blocking", "user": "abc-123" }' ``` In the codebase, this logic is implemented in the `createChatMessage` method of the `ChatClient` class and the `sendRequest` method of the `DifyClient` class. Here is the relevant code snippet from the `ChatClient` class: ```js export class ChatClient extends DifyClient { createChatMessage( inputs, query, user, stream = false, conversation_id = null, files = null ) { const data = { inputs, query, user, response_mode: stream ? "streaming" : "blocking", files, }; if (conversation_id) data.conversation_id = conversation_id; return this.sendRequest( routes.createChatMessage.method, routes.createChatMessage.url(), data, null, stream ); } } ``` And the `sendRequest` method in the `DifyClient` class: ```js async sendRequest( method, endpoint, data = null, params = null, stream = false, headerParams = {} ) { const headers = { ...{ Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json", }, ...headerParams }; const url = `${this.baseUrl}${endpoint}`; let response; if (stream) { response = await axios({ method, url, data, params, headers, responseType: "stream", }); } else { response = await axios({ method, url, ...(method !== "GET" && { data }), params, headers, responseType: "json", }); } return response; } ``` By setting the `response_mode` to "blocking" in your API request, you can ensure that the workflow tool does not output in a stream in the chat workflow <sup>[[3]](https://github.com/langgenius/dify/blob/main/sdks/nodejs-client/index.js)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Sep 10, 2024):

This is by design.

@crazywoola commented on GitHub (Sep 10, 2024): This is by design.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5527