Skip to content

Commit 37f3462

Browse files
committed
support process message function.
1 parent b1dab55 commit 37f3462

File tree

6 files changed

+93
-5
lines changed

6 files changed

+93
-5
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ All notable changes to this project will be documented in this file.
99

1010
---
1111

12+
## [1.0.9.3] - 2025-12-12
13+
### Added
14+
- Added oxy.BaseLLM parameter to support custom multimodal base64 prefixes.
15+
- Added func_process_message method to the MAS class for unified message processing, refer to [./examples/backend/demo_process_message.py](./examples/backend/demo_process_message.py)
16+
17+
### Fixed
18+
- When the send_msg_key parameter of the chat_with_agent function is empty, messages will not be sent.
19+
20+
---
21+
22+
## [1.0.9.2] - 2025-12-09
23+
### Added
24+
- Added stream_end message as an indicator for the end of streaming messages.
25+
- Stream messages now support batch storage.
26+
27+
### Changed
28+
- Modified the structure of the message table, added new fields.
29+
30+
---
31+
32+
## [1.0.9.1] - 2025-12-04
33+
### Added
34+
- Added pre-logging of payloads for easier troubleshooting.
35+
- Standardized SSE message fields: id, event, data.
36+
- SSEOxyGent now forwards headers transparently.
37+
38+
### Changed
39+
- When storing in the history table, the answer field in memory is forcibly converted to a string.
40+
41+
---
42+
1243
## [1.0.8] - 2025-11-14
1344

1445
### Added

CHANGELOG_zh.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
---
1111

12+
## [1.0.9.3] - 2025-12-12
13+
14+
### Added
15+
- 新增oxy.BaseLLM参数,支持自定义多模态base64前缀
16+
- MAS类新增func_process_message方法,用于统一处理消息,详见 [./examples/backend/demo_process_message.py](./examples/backend/demo_process_message.py)
17+
18+
### Fixed
19+
- chat_with_agent函数入参send_msg_key参数为空时,修改为不发送消息
20+
21+
---
22+
1223
## [1.0.9.2] - 2025-12-09
1324

1425
### Added
@@ -23,11 +34,13 @@
2334
## [1.0.9.1] - 2025-12-04
2435

2536
### Added
26-
- 打印payload日志
27-
- history表存储时,memory的answer字段强转str
37+
- 前置打印payload日志,便于排除
2838
- 标准化sse消息字段id、event、data
2939
- SSEOxyGent透传headers
3040

41+
### Changed
42+
- history表存储时,memory的answer字段强转str
43+
3144
---
3245

3346
## [1.0.8] - 2025-11-14

examples/advanced/demo_multimodal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
model_name=os.getenv("DEFAULT_VLM_MODEL_NAME"),
1212
is_multimodal_supported=True, # 设置支持多模态
1313
is_convert_url_to_base64=True, # 设置将图片链接转换为base64
14+
base64_image_prefix="data:image/jpeg", # 设置base64图片前缀
1415
),
1516
oxy.ChatAgent(
1617
name="vision_agent",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import asyncio
2+
import os
3+
4+
from oxygent import MAS, Config, OxyRequest, oxy
5+
6+
Config.set_message_is_show_in_terminal(True)
7+
8+
9+
def process_message(dict_message: dict, oxy_request: OxyRequest) -> dict:
10+
if dict_message["data"]["type"] == "stream":
11+
dict_message["data"]["content"]["delta"] += "-"
12+
return dict_message
13+
14+
15+
oxy_space = [
16+
oxy.HttpLLM(
17+
name="default_llm",
18+
api_key=os.getenv("DEFAULT_LLM_API_KEY"),
19+
base_url=os.getenv("DEFAULT_LLM_BASE_URL"),
20+
model_name=os.getenv("DEFAULT_LLM_MODEL_NAME"),
21+
llm_params={"stream": True},
22+
),
23+
oxy.ChatAgent(
24+
name="qa_agent",
25+
llm_model="default_llm",
26+
),
27+
]
28+
29+
30+
async def main():
31+
async with MAS(oxy_space=oxy_space, func_process_message=process_message) as mas:
32+
await mas.start_web_service(first_query="hello")
33+
34+
35+
if __name__ == "__main__":
36+
asyncio.run(main())

oxygent/mas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class MAS(BaseModel):
9898
lambda x: None, exclude=True, description="interceptor function"
9999
)
100100

101+
func_process_message: Optional[Callable] = Field(
102+
lambda x, oxy_request: x, exclude=True, description="process message function"
103+
)
104+
101105
routers: list = Field(default_factory=list)
102106
middlewares: list = Field(default_factory=list)
103107

oxygent/schemas/oxy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,12 @@ async def start(self) -> "OxyResponse":
356356

357357
async def send_message(self, message=None, event=None, id=None):
358358
if self.mas and self.is_send_message:
359-
args = {"id": id, "event": event, "data": message}
360-
filtered_args = {k: v for k, v in args.items() if v is not None}
361-
sse_message = SSEMessage(**filtered_args)
359+
dict_message = {"id": id, "event": event, "data": message}
360+
dict_message_processed = self.mas.func_process_message(dict_message, self)
361+
dict_message_filtered = {
362+
k: v for k, v in dict_message_processed.items() if v is not None
363+
}
364+
sse_message = SSEMessage(**dict_message_filtered)
362365
redis_key = (
363366
f"{self.mas.message_prefix}:{self.mas.name}:{self.current_trace_id}"
364367
)

0 commit comments

Comments
 (0)