| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- """
- 项目配置
- 定义项目的运行配置,包括模型、知识管理、日志等。
- """
- import logging
- from agent.core.runner import KnowledgeConfig
- # ===== 运行配置 =====
- class RunnerConfig:
- """运行配置"""
- def __init__(self):
- # 模型配置
- self.model = "sonnet-4.5"
- self.temperature = 0.3
- self.max_iterations = 1000
- # 路径配置
- self.skills_dir = "./skills"
- self.trace_store_path = ".trace"
- # 其他配置
- self.debug = True
- self.name = "Research Agent"
- # 知识管理配置
- self.knowledge = KnowledgeConfig(
- # 压缩时提取(消息量超阈值触发压缩时,在 Level 1 过滤前用完整 history 反思)
- enable_extraction=True,
- reflect_prompt="", # 空则使用默认,见 agent/core/prompts/knowledge.py:REFLECT_PROMPT
- # agent运行完成后提取(不代表任务完成,agent 可能中途退出等待人工评估)
- enable_completion_extraction=True,
- completion_reflect_prompt="", # 空则使用默认,见 agent/core/prompts/knowledge.py:COMPLETION_REFLECT_PROMPT
- # 知识注入(agent切换当前工作的goal时,自动注入相关知识)
- enable_injection=True,
- # 默认字段(保存/搜索时自动注入)
- owner="user@example.com", # 所有者(空则尝试从 git config user.email 获取,再空则用 agent:{agent_id})
- default_tags={"project": "research", "domain": "ai_agent"}, # 默认 tags(会与工具调用参数合并)
- default_scopes=["org:cybertogether"], # 默认 scopes
- default_search_types=["strategy", "tool"], # 默认搜索类型过滤
- default_search_owner="user@example.com" # 默认搜索 owner 过滤(空则不过滤)
- )
- # 日志配置
- class LoggingConfig:
- level = "INFO"
- console = True
- file = None
- self.logging = LoggingConfig()
- # 自动反思配置(项目层面控制)
- class AutoReflectConfig:
- enabled = True
- on_completion = True
- on_failure = True
- min_messages = 10
- focus_on_failure = "本次任务执行失败了,请重点反思失败的原因、踩坑点以及未来应如何避免。"
- self.auto_reflect = AutoReflectConfig()
- # 配置实例
- RUNNER_CONFIG = RunnerConfig()
- # ===== 工具函数 =====
- def setup_logging(config):
- """配置日志系统"""
- level = getattr(logging, config.level.upper(), logging.INFO)
- handlers = []
- if config.console:
- handlers.append(logging.StreamHandler())
- if config.file:
- handlers.append(logging.FileHandler(config.file, encoding="utf-8"))
- logging.basicConfig(
- level=level,
- format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
- handlers=handlers,
- force=True
- )
- # 设置第三方库日志级别
- logging.getLogger("httpx").setLevel(logging.WARNING)
- logging.getLogger("httpcore").setLevel(logging.WARNING)
|