fix: Feishu channel agents file_write permission blocked + memory system tests & docs
- Fix 8 Feishu agent handlers to use permission_level="acceptEdits" so file_write tool works without Web UI approval popup (lingxi/renshenguo/suyao/tiantian/orange/main/schedule) - Add P5-P7 memory improvements: offline keyword fallback, team sharing, file-based memory - Add auto_dream_service for daily memory consolidation - Add 99 memory system test cases (basic 18 + advanced 43 + pytest 38) - Add platform capability assessment report and unfinished project checklist Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -100,11 +100,13 @@ def _reply_to_feishu(open_id: str, text: str):
|
||||
logger.warning("橙子回复消息失败: %s", e)
|
||||
|
||||
|
||||
def _reply_card(open_id: str, title: str, content: str, status: str = "info"):
|
||||
def _reply_card(open_id: str, title: str, content: str, status: str = "info",
|
||||
execution_log_id: str = None, agent_name: str = None):
|
||||
"""通过橙子应用回复卡片消息。"""
|
||||
try:
|
||||
from app.services.orange_app_service import send_message_to_user
|
||||
send_message_to_user(open_id, title, content, status=status)
|
||||
send_message_to_user(open_id, title, content, status=status,
|
||||
execution_log_id=execution_log_id, agent_name=agent_name)
|
||||
except Exception as e:
|
||||
logger.warning("橙子回复卡片失败: %s", e)
|
||||
|
||||
@@ -230,7 +232,7 @@ async def _handle_message_async(data):
|
||||
temperature=temperature,
|
||||
max_iterations=max_iterations,
|
||||
),
|
||||
tools=AgentToolConfig(),
|
||||
tools=AgentToolConfig(permission_level="acceptEdits"), # 飞书渠道无Web弹窗
|
||||
memory=AgentMemoryConfig(
|
||||
max_history_messages=int(cfg.get("memory_max_history", 20)),
|
||||
vector_memory_top_k=int(cfg.get("memory_vector_top_k", 5)),
|
||||
@@ -256,7 +258,23 @@ async def _handle_message_async(data):
|
||||
result = await runtime.run(text)
|
||||
|
||||
if result.content:
|
||||
_reply_card(open_id, f"🍊 {agent.name}", result.content.strip(), status="success")
|
||||
# Look up execution log for feedback buttons
|
||||
exec_log_id = None
|
||||
try:
|
||||
from app.models.agent_execution_log import AgentExecutionLog
|
||||
log_entry = (
|
||||
db.query(AgentExecutionLog)
|
||||
.filter(AgentExecutionLog.agent_name == agent.name)
|
||||
.order_by(AgentExecutionLog.created_at.desc())
|
||||
.first()
|
||||
)
|
||||
if log_entry:
|
||||
exec_log_id = str(log_entry.id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
_reply_card(open_id, f"🍊 {agent.name}", result.content.strip(), status="success",
|
||||
execution_log_id=exec_log_id, agent_name=agent.name)
|
||||
else:
|
||||
_reply_to_feishu(open_id, "Agent 未返回有效回复,请重试。")
|
||||
|
||||
@@ -321,6 +339,19 @@ def _build_event_handler():
|
||||
verification_token="",
|
||||
)
|
||||
builder.register_p2_im_message_receive_v1(on_message_receive)
|
||||
|
||||
# Register card action handler for feedback buttons
|
||||
from app.services.feishu_card_actions import card_action_handler
|
||||
from lark_oapi.event.callback.model.p2_card_action_trigger import (
|
||||
P2CardActionTrigger,
|
||||
P2CardActionTriggerResponse,
|
||||
)
|
||||
|
||||
def on_card_action(event: P2CardActionTrigger) -> P2CardActionTriggerResponse:
|
||||
return card_action_handler(event)
|
||||
|
||||
builder.register_p2_card_action_trigger(on_card_action)
|
||||
|
||||
return builder.build()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user