RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix:The OpenAI-Compatible Agent API returns an incorrect message (#8177)
Stephen Hu1ab0f52832a6
diff --git a/agent/canvas.py b/agent/canvas.pyindex 8e94c639c3..4b859fbf35 100644--- a/agent/canvas.py+++ b/agent/canvas.py@@ -169,6 +169,7 @@ class Canvas:def run(self, running_hint_text = "is running...🕞", **kwargs):if not running_hint_text or not isinstance(running_hint_text, str):running_hint_text = "is running...🕞"+ bypass_begin = bool(kwargs.get("bypass_begin", False))if self.answer:cpn_id = self.answer[0]@@ -188,6 +189,12 @@ class Canvas:if not self.path:self.components["begin"]["obj"].run(self.history, **kwargs)self.path.append(["begin"])+ if bypass_begin:+ cpn = self.get_component("begin")+ downstream = cpn["downstream"]+ self.path.append(downstream)++self.path.append([])diff --git a/agent/component/answer.py b/agent/component/answer.pyindex 67dcbc63f7..c8c3439c00 100644--- a/agent/component/answer.py+++ b/agent/component/answer.py@@ -64,14 +64,17 @@ class Answer(ComponentBase, ABC):for ii, row in stream.iterrows():answer += row.to_dict()["content"]yield {"content": answer}- else:+ elif stream is not None:for st in stream():res = styield st- if self._param.post_answers:+ if self._param.post_answers and res:res["content"] += random.choice(self._param.post_answers)yield res+ if res is None:+ res = {"content": ""}+self.set_output(res)def set_exception(self, e):diff --git a/agent/component/base.py b/agent/component/base.pyindex 8bdddb38e4..e35a84e64e 100644--- a/agent/component/base.py+++ b/agent/component/base.py@@ -442,7 +442,6 @@ class ComponentBase(ABC):elif q.get("value"):outs.append(pd.DataFrame([{"content": q["value"]}]))return outs-def get_input(self):if self._param.debug_inputs:return pd.DataFrame([{"content": v["value"]} for v in self._param.debug_inputs if v.get("value")])diff --git a/api/db/services/canvas_service.py b/api/db/services/canvas_service.pyindex 5d98878fc2..1184034743 100644--- a/api/db/services/canvas_service.py+++ b/api/db/services/canvas_service.py@@ -294,8 +294,22 @@ def completionOpenAI(tenant_id, agent_id, question, session_id=None, stream=True"source": "agent","dsl": cvs.dsl}+ canvas.messages.append({"role": "user", "content": question, "id": message_id})+ canvas.add_user_input(question)+API4ConversationService.save(**conv)conv = API4Conversation(**conv)+ if not conv.message:+ conv.message = []+ conv.message.append({+ "role": "user",+ "content": question,+ "id": message_id+ })++ if not conv.reference:+ conv.reference = []+ conv.reference.append({"chunks": [], "doc_aggs": []})# Handle existing sessionelse:@@ -331,7 +345,7 @@ def completionOpenAI(tenant_id, agent_id, question, session_id=None, stream=Trueif stream:try:completion_tokens = 0- for ans in canvas.run(stream=True):+ for ans in canvas.run(stream=True, bypass_begin=True):if ans.get("running_status"):completion_tokens += len(tiktokenenc.encode(ans.get("content", "")))yield "data: " + json.dumps(@@ -394,7 +408,7 @@ def completionOpenAI(tenant_id, agent_id, question, session_id=None, stream=Trueelse: # Non-streaming modetry:all_answer_content = ""- for answer in canvas.run(stream=False):+ for answer in canvas.run(stream=False, bypass_begin=True):if answer.get("running_status"):continue