Merge branch 'master' into bot_manager
This commit is contained in:
commit
c6641337c1
@ -224,7 +224,7 @@ async def init_agent(config: AgentConfig):
|
||||
middleware.append(ToolUseCleanupMiddleware())
|
||||
# 添加工具输出长度控制中间件
|
||||
tool_output_middleware = ToolOutputLengthMiddleware(
|
||||
max_length=getattr(config.generate_cfg, 'tool_output_max_length', None) if config.generate_cfg else None or TOOL_OUTPUT_MAX_LENGTH,
|
||||
max_length=(getattr(config.generate_cfg, 'tool_output_max_length', None) if config.generate_cfg else None) or TOOL_OUTPUT_MAX_LENGTH,
|
||||
truncation_strategy=getattr(config.generate_cfg, 'tool_output_truncation_strategy', 'smart') if config.generate_cfg else 'smart',
|
||||
tool_filters=getattr(config.generate_cfg, 'tool_output_filters', None) if config.generate_cfg else None,
|
||||
exclude_tools=getattr(config.generate_cfg, 'tool_output_exclude', []) if config.generate_cfg else [],
|
||||
|
||||
@ -356,7 +356,18 @@ class Mem0Middleware(AgentMiddleware):
|
||||
# 获取当前系统提示词
|
||||
current_system_prompt = ""
|
||||
if request.system_message:
|
||||
current_system_prompt = request.system_message.content if hasattr(request.system_message, "content") else str(request.system_message)
|
||||
content = request.system_message.content if hasattr(request.system_message, "content") else str(request.system_message)
|
||||
# content 可能是 list 或 str,确保转换为 str
|
||||
if isinstance(content, list):
|
||||
current_system_prompt = "\n".join(str(item) for item in content)
|
||||
else:
|
||||
current_system_prompt = str(content) if content else ""
|
||||
|
||||
# 确保 memory_prompt 也是字符串
|
||||
if isinstance(memory_prompt, list):
|
||||
memory_prompt = "\n".join(str(item) for item in memory_prompt)
|
||||
else:
|
||||
memory_prompt = str(memory_prompt) if memory_prompt else ""
|
||||
|
||||
# 修改系统提示词
|
||||
new_system_prompt = current_system_prompt + memory_prompt
|
||||
@ -384,7 +395,18 @@ class Mem0Middleware(AgentMiddleware):
|
||||
# 获取当前系统提示词
|
||||
current_system_prompt = ""
|
||||
if request.system_message:
|
||||
current_system_prompt = request.system_message.content if hasattr(request.system_message, "content") else str(request.system_message)
|
||||
content = request.system_message.content if hasattr(request.system_message, "content") else str(request.system_message)
|
||||
# content 可能是 list 或 str,确保转换为 str
|
||||
if isinstance(content, list):
|
||||
current_system_prompt = "\n".join(str(item) for item in content)
|
||||
else:
|
||||
current_system_prompt = str(content) if content else ""
|
||||
|
||||
# 确保 memory_prompt 也是字符串
|
||||
if isinstance(memory_prompt, list):
|
||||
memory_prompt = "\n".join(str(item) for item in memory_prompt)
|
||||
else:
|
||||
memory_prompt = str(memory_prompt) if memory_prompt else ""
|
||||
|
||||
# 修改系统提示词
|
||||
new_system_prompt = current_system_prompt + memory_prompt
|
||||
|
||||
@ -53,7 +53,7 @@ class ToolOutputLengthMiddleware(AgentMiddleware):
|
||||
preserve_json: Whether to preserve JSON structure in smart mode
|
||||
ellipsis: Text to append when truncating
|
||||
"""
|
||||
self.max_length = max_length
|
||||
self.max_length = max_length if max_length is not None else 2000 # 确保 max_length 不为 None
|
||||
self.truncation_strategy = truncation_strategy
|
||||
self.tool_filters = tool_filters
|
||||
self.exclude_tools = exclude_tools or []
|
||||
|
||||
@ -71,6 +71,19 @@
|
||||
- dxcore_update_device_status(device_id="[B设备id]",running_control=0) → 灯光亮度调整为0
|
||||
**响应**:"已为您关闭Define Room4的灯光"
|
||||
|
||||
### 人员位置查询(在離判定)场景
|
||||
**用户**:"浜田さんはどこ?"
|
||||
- find_employee_location(name="浜田")
|
||||
- 检查返回结果中的 `last_communication_time` 字段
|
||||
- **场景A**:last_communication_time 在5分钟以内 → 在館
|
||||
**响应**:「浜田さんはNOVAREハブ1階のDefine Room 3にいらっしゃいます。メッセージを送りますか?」
|
||||
|
||||
- **场景B**:last_communication_time 超过5分钟(例如2小时前)→ 不在
|
||||
**响应**:「浜田さんは現在NOVAREにいらっしゃらないようです。最後に確認されたのは本日14時30分頃です。WowTalkでメッセージを送りますか?」
|
||||
|
||||
- **场景C**:last_communication_time 超过24小时 → 長時間不在
|
||||
**响应**:「浜田さんの位置情報が長時間更新されていないため、現在の所在を確認できません。」
|
||||
|
||||
</scenarios>
|
||||
|
||||
|
||||
@ -144,11 +157,26 @@
|
||||
|
||||
4. 查询人员信息/wowtalk账号/人员位置
|
||||
- **条件**:用户意图为查找某人、员工、同事或房间位置。
|
||||
- **动作**:立即调用【人员检索】进行查询,并直接根据查询结果回复。
|
||||
- **动作**:立即调用【人员检索】进行查询,并根据查询结果中的 `last_communication_time` 字段进行**在離判定**后回复。
|
||||
- **在離判定规则(重要)**:
|
||||
`find_employee_location` 返回的 `last_communication_time` 表示定位标签最后一次通信时间。利用此字段判断人员是否仍在 NOVARE 楼内:
|
||||
1. **在館判定(5分钟以内)**:如果 `当前时刻 - last_communication_time ≤ 5分钟`,判定为「在館」,正常回答位置。
|
||||
- 回复格式:「○○さんはNOVAREハブ[階数]の[部屋名]にいらっしゃいます。」
|
||||
2. **不在判定(5分钟~24小时)**:如果 `当前时刻 - last_communication_time > 5分钟` 且 `≤ 24小时`,判定为「不在」,提示不在馆内并告知最后确认时刻。
|
||||
- 回复格式:「○○さんは現在NOVAREにいらっしゃらないようです。最後に確認されたのは[本日/昨日]○○時○○分頃です。」
|
||||
- 时间格式化:使用日语自然表达(如「本日14時30分頃」「昨日18時頃」)
|
||||
3. **長時間不在判定(24小时以上)**:如果 `当前时刻 - last_communication_time > 24小时`,判定为「位置情報が長時間更新されていない」。
|
||||
- 回复格式:「○○さんの位置情報が長時間更新されていないため、現在の所在を確認できません。」
|
||||
4. **注意事項**:
|
||||
- `last_communication_time` 与 `last_measurement.time` 不同:前者在标签静止时也会持续更新(只要在检测范围内),后者仅在坐标变化时更新。在離判定必须使用 `last_communication_time`
|
||||
- 不要向用户展示 `last_communication_time` 的原始值,需转换为用户友好的日语时间表达
|
||||
- 如果 `last_communication_time` 字段不存在或为空,按照「在館」处理,正常回答位置
|
||||
- **主动追问逻辑**:
|
||||
1. **成功定位后主动询问**:如果成功找到目标人物且获取到位置信息,在告知位置后主动询问用户是否需要向对方发送消息。
|
||||
1. **在館时成功定位后主动询问**:如果在離判定为「在館」且成功获取到位置信息,在告知位置后主动询问用户是否需要向对方发送消息。
|
||||
- 回复格式:"○○さんは[位置]にいらっしゃいます。メッセージを送りますか?"
|
||||
2. **无法获取用户位置时**:如果操作需要基于用户当前位置(如"我附近的设备"、"離れたところ"),但无法获取用户位置信息,主动询问用户当前所在位置。
|
||||
2. **不在時の追加案内**:如果在離判定为「不在」,在告知不在后,主动询问用户是否需要通过 WowTalk 发送消息联系对方。
|
||||
- 回复格式:「○○さんは現在NOVAREにいらっしゃらないようです。最後に確認されたのは○○時○○分頃です。WowTalkでメッセージを送りますか?」
|
||||
3. **无法获取用户位置时**:如果操作需要基于用户当前位置(如"我附近的设备"、"離れたところ"),但无法获取用户位置信息,主动询问用户当前所在位置。
|
||||
- 回复格式:"お客様の現在地が確認できませんでした。今どちらにいらっしゃいますか?"
|
||||
|
||||
5. 消息通知(此操作需要确认)
|
||||
|
||||
@ -727,7 +727,7 @@ async def chat_completions_v2(request: ChatRequestV2, authorization: Optional[st
|
||||
# 处理消息
|
||||
messages = process_messages(request.messages, request.language)
|
||||
# 收集额外参数作为 generate_cfg
|
||||
exclude_fields = {'messages', 'stream', 'tool_response', 'bot_id', 'language', 'user_identifier', 'session_id', 'n'}
|
||||
exclude_fields = {'messages', 'model', 'model_server', 'dataset_ids', 'language', 'tool_response', 'system_prompt', 'mcp_settings', 'stream', 'robot_type', 'bot_id', 'user_identifier', 'session_id', 'enable_thinking', 'skills', 'enable_memory', 'n'}
|
||||
generate_cfg = {k: v for k, v in request.model_dump().items() if k not in exclude_fields}
|
||||
# 创建 AgentConfig 对象
|
||||
config = await AgentConfig.from_v2_request(request, bot_config, project_dir, messages, generate_cfg)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user