Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ai
/
ai-workflow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 498607af
authored
Jun 13, 2026
by
sunqi02
Committed by
胡悦
Jul 06, 2026
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 添加 ThinkingBlockSafeFormatter 以处理 ThinkingBlock,避免消息丢失
1 parent
f89a461d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletions
workspace/agent-admin/backend/app/service/agent_hub.py
workspace/agent-admin/backend/app/service/agent_hub.py
View file @
498607a
...
@@ -19,6 +19,29 @@ from agentscope.agent import ReActAgent
...
@@ -19,6 +19,29 @@ from agentscope.agent import ReActAgent
from
agentscope.memory
import
InMemoryMemory
from
agentscope.memory
import
InMemoryMemory
class
ThinkingBlockSafeFormatter
(
OpenAIChatFormatter
):
"""OpenAI formatter that strips ThinkingBlock before formatting.
The upstream OpenAIChatFormatter does not handle ThinkingBlock
(type="thinking"), causing "Unsupported block type" warnings and
risking silent message drops when a message contains only thinking
blocks. This wrapper pre-filters them so they never reach the upstream
block-handling loop.
"""
async
def
_format
(
self
,
msgs
:
list
[
Msg
])
->
list
[
dict
[
str
,
Any
]]:
# TruncatedFormatterBase.format() deepcopies msgs before calling
# _format, so we can safely mutate the copies here.
for
msg
in
msgs
:
if
hasattr
(
msg
,
"content"
)
and
isinstance
(
msg
.
content
,
list
):
msg
.
content
=
[
block
for
block
in
msg
.
content
if
not
(
isinstance
(
block
,
dict
)
and
block
.
get
(
"type"
)
==
"thinking"
)
]
return
await
super
()
.
_format
(
msgs
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
# sub_agent 专用低 temperature:调用子 Agent 处理确定性任务时使用更稳定的输出
# sub_agent 专用低 temperature:调用子 Agent 处理确定性任务时使用更稳定的输出
...
@@ -138,7 +161,7 @@ class AgentHub:
...
@@ -138,7 +161,7 @@ class AgentHub:
stream
=
False
,
stream
=
False
,
client_kwargs
=
{
"base_url"
:
self
.
main_model_config
.
api_base
}
client_kwargs
=
{
"base_url"
:
self
.
main_model_config
.
api_base
}
)
)
self
.
formatter
=
OpenAIChat
Formatter
()
self
.
formatter
=
ThinkingBlockSafe
Formatter
()
# 加载回复风格指南(soul/agent.md)
# 加载回复风格指南(soul/agent.md)
soul_path
=
Path
(
__file__
)
.
parent
.
parent
.
parent
/
"soul"
/
"agent.md"
soul_path
=
Path
(
__file__
)
.
parent
.
parent
.
parent
/
"soul"
/
"agent.md"
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment