[PR #32239] feat: Add Openai response tool call supper #33624

Closed
opened 2026-02-21 20:53:37 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/32239

State: closed
Merged: No


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #32027.

Title

[Feature] Support External Tool Calling (OpenAI Protocol) & OpenClaw Integration on skill-bundler

fixe: #32027
https://github.com/langgenius/dify/issues/32027

Summary

This PR enables Dify Chatflow applications to accept OpenAI-compatible tool definitions, allowing Dify to function as an upstream LLM provider for OpenClaw. With this feature, Dify apps can generate tool call requests (tool_calls) to be executed by external systems (like OpenClaw's local tools) and receive execution results to continue the conversation.

This feature was originally developed based on the main branch. Since the refactor/skill-bundler branch represents the core of Dify's next-generation AI Skill node support, this submission has been merged and integrated with refactor/skill-bundler. All conflicts have been resolved to ensure perfect compatibility between the external tool calling feature and Dify's next-gen Skill/Sandbox architecture.

Motivation and Context

To achieve deep integration between Dify workflows and OpenClaw's local tool ecosystem, we need Dify's LLM node to recognize and handle externally injected tool definitions. This allows developers to leverage Dify's powerful orchestration capabilities while utilizing OpenClaw's extensive local execution capabilities.

Key Changes

  1. API Enhancements:

    • Added support for tools (OpenAI format) and tool_choice parameters in completion-messages and chat-messages endpoints.
    • Updated API entry points (api/controllers/service_api/app/completion.py) to pass through external parameters.
  2. Core Logic:

    • LLM Node: Updated api/core/workflow/nodes/llm/node.py to handle externally injected tool definitions and correctly process streaming outputs for tool_calls.
    • Streaming Response: Introduced tool_call chunk events to stream tool execution instructions via Server-Sent Events (SSE) in real-time.
    • Event Handling: Fixed an issue where tool_calls were lost in _stream_llm_events after merging with skill-bundler, ensuring tool call history is correctly captured.
  3. Data Persistence:

    • Added tool_calls field to the Message model to persist full tool execution history and prevent context loss in multi-turn conversations.
    • Included corresponding database migration scripts (alembic).
  4. Compatibility:

    • Resolved merge conflicts with the refactor/skill-bundler branch.
    • Ensured that Dify's native internal tools (Plugins/Skills) and externally injected tools (OpenClaw Tools) can coexist without conflict.

Checklist

  • This change requires a documentation update, included: Dify Document (if applicable)
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods.
**Original Pull Request:** https://github.com/langgenius/dify/pull/32239 **State:** closed **Merged:** No --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #32027`. ## Title [Feature] Support External Tool Calling (OpenAI Protocol) & OpenClaw Integration on skill-bundler fixe: #32027 https://github.com/langgenius/dify/issues/32027 ## Summary This PR enables Dify Chatflow applications to accept OpenAI-compatible tool definitions, allowing Dify to function as an upstream LLM provider for OpenClaw. With this feature, Dify apps can generate tool call requests (`tool_calls`) to be executed by external systems (like OpenClaw's local tools) and receive execution results to continue the conversation. This feature was originally developed based on the `main` branch. Since the `refactor/skill-bundler` branch represents the core of Dify's next-generation AI Skill node support, this submission has been merged and integrated with `refactor/skill-bundler`. All conflicts have been resolved to ensure perfect compatibility between the external tool calling feature and Dify's next-gen Skill/Sandbox architecture. ## Motivation and Context To achieve deep integration between Dify workflows and OpenClaw's local tool ecosystem, we need Dify's LLM node to recognize and handle externally injected tool definitions. This allows developers to leverage Dify's powerful orchestration capabilities while utilizing OpenClaw's extensive local execution capabilities. ## Key Changes 1. **API Enhancements**: - Added support for `tools` (OpenAI format) and `tool_choice` parameters in `completion-messages` and `chat-messages` endpoints. - Updated API entry points (`api/controllers/service_api/app/completion.py`) to pass through external parameters. 2. **Core Logic**: - **LLM Node**: Updated `api/core/workflow/nodes/llm/node.py` to handle externally injected tool definitions and correctly process streaming outputs for `tool_calls`. - **Streaming Response**: Introduced `tool_call` chunk events to stream tool execution instructions via Server-Sent Events (SSE) in real-time. - **Event Handling**: Fixed an issue where `tool_calls` were lost in `_stream_llm_events` after merging with `skill-bundler`, ensuring tool call history is correctly captured. 3. **Data Persistence**: - Added `tool_calls` field to the `Message` model to persist full tool execution history and prevent context loss in multi-turn conversations. - Included corresponding database migration scripts (`alembic`). 4. **Compatibility**: - Resolved merge conflicts with the `refactor/skill-bundler` branch. - Ensured that Dify's native internal tools (Plugins/Skills) and externally injected tools (OpenClaw Tools) can coexist without conflict. ## Checklist - [x] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) (if applicable) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods.
yindo added the pull-request label 2026-02-21 20:53:37 -05:00
yindo closed this issue 2026-02-21 20:53:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33624