fix: remove serialize_as_any=False to fix EventContext validation error (partial fix)#1818
Closed
the-lazy-me with Copilot wants to merge 2 commits into
Closed
fix: remove serialize_as_any=False to fix EventContext validation error (partial fix)#1818the-lazy-me with Copilot wants to merge 2 commits into
the-lazy-me with Copilot wants to merge 2 commits into
Conversation
Co-authored-by: the-lazy-me <52873503+the-lazy-me@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix validation error for EventContext event.message_chain
fix: remove serialize_as_any=False to fix EventContext validation error
Nov 29, 2025
Collaborator
|
@copilot 还是同样报错,可能是插件 sdk 或者是插件https://github.com/langbot-app/langbot-plugin-demo/tree/main/AIImagePlugin的问题 |
Contributor
Author
经过深入分析,您说得对。问题确实不在 LangBot 本体代码中,而是在插件 SDK ( 具体问题位置在 SDK 的以下文件:
这些地方在序列化时可能丢失了子类特有的字段(如 我的修改 (cd22952) 移除了 建议在 langbot-plugin-sdk 仓库中修复这个问题,需要确保 |
Copilot
AI
changed the title
fix: remove serialize_as_any=False to fix EventContext validation error
fix: remove serialize_as_any=False to fix EventContext validation error (partial fix)
Nov 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述 / Overview
修复插件系统中
EventContext.event.message_chain字段验证失败的问题(部分修复)。When emitting events to plugins,
model_dump(serialize_as_any=False)was used inconnector.py. This can override thepydantic.SerializeAsAnyannotation on theeventfield, causing subclass-specific fields likemessage_chainto be lost during serialization in certain Python/Pydantic version combinations.Fix in LangBot: Remove the explicit
serialize_as_any=Falseparameter to let Pydantic use default behavior respecting theSerializeAsAnyannotation.model_dump()调用以确保子类字段被正确序列化:cli/run/handler.py第 144 行runtime/plugin/mgr.py第 511 行This is a partial fix. The complete fix requires changes in the langbot-plugin-sdk repository to ensure
model_dump()calls properly serialize subclass fields.更改前后对比截图 / Screenshots
修改前 / Before:
修改后 / After:
LangBot now correctly serializes event data when sending to plugins. However, the SDK-side serialization issue may still cause the error until the SDK is also fixed.
检查清单 / Checklist
PR 作者完成 / For PR author
项目维护者完成 / For project maintainer
Original prompt
This section details on the original issue you should resolve
<issue_title>[Bug]: 1 validation error for EventContext event.message_chain Field required [type=missing, ...]</issue_title>
<issue_description>### Runtime environment
v4.5.4
Exception
详细报错信息:
[2025-11-29 20:29:27.597] handler.py (146) - [INFO] : [Action] emit_event
[11-29 20:29:27.598] process.py (39) - [INFO] : Processing request from group_cidgZaf+Yel/9rYcSF9/nKEow== (6): 你好
Traceback (most recent call last):
File "/Volumes/Disk-1tb/LangBot/.venv/lib/python3.11/site-packages/langbot_plugin/runtime/io/handler.py", line 121, in handle_message
response = await response
^^^^^^^^^^^^^^
File "/Volumes/Disk-1tb/LangBot/.venv/lib/python3.11/site-packages/langbot_plugin/runtime/io/handlers/control.py", line 175, in emit_event
emitted_plugins, event_context = await self.context.plugin_mgr.emit_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Disk-1tb/LangBot/.venv/lib/python3.11/site-packages/langbot_plugin/runtime/plugin/mgr.py", line 519, in emit_event
event_context = EventContext.model_validate(resp["event_context"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Disk-1tb/LangBot/.venv/lib/python3.11/site-packages/pydantic/main.py", line 716, in model_validate
return cls.pydantic_validator.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for EventContext
event.message_chain
Field required [type=missing, input_value={'reply_message_chain': N...er_message_alter': None}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
[2025-11-29 20:29:27.602] handler.py (146) - [INFO] : [Action] emit_event
[11-29 20:29:27.602] pipelinemgr.py (253) - [ERROR] : Error processing query 6 stage=MessageProcessor : ActionCallError: ValidationError: 1 validation error for EventContext
event.message_chain
Field required [type=missing, input_value={'reply_message_chain': N...er_message_alter': None}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
[11-29 20:29:27.603] pipelinemgr.py (254) - [ERROR] : Traceback: Traceback (most recent call last):
File "/Volumes/Disk-1tb/LangBot/.venv/lib/python3.11/site-packages/langbot_plugin/runtime/io/handler.py", line 175, in call_action
raise ActionCallError(f"{response.message}")
langbot_plugin.entities.io.errors.ActionCallError: ValidationError: 1 validation error for EventContext
event.message_chain
Field required [type=missing, input_value={'reply_message_chain': N...er_message_alter': None}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Volumes/Disk-1tb/LangBot/src/langbot/pkg/pipeline/pipelinemgr.py", line 250, in process_query
await self._execute_from_stage(0, query)
File "/Volumes/Disk-1tb/LangBot/src/langbot/pkg/pipeline/pipelinemgr.py", line 206, in _execute_from_stage
async for sub_result in result:
File "/Volumes/Disk-1tb/LangBot/src/langbot/pkg/pipeline/process/process.py", line 52, in generator
async for result in handler_to_use.handle(query):
File "/Volumes/Disk-1tb/LangBot/src/langbot/pkg/pipeline/process/handlers/chat.py", line 49, in handle
event_ctx = await self.ap.plugin_connector.emit_event(event, bound_plugins)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Disk-1tb/LangBot/src/langbot/pkg/plugin/connector.py", line 376, in emit_event
event_ctx_result = await self.handler.emit_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Disk-1tb/LangBot/src/langbot/pkg/plugin/handler.py", line 560, in emit_event
result = await self.call_action(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Disk-1tb/LangBot/.venv/lib/python3.11/site-packages/langbot_plugin/runtime/io/handler.py", line 180, in call_action
raise ActionCallError(f"{e.class.name}: {str(e)}")
langbot_plugin.entities.io.errors.ActionCallError: ActionCallError: ValidationError: 1 validation error for EventContext
event.message_chain
Field required [type=missing, input_value={'reply_message_chain': N...er_message_alter': None}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
启用的插件:https://github.com/langbot-app/langbot-plugin-demo/tree/main/AIImagePlugin
使用的平台:钉钉
关闭插件后是正常的
Reproduction steps
No response
Enabled plugins
No response</issue_description>
<agent_instructions>中文交流,深度研究 LangBot本体代码、插件代码、插件 SDK 代码以明确准确问题所在</agent_instructions>
Comments on the Issue (you are @copilot in this section)
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.