mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 00:45:53 +08:00
fix: convert tool messages into user messages in react mode and fill … (#2584)
This commit is contained in:
parent
29ab244de6
commit
3a34370422
@ -606,6 +606,7 @@ class BaseAssistantApplicationRunner(AppRunner):
|
|||||||
for message in messages:
|
for message in messages:
|
||||||
result.append(UserPromptMessage(content=message.query))
|
result.append(UserPromptMessage(content=message.query))
|
||||||
agent_thoughts: list[MessageAgentThought] = message.agent_thoughts
|
agent_thoughts: list[MessageAgentThought] = message.agent_thoughts
|
||||||
|
if agent_thoughts:
|
||||||
for agent_thought in agent_thoughts:
|
for agent_thought in agent_thoughts:
|
||||||
tools = agent_thought.tool
|
tools = agent_thought.tool
|
||||||
if tools:
|
if tools:
|
||||||
@ -637,5 +638,10 @@ class BaseAssistantApplicationRunner(AppRunner):
|
|||||||
),
|
),
|
||||||
*tool_call_response
|
*tool_call_response
|
||||||
])
|
])
|
||||||
|
if not tools:
|
||||||
|
result.append(AssistantPromptMessage(content=agent_thought.thought))
|
||||||
|
else:
|
||||||
|
if message.answer:
|
||||||
|
result.append(AssistantPromptMessage(content=message.answer))
|
||||||
|
|
||||||
return result
|
return result
|
@ -154,7 +154,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
|||||||
thought='',
|
thought='',
|
||||||
action_str='',
|
action_str='',
|
||||||
observation='',
|
observation='',
|
||||||
action=None
|
action=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# publish agent thought if it's first iteration
|
# publish agent thought if it's first iteration
|
||||||
@ -469,7 +469,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
|||||||
thought=message.content,
|
thought=message.content,
|
||||||
action_str='',
|
action_str='',
|
||||||
action=None,
|
action=None,
|
||||||
observation=None
|
observation=None,
|
||||||
)
|
)
|
||||||
if message.tool_calls:
|
if message.tool_calls:
|
||||||
try:
|
try:
|
||||||
@ -608,6 +608,13 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
|||||||
overridden = True
|
overridden = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# convert tool prompt messages to user prompt messages
|
||||||
|
for idx, prompt_message in enumerate(prompt_messages):
|
||||||
|
if isinstance(prompt_message, ToolPromptMessage):
|
||||||
|
prompt_messages[idx] = UserPromptMessage(
|
||||||
|
content=prompt_message.content
|
||||||
|
)
|
||||||
|
|
||||||
if not overridden:
|
if not overridden:
|
||||||
prompt_messages.insert(0, SystemPromptMessage(
|
prompt_messages.insert(0, SystemPromptMessage(
|
||||||
content=system_message,
|
content=system_message,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user