feat: 添加AI记忆模块和事件调度系统 - 新增AI记忆模块,支持本地记忆召回和自动写入功能 - 实现事件调度系统,支持批量处理待定事件和重试机制 - 集成心跳监控机制,跟踪API、调度器和工作节点状态 - 扩展仪表板数据统计,包含AI记忆条目和心跳概要 - 添加企业运营分析报告功能,提供财务、采购等多维度分析 - 更新配置设置,增加事件调度和AI记忆相关参数 - 优化任务队列,添加事件分发任务类型 - 扩展审计日志,记录AI记忆操作和事件调度行为 - 实现领域事件模型,支持事件持久化和状态管理 - 添加观察性服务,监控系统组件健康状况 ```
170 lines
4.3 KiB
Python
170 lines
4.3 KiB
Python
from enum import StrEnum
|
|
|
|
|
|
class AIProviderName(StrEnum):
|
|
NOOP = "noop"
|
|
OPENCLAW = "openclaw"
|
|
HERMES = "hermes"
|
|
OPENCLAW_HERMES = "openclaw_hermes"
|
|
OPENCLAW_HERMES_DASH = "openclaw-hermes"
|
|
HYBRID = "hybrid"
|
|
DIRECT_LLM = "direct_llm"
|
|
|
|
|
|
class AIResponseKey(StrEnum):
|
|
PROVIDER = "provider"
|
|
ANSWER = "answer"
|
|
RAW = "raw"
|
|
RESULT = "result"
|
|
OK = "ok"
|
|
ERROR = "error"
|
|
MESSAGE = "message"
|
|
TYPE = "type"
|
|
BASE_URL = "base_url"
|
|
HEALTH = "health"
|
|
HEALTHZ = "healthz"
|
|
READYZ = "readyz"
|
|
DATA = "data"
|
|
STATUS_CODE = "status_code"
|
|
TEXT = "text"
|
|
PIPELINE = "pipeline"
|
|
HERMES_RECALL = "hermes_recall"
|
|
LOCAL_MEMORY = "local_memory"
|
|
MEMORY_WRITE = "memory_write"
|
|
HERMES_ANSWER = "hermes_answer"
|
|
HERMES_REMEMBER = "hermes_remember"
|
|
OPENCLAW = "openclaw"
|
|
TOOL = "tool"
|
|
TOOL_INVOKED = "tool_invoked"
|
|
TOOL_ERROR = "tool_error"
|
|
|
|
|
|
class AIRequestKey(StrEnum):
|
|
PROMPT = "prompt"
|
|
CONTEXT = "context"
|
|
|
|
|
|
class AIContextKey(StrEnum):
|
|
OPENCLAW_TOOL = "openclaw_tool"
|
|
OPENCLAW_ACTION = "openclaw_action"
|
|
OPENCLAW_ARGS = "openclaw_args"
|
|
OPENCLAW_SESSION_KEY = "openclaw_session_key"
|
|
AGENT_PIPELINE = "agent_pipeline"
|
|
HERMES_MEMORY = "hermes_memory"
|
|
LOCAL_MEMORY = "local_memory"
|
|
MEMORY_SCOPE = "memory_scope"
|
|
MEMORY_SUBJECT = "memory_subject"
|
|
OPENCLAW = "openclaw"
|
|
MODE = "mode"
|
|
USER_PROMPT = "user_prompt"
|
|
REQUEST_CONTEXT = "request_context"
|
|
ASSISTANT_ANSWER = "assistant_answer"
|
|
|
|
|
|
class AIMemoryMode(StrEnum):
|
|
RECALL = "memory_recall"
|
|
WRITE = "memory_write"
|
|
|
|
|
|
class AIHttpPath(StrEnum):
|
|
CHAT_COMPLETIONS = "/chat/completions"
|
|
HEALTH = "/health"
|
|
HEALTHZ = "/healthz"
|
|
READYZ = "/readyz"
|
|
TOOLS_INVOKE = "/tools/invoke"
|
|
V1 = "/v1"
|
|
|
|
|
|
class AIHttpHeader(StrEnum):
|
|
AUTHORIZATION = "Authorization"
|
|
HERMES_SESSION_ID = "X-Hermes-Session-Id"
|
|
|
|
|
|
class AIHttpPayloadKey(StrEnum):
|
|
MODEL = "model"
|
|
MESSAGES = "messages"
|
|
ROLE = "role"
|
|
CONTENT = "content"
|
|
STREAM = "stream"
|
|
TOOL = "tool"
|
|
ACTION = "action"
|
|
ARGS = "args"
|
|
SESSION_KEY = "sessionKey"
|
|
CHOICES = "choices"
|
|
MESSAGE = "message"
|
|
|
|
|
|
class AIToolAuditKey(StrEnum):
|
|
TOOL = "tool"
|
|
ACTION = "action"
|
|
ARGS = "args"
|
|
SESSION_KEY = "session_key"
|
|
|
|
|
|
class AIChatRole(StrEnum):
|
|
SYSTEM = "system"
|
|
USER = "user"
|
|
|
|
|
|
class AIDefault(StrEnum):
|
|
ACTION_JSON = "json"
|
|
SESSION_KEY_MAIN = "main"
|
|
|
|
|
|
class AIRiskPreference(StrEnum):
|
|
BALANCED = "balanced"
|
|
|
|
|
|
class AIErrorKey(StrEnum):
|
|
OPENCLAW = "openclaw_error"
|
|
HERMES = "hermes_error"
|
|
DIRECT_LLM = "llm_error"
|
|
|
|
|
|
OPENCLAW_HERMES_PIPELINE = (
|
|
"hermes_recall -> openclaw_gateway -> hermes_answer -> hermes_remember"
|
|
)
|
|
COMPANY_MANAGEMENT_SYSTEM_INSTRUCTIONS = (
|
|
"You are a company management AI. Be concise, cite data from context, "
|
|
"and never approve payments, performance changes, or trades automatically."
|
|
)
|
|
CHAT_USER_CONTENT_TEMPLATE = "Context:\n{context}\n\nTask:\n{task}"
|
|
AUTHORIZATION_BEARER_TEMPLATE = "Bearer {token}"
|
|
NOOP_PROVIDER_ANSWER = (
|
|
"AI provider is not configured yet. This is a deterministic placeholder. "
|
|
"Set MODEL_PROVIDER to openclaw_hermes, openclaw, hermes, or direct_llm "
|
|
"after credentials are ready."
|
|
)
|
|
OPENCLAW_TOOL_COMPLETED_ANSWER = "OpenClaw tool invocation completed."
|
|
DIRECT_LLM_API_KEY_MISSING = "DIRECT_LLM_API_KEY is not configured"
|
|
UNEXPECTED_HERMES_RESPONSE = "Unexpected chat completion response"
|
|
OPENCLAW_CHAT_PROVIDER_REQUIRED = (
|
|
"OpenClaw Gateway is not configured as a chat provider. "
|
|
"Provide context.openclaw_tool for /tools/invoke, or use "
|
|
"MODEL_PROVIDER=hermes/openclaw_hermes for AI answers."
|
|
)
|
|
OPENCLAW_TOOL_NOT_ALLOWED = "OpenClaw tool is not allowed"
|
|
OPENCLAW_ACTION_NOT_ALLOWED = "OpenClaw action is not allowed"
|
|
UNSUPPORTED_AI_SKILL_TEMPLATE = "Unsupported AI skill: {skill_id}"
|
|
|
|
AI_AUDIT_REDACTED_VALUE = "[REDACTED]"
|
|
AI_AUDIT_TRUNCATED_VALUE = "[TRUNCATED]"
|
|
AI_AUDIT_MAX_TEXT_LENGTH = 1000
|
|
AI_AUDIT_MAX_SEQUENCE_ITEMS = 20
|
|
AI_AUDIT_MAX_DEPTH = 4
|
|
AI_AUDIT_SENSITIVE_KEYS = frozenset(
|
|
{
|
|
"authorization",
|
|
"api_key",
|
|
"apikey",
|
|
"access_token",
|
|
"tenant_access_token",
|
|
"token",
|
|
"secret",
|
|
"password",
|
|
"openclaw_gateway_token",
|
|
"hermes_api_key",
|
|
"direct_llm_api_key",
|
|
}
|
|
)
|