|
@@ -10,10 +10,12 @@ import logging
|
|
|
import sys
|
|
import sys
|
|
|
import os
|
|
import os
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
|
|
+from agent.core.runner import KnowledgeConfig
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
from dotenv import load_dotenv
|
|
|
|
|
+
|
|
|
load_dotenv()
|
|
load_dotenv()
|
|
|
|
|
|
|
|
from agent import (
|
|
from agent import (
|
|
@@ -171,9 +173,9 @@ async def generate_fallback_output(store: FileSystemTraceStore, trace_id: str):
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# 生成输出
|
|
# 生成输出
|
|
|
- print("\n" + "="*60)
|
|
|
|
|
|
|
+ print("\n" + "=" * 60)
|
|
|
print("📊 任务执行摘要(兜底输出)")
|
|
print("📊 任务执行摘要(兜底输出)")
|
|
|
- print("="*60)
|
|
|
|
|
|
|
+ print("=" * 60)
|
|
|
print(f"\n搜索情况:找到 {len(search_results)} 条候选内容")
|
|
print(f"\n搜索情况:找到 {len(search_results)} 条候选内容")
|
|
|
print(f"画像获取:获取了 {len(portrait_data)} 条画像数据")
|
|
print(f"画像获取:获取了 {len(portrait_data)} 条画像数据")
|
|
|
|
|
|
|
@@ -202,9 +204,9 @@ async def generate_fallback_output(store: FileSystemTraceStore, trace_id: str):
|
|
|
|
|
|
|
|
# 输出推荐结果
|
|
# 输出推荐结果
|
|
|
print(f"\n符合要求:{len(matched_results)} 条内容(50岁以上占比>=20%)")
|
|
print(f"\n符合要求:{len(matched_results)} 条内容(50岁以上占比>=20%)")
|
|
|
- print("\n" + "="*60)
|
|
|
|
|
|
|
+ print("\n" + "=" * 60)
|
|
|
print("🎯 推荐结果")
|
|
print("🎯 推荐结果")
|
|
|
- print("="*60)
|
|
|
|
|
|
|
+ print("=" * 60)
|
|
|
|
|
|
|
|
for i, result in enumerate(matched_results[:10], 1):
|
|
for i, result in enumerate(matched_results[:10], 1):
|
|
|
aweme_id = result["aweme_id"]
|
|
aweme_id = result["aweme_id"]
|
|
@@ -216,12 +218,13 @@ async def generate_fallback_output(store: FileSystemTraceStore, trace_id: str):
|
|
|
print(f"\n{i}. {desc}")
|
|
print(f"\n{i}. {desc}")
|
|
|
print(f" 链接: https://www.douyin.com/video/{aweme_id}")
|
|
print(f" 链接: https://www.douyin.com/video/{aweme_id}")
|
|
|
print(f" 作者: {author.get('nickname', '未知')}")
|
|
print(f" 作者: {author.get('nickname', '未知')}")
|
|
|
- print(f" 热度: 👍 {stats.get('digg_count', 0):,} | 💬 {stats.get('comment_count', 0):,} | 🔄 {stats.get('share_count', 0):,}")
|
|
|
|
|
|
|
+ print(
|
|
|
|
|
+ f" 热度: 👍 {stats.get('digg_count', 0):,} | 💬 {stats.get('comment_count', 0):,} | 🔄 {stats.get('share_count', 0):,}")
|
|
|
print(f" 画像: 50岁以上 {portrait['age_50_plus']}% (tgi: {portrait['tgi']}) - {portrait['source']}")
|
|
print(f" 画像: 50岁以上 {portrait['age_50_plus']}% (tgi: {portrait['tgi']}) - {portrait['source']}")
|
|
|
|
|
|
|
|
- print("\n" + "="*60)
|
|
|
|
|
|
|
+ print("\n" + "=" * 60)
|
|
|
print(f"✅ 已为您找到 {min(len(matched_results), 10)} 条推荐视频")
|
|
print(f"✅ 已为您找到 {min(len(matched_results), 10)} 条推荐视频")
|
|
|
- print("="*60)
|
|
|
|
|
|
|
+ print("=" * 60)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
logger.error(f"生成兜底输出失败: {e}", exc_info=True)
|
|
logger.error(f"生成兜底输出失败: {e}", exc_info=True)
|
|
@@ -271,11 +274,32 @@ async def main():
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
config = RunConfig(
|
|
config = RunConfig(
|
|
|
|
|
+ name="内容寻找",
|
|
|
model=model,
|
|
model=model,
|
|
|
temperature=temperature,
|
|
temperature=temperature,
|
|
|
max_iterations=max_iterations,
|
|
max_iterations=max_iterations,
|
|
|
tools=allowed_tools, # 限制工具范围
|
|
tools=allowed_tools, # 限制工具范围
|
|
|
extra_llm_params={"max_tokens": 8192}, # 增加输出 token 限制,避免被截断
|
|
extra_llm_params={"max_tokens": 8192}, # 增加输出 token 限制,避免被截断
|
|
|
|
|
+ knowledge=KnowledgeConfig(
|
|
|
|
|
+ # 压缩时提取(消息量超阈值触发压缩时,用完整 history 反思)
|
|
|
|
|
+ enable_extraction=True,
|
|
|
|
|
+ reflect_prompt="", # 自定义反思 prompt;空则使用默认,见 agent/core/prompts/knowledge.py:REFLECT_PROMPT
|
|
|
|
|
+
|
|
|
|
|
+ # agent运行完成后提取(不代表任务完成,agent 可能中途退出等待人工评估)
|
|
|
|
|
+ enable_completion_extraction=True,
|
|
|
|
|
+ completion_reflect_prompt="",
|
|
|
|
|
+ # 自定义复盘 prompt;空则使用默认,见 agent/core/prompts/knowledge.py:COMPLETION_REFLECT_PROMPT
|
|
|
|
|
+
|
|
|
|
|
+ # 知识注入(agent切换当前工作的goal时,自动注入相关知识)
|
|
|
|
|
+ enable_injection=True,
|
|
|
|
|
+
|
|
|
|
|
+ # 默认字段(保存/搜索时自动注入)
|
|
|
|
|
+ owner="content_finder_agent", # 所有者(空则尝试从 git config user.email 获取,再空则用 agent:{agent_id})
|
|
|
|
|
+ default_tags={"project": "content_finder"}, # 默认 tags(会与工具调用参数合并)
|
|
|
|
|
+ default_scopes=["com.piaoquantv.supply"], # 默认 scopes
|
|
|
|
|
+ default_search_types=["tool", "usecase", "definition"], # 默认搜索类型过滤
|
|
|
|
|
+ default_search_owner="content_finder_agent" # 默认搜索 owner 过滤(空则不过滤)
|
|
|
|
|
+ )
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
# 执行
|
|
# 执行
|