feat: Support for Chat Flow & Agent Support for binding a single chat flow (#765)

Co-authored-by: Yu Yang <72337138+tomasyu985@users.noreply.github.com>
Co-authored-by: zengxiaohui <csu.zengxiaohui@gmail.com>
Co-authored-by: lijunwen.gigoo <lijunwen.gigoo@bytedance.com>
Co-authored-by: lvxinyu.1117 <lvxinyu.1117@bytedance.com>
Co-authored-by: liuyunchao.0510 <liuyunchao.0510@bytedance.com>
Co-authored-by: haozhenfei <37089575+haozhenfei@users.noreply.github.com>
Co-authored-by: July <jiangxujin@bytedance.com>
Co-authored-by: tecvan-fe <fanwenjie.fe@bytedance.com>
This commit is contained in:
Zhj
2025-08-28 21:53:32 +08:00
committed by GitHub
parent bbc615a18e
commit d70101c979
503 changed files with 48036 additions and 3427 deletions

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package entity
import "time"
type ChatFlowRole struct {
ID int64
WorkflowID int64
ConnectorID int64
Name string
Description string
Version string
AvatarUri string
BackgroundImageInfo string
OnboardingInfo string
SuggestReplyInfo string
AudioConfig string
UserInputConfig string
CreatorID int64
CreatedAt time.Time
UpdatedAt time.Time
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package entity
type ConversationTemplate struct {
SpaceID int64
AppID int64
Name string
TemplateID int64
}
type StaticConversation struct {
UserID int64
ConnectorID int64
TemplateID int64
ConversationID int64
}
type DynamicConversation struct {
ID int64
UserID int64
ConnectorID int64
ConversationID int64
Name string
}

View File

@@ -74,3 +74,9 @@ type ToolInterruptEvent struct {
ExecuteID int64
*InterruptEvent
}
type ConvRelatedInfo struct {
EventID int64
ExecID int64
NodeType NodeType
}

View File

@@ -144,8 +144,11 @@ const (
NodeTypeCodeRunner NodeType = "CodeRunner"
NodeTypePlugin NodeType = "Plugin"
NodeTypeCreateConversation NodeType = "CreateConversation"
NodeTypeConversationList NodeType = "ConversationList"
NodeTypeMessageList NodeType = "MessageList"
NodeTypeClearMessage NodeType = "ClearMessage"
NodeTypeCreateMessage NodeType = "CreateMessage"
NodeTypeEditMessage NodeType = "EditMessage"
NodeTypeDeleteMessage NodeType = "DeleteMessage"
NodeTypeLambda NodeType = "Lambda"
NodeTypeLLM NodeType = "LLM"
NodeTypeSelector NodeType = "Selector"
@@ -153,6 +156,10 @@ const (
NodeTypeSubWorkflow NodeType = "SubWorkflow"
NodeTypeJsonSerialization NodeType = "JsonSerialization"
NodeTypeJsonDeserialization NodeType = "JsonDeserialization"
NodeTypeConversationUpdate NodeType = "ConversationUpdate"
NodeTypeConversationDelete NodeType = "ConversationDelete"
NodeTypeClearConversationHistory NodeType = "ClearConversationHistory"
NodeTypeConversationHistory NodeType = "ConversationHistory"
NodeTypeComment NodeType = "Comment"
)
@@ -272,6 +279,7 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
PostFillNil: true,
InputSourceAware: true,
MayUseChatModel: true,
UseCtxCache: true,
},
EnUSName: "LLM",
EnUSDescription: "Invoke the large language model, generate responses using variables and prompt words.",
@@ -324,6 +332,7 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
UseCtxCache: true,
},
EnUSName: "Knowledge retrieval",
EnUSDescription: "In the selected knowledge, the best matching information is recalled based on the input variable and returned as an Array.",
@@ -487,6 +496,7 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
PreFillZero: true,
PostFillNil: true,
MayUseChatModel: true,
UseCtxCache: true,
},
EnUSName: "Intent recognition",
EnUSDescription: "Used for recognizing the intent in user input and matching it with preset intent options.",
@@ -593,7 +603,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-List.jpeg",
SupportBatch: false,
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
@@ -601,16 +610,15 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
EnUSName: "Query message list",
EnUSDescription: "Used to query the message list",
},
NodeTypeClearMessage: {
NodeTypeClearConversationHistory: {
ID: 38,
Key: NodeTypeClearMessage,
Name: "清除上下文",
Category: "conversation_history",
Key: NodeTypeClearConversationHistory,
Name: "清空会话历史",
Category: "conversation_history", // Mapped from cate_list
Desc: "用于清空会话历史清空后LLM看到的会话历史为空",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-Delete.jpeg",
SupportBatch: false,
Disabled: true,
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
@@ -627,7 +635,6 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-Create.jpeg",
SupportBatch: false,
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
@@ -730,6 +737,118 @@ var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
EnUSName: "Add Data",
EnUSDescription: "Add new data records to the table, and insert them into the database after the user enters the data content",
},
NodeTypeConversationUpdate: {
ID: 51,
Name: "修改会话",
Key: NodeTypeConversationUpdate,
Category: "conversation_management",
Desc: "用于修改会话的名字",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-编辑会话.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Edit Conversation",
EnUSDescription: "Used to modify the name of a conversation.",
},
NodeTypeConversationDelete: {
ID: 52,
Name: "删除会话",
Key: NodeTypeConversationDelete,
Category: "conversation_management",
Desc: "用于删除会话",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-删除会话.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Delete Conversation",
EnUSDescription: "Used to delete a conversation.",
},
NodeTypeConversationList: {
ID: 53,
Name: "查询会话列表",
Key: NodeTypeConversationList,
Category: "conversation_management",
Desc: "用于查询所有会话,包含静态会话、动态会话",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-查询会话.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PostFillNil: true,
},
EnUSName: "Query Conversation List",
EnUSDescription: "Used to query all conversations, including static conversations and dynamic conversations",
},
NodeTypeConversationHistory: {
ID: 54,
Name: "查询会话历史",
Key: NodeTypeConversationHistory,
Category: "conversation_history", // Mapped from cate_list
Desc: "用于查询会话历史返回LLM可见的会话消息",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-查询会话历史.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Query Conversation History",
EnUSDescription: "Used to query conversation history, returns conversation messages visible to the LLM",
},
NodeTypeCreateMessage: {
ID: 55,
Name: "创建消息",
Key: NodeTypeCreateMessage,
Category: "message",
Desc: "用于创建消息",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-创建消息.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Create message",
EnUSDescription: "Used to create messages",
},
NodeTypeEditMessage: {
ID: 56,
Name: "修改消息",
Key: NodeTypeEditMessage,
Category: "message",
Desc: "用于修改消息",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-修改消息.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Edit message",
EnUSDescription: "Used to edit messages",
},
NodeTypeDeleteMessage: {
ID: 57,
Name: "删除消息",
Key: NodeTypeDeleteMessage,
Category: "message",
Desc: "用于删除消息",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-删除消息.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Delete message",
EnUSDescription: "Used to delete messages",
},
NodeTypeJsonSerialization: {
// ID is the unique identifier of this node type. Used in various front-end APIs.
ID: 58,

View File

@@ -17,6 +17,8 @@
package vo
import (
"fmt"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/pkg/i18n"
@@ -108,7 +110,8 @@ type Data struct {
type Inputs struct {
// InputParameters are the fields defined by user for this particular node.
InputParameters []*Param `json:"inputParameters"`
// ChatHistorySetting configures the chat history setting for this node in chatflow mode.
ChatHistorySetting *ChatHistorySetting `json:"chatHistorySetting,omitempty"`
// SettingOnError configures common error handling strategy for nodes.
// NOTE: enable in frontend node's form first.
SettingOnError *SettingOnError `json:"settingOnError,omitempty"`
@@ -432,9 +435,8 @@ type DatabaseInfo struct {
}
type IntentDetector struct {
ChatHistorySetting *ChatHistorySetting `json:"chatHistorySetting,omitempty"`
Intents []*Intent `json:"intents,omitempty"`
Mode string `json:"mode,omitempty"`
Intents []*Intent `json:"intents,omitempty"`
Mode string `json:"mode,omitempty"`
}
type ChatHistorySetting struct {
EnableChatHistory bool `json:"enableChatHistory,omitempty"`
@@ -826,6 +828,133 @@ const defaultEnUSInitCanvasJsonSchema = `{
}
}`
const defaultZhCNInitCanvasJsonSchemaChat = `{
"nodes": [{
"id": "100001",
"type": "1",
"meta": {
"position": {
"x": 0,
"y": 0
}
},
"data": {
"outputs": [{
"type": "string",
"name": "USER_INPUT",
"required": true
}, {
"type": "string",
"name": "CONVERSATION_NAME",
"required": false,
"description": "本次请求绑定的会话,会自动写入消息、会从该会话读对话历史。",
"defaultValue": "%s"
}],
"nodeMeta": {
"title": "开始",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start.png",
"description": "工作流的起始节点,用于设定启动工作流需要的信息",
"subTitle": ""
}
}
}, {
"id": "900001",
"type": "2",
"meta": {
"position": {
"x": 1000,
"y": 0
}
},
"data": {
"nodeMeta": {
"title": "结束",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End.png",
"description": "工作流的最终节点,用于返回工作流运行后的结果信息",
"subTitle": ""
},
"inputs": {
"terminatePlan": "useAnswerContent",
"streamingOutput": true,
"inputParameters": [{
"name": "output",
"input": {
"type": "string",
"value": {
"type": "ref"
}
}
}]
}
}
}]
}`
const defaultEnUSInitCanvasJsonSchemaChat = `{
"nodes": [{
"id": "100001",
"type": "1",
"meta": {
"position": {
"x": 0,
"y": 0
}
},
"data": {
"outputs": [{
"type": "string",
"name": "USER_INPUT",
"required": true
}, {
"type": "string",
"name": "CONVERSATION_NAME",
"required": false,
"description": "The conversation bound to this request will automatically write messages and read conversation history from that conversation.",
"defaultValue": "%s"
}],
"nodeMeta": {
"title": "Start",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start.png",
"description": "The starting node of the workflow, used to set the information needed to initiate the workflow.",
"subTitle": ""
}
}
}, {
"id": "900001",
"type": "2",
"meta": {
"position": {
"x": 1000,
"y": 0
}
},
"data": {
"nodeMeta": {
"title": "End",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End.png",
"description": "The final node of the workflow, used to return the result information after the workflow runs.",
"subTitle": ""
},
"inputs": {
"terminatePlan": "useAnswerContent",
"streamingOutput": true,
"inputParameters": [{
"name": "output",
"input": {
"type": "string",
"value": {
"type": "ref"
}
}
}]
}
}
}]
}`
func GetDefaultInitCanvasJsonSchema(locale i18n.Locale) string {
return ternary.IFElse(locale == i18n.LocaleEN, defaultEnUSInitCanvasJsonSchema, defaultZhCNInitCanvasJsonSchema)
}
func GetDefaultInitCanvasJsonSchemaChat(locale i18n.Locale, name string) string {
return ternary.IFElse(locale == i18n.LocaleEN, fmt.Sprintf(defaultEnUSInitCanvasJsonSchemaChat, name), fmt.Sprintf(defaultZhCNInitCanvasJsonSchemaChat, name))
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package vo
type ChatFlowRoleCreate struct {
WorkflowID int64
CreatorID int64
Name string
Description string
AvatarUri string
BackgroundImageInfo string
OnboardingInfo string
SuggestReplyInfo string
AudioConfig string
UserInputConfig string
}
type ChatFlowRoleUpdate struct {
WorkflowID int64
Name *string
Description *string
AvatarUri *string
BackgroundImageInfo *string
OnboardingInfo *string
SuggestReplyInfo *string
AudioConfig *string
UserInputConfig *string
}
type PublishRolePolicy struct {
WorkflowID int64
CreatorID int64
Version string
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package vo
import "github.com/cloudwego/eino/schema"
type ChatFlowEvent string
const (
ChatFlowCreated ChatFlowEvent = "conversation.chat.created"
ChatFlowInProgress ChatFlowEvent = "conversation.chat.in_progress"
ChatFlowCompleted ChatFlowEvent = "conversation.chat.completed"
ChatFlowFailed ChatFlowEvent = "conversation.chat.failed"
ChatFlowRequiresAction ChatFlowEvent = "conversation.chat.requires_action"
ChatFlowError ChatFlowEvent = "error"
ChatFlowDone ChatFlowEvent = "done"
ChatFlowMessageDelta ChatFlowEvent = "conversation.message.delta"
ChatFlowMessageCompleted ChatFlowEvent = "conversation.message.completed"
)
type Usage struct {
TokenCount *int32 `form:"token_count" json:"token_count,omitempty"`
OutputTokens *int32 `form:"output_count" json:"output_count,omitempty"`
InputTokens *int32 `form:"input_count" json:"input_count,omitempty"`
}
type Status string
const (
Created Status = "created"
InProgress Status = "in_progress"
Completed Status = "completed"
Failed Status = "failed"
RequiresAction Status = "requires_action"
Canceled Status = "canceled"
)
type ChatFlowDetail struct {
ID string `json:"id,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
BotID string `json:"bot_id,omitempty"`
Status Status `json:"status,omitempty"`
Usage *Usage `json:"usage,omitempty"`
ExecuteID string `json:"execute_id,omitempty"`
SectionID string `json:"section_id"`
}
type MessageDetail struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
ConversationID string `json:"conversation_id"`
BotID string `json:"bot_id"`
Role string `json:"role"`
Type string `json:"type"`
Content string `json:"content"`
ContentType string `json:"content_type"`
SectionID string `json:"section_id"`
}
type ErrorDetail struct {
Code string `form:"code,required" json:"code,required"`
Msg string `form:"msg,required" json:"msg,required"`
DebugUrl string `form:"debug_url" json:"debug_url,omitempty"`
}
type SuggestInfo struct {
UserInput *schema.Message `json:"user_input,omitempty"`
AnswerInput *schema.Message `json:"answer,omitempty"`
PersonaInput *string `json:"persona_input,omitempty"`
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package vo
type Env string
const (
Draft Env = "draft"
Online Env = "online"
)
type CreateConversationTemplateMeta struct {
UserID int64
AppID int64
SpaceID int64
Name string
}
type GetConversationTemplatePolicy struct {
AppID *int64
Name *string
Version *string
TemplateID *int64
}
type ListConversationTemplatePolicy struct {
AppID int64
Page *Page
NameLike *string
Version *string
}
type ListConversationMeta struct {
APPID int64
UserID int64
ConnectorID int64
}
type ListConversationPolicy struct {
ListConversationMeta
Page *Page
NameLike *string
Version *string
}
type CreateStaticConversation struct {
AppID int64
UserID int64
ConnectorID int64
TemplateID int64
}
type CreateDynamicConversation struct {
AppID int64
UserID int64
ConnectorID int64
Name string
}

View File

@@ -68,6 +68,7 @@ type MetaUpdate struct {
IconURI *string
HasPublished *bool
LatestPublishedVersion *string
WorkflowMode *Mode
}
type MetaQuery struct {
@@ -80,4 +81,5 @@ type MetaQuery struct {
LibOnly bool
NeedTotalNumber bool
DescByUpdate bool
Mode *workflow.WorkflowMode
}

View File

@@ -21,4 +21,5 @@ type ReleaseWorkflowConfig struct {
PluginIDs []int64
ConnectorIDs []int64
WorkflowIDs []int64
}