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 f1eded1c
authored
Jun 13, 2026
by
sunqi02
Committed by
胡悦
Jul 01, 2026
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 扩展 OpenAIChatFormatter,支持将 thinking block 转换为 text block
1 parent
24cd1503
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletions
workspace/agent-admin/backend/app/service/agent_hub.py
workspace/agent-admin/backend/app/service/agent_hub.py
View file @
f1eded1
...
...
@@ -10,7 +10,33 @@ from agentscope.tool import Toolkit
from
app.hooks.post_reply
import
PostReplyHook
from
app.service.memory
import
SessionMemory
from
agentscope.model
import
OpenAIChatModel
from
agentscope.formatter
import
OpenAIChatFormatter
from
agentscope.formatter
import
OpenAIChatFormatter
as
_OpenAIChatFormatter
class
OpenAIChatFormatter
(
_OpenAIChatFormatter
):
"""扩展 AgentScope 的 OpenAI formatter,支持 thinking block → text 转换。
ReActAgent 在 reasoning 阶段产出的 thinking block 会存入 InMemoryMemory,
后续 API 调用格式化历史消息时会遇到该类型。原生 formatter 不认识 thinking
类型会打 warning,这里将其转为 text block 保留推理上下文。
"""
async
def
_format
(
self
,
msgs
:
list
)
->
list
:
for
msg
in
msgs
:
blocks
=
msg
.
content
if
isinstance
(
msg
.
content
,
list
)
else
[]
if
not
blocks
:
continue
new_blocks
=
[]
for
block
in
blocks
:
if
isinstance
(
block
,
dict
)
and
block
.
get
(
"type"
)
==
"thinking"
:
text
=
block
.
get
(
"thinking"
,
""
)
if
text
.
strip
():
new_blocks
.
append
({
"type"
:
"text"
,
"text"
:
text
})
else
:
new_blocks
.
append
(
block
)
msg
.
content
=
new_blocks
return
await
super
()
.
_format
(
msgs
)
from
agentscope.message
import
Msg
from
agentscope.message._message_block
import
TextBlock
from
agentscope.tool._response
import
ToolResponse
...
...
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