refactor: reorganize OpenClaw services and enhance session management
This commit is contained in:
120
backend/app/services/openclaw/constants.py
Normal file
120
backend/app/services/openclaw/constants.py
Normal file
@@ -0,0 +1,120 @@
|
||||
"""Shared constants for lifecycle orchestration services."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import re
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
_GATEWAY_AGENT_PREFIX = "agent:gateway-"
|
||||
_GATEWAY_AGENT_SUFFIX = ":main"
|
||||
_GATEWAY_OPENCLAW_AGENT_PREFIX = "mc-gateway-"
|
||||
|
||||
DEFAULT_HEARTBEAT_CONFIG: dict[str, Any] = {
|
||||
"every": "10m",
|
||||
"target": "none",
|
||||
"includeReasoning": False,
|
||||
}
|
||||
|
||||
OFFLINE_AFTER = timedelta(minutes=10)
|
||||
AGENT_SESSION_PREFIX = "agent"
|
||||
|
||||
DEFAULT_CHANNEL_HEARTBEAT_VISIBILITY: dict[str, bool] = {
|
||||
# Suppress routine HEARTBEAT_OK delivery by default.
|
||||
"showOk": False,
|
||||
"showAlerts": True,
|
||||
"useIndicator": True,
|
||||
}
|
||||
|
||||
DEFAULT_IDENTITY_PROFILE = {
|
||||
"role": "Generalist",
|
||||
"communication_style": "direct, concise, practical",
|
||||
"emoji": ":gear:",
|
||||
}
|
||||
|
||||
IDENTITY_PROFILE_FIELDS = {
|
||||
"role": "identity_role",
|
||||
"communication_style": "identity_communication_style",
|
||||
"emoji": "identity_emoji",
|
||||
}
|
||||
|
||||
EXTRA_IDENTITY_PROFILE_FIELDS = {
|
||||
"autonomy_level": "identity_autonomy_level",
|
||||
"verbosity": "identity_verbosity",
|
||||
"output_format": "identity_output_format",
|
||||
"update_cadence": "identity_update_cadence",
|
||||
# Per-agent charter (optional).
|
||||
# Used to give agents a "purpose in life" and a distinct vibe.
|
||||
"purpose": "identity_purpose",
|
||||
"personality": "identity_personality",
|
||||
"custom_instructions": "identity_custom_instructions",
|
||||
}
|
||||
|
||||
DEFAULT_GATEWAY_FILES = frozenset(
|
||||
{
|
||||
"AGENTS.md",
|
||||
"SOUL.md",
|
||||
"TASK_SOUL.md",
|
||||
"SELF.md",
|
||||
"AUTONOMY.md",
|
||||
"TOOLS.md",
|
||||
"IDENTITY.md",
|
||||
"USER.md",
|
||||
"HEARTBEAT.md",
|
||||
"BOOT.md",
|
||||
"BOOTSTRAP.md",
|
||||
"MEMORY.md",
|
||||
},
|
||||
)
|
||||
|
||||
# These files are intended to evolve within the agent workspace.
|
||||
# Provision them if missing, but avoid overwriting existing content during updates.
|
||||
#
|
||||
# Examples:
|
||||
# - SELF.md: evolving identity/preferences
|
||||
# - USER.md: human-provided context + lead intake notes
|
||||
# - MEMORY.md: curated long-term memory (consolidated)
|
||||
PRESERVE_AGENT_EDITABLE_FILES = frozenset({"SELF.md", "USER.md", "MEMORY.md", "TASK_SOUL.md"})
|
||||
|
||||
HEARTBEAT_LEAD_TEMPLATE = "HEARTBEAT_LEAD.md"
|
||||
HEARTBEAT_AGENT_TEMPLATE = "HEARTBEAT_AGENT.md"
|
||||
SESSION_KEY_PARTS_MIN = 2
|
||||
_SESSION_KEY_PARTS_MIN = SESSION_KEY_PARTS_MIN
|
||||
|
||||
MAIN_TEMPLATE_MAP = {
|
||||
"AGENTS.md": "MAIN_AGENTS.md",
|
||||
"HEARTBEAT.md": "MAIN_HEARTBEAT.md",
|
||||
"USER.md": "MAIN_USER.md",
|
||||
"BOOT.md": "MAIN_BOOT.md",
|
||||
"TOOLS.md": "MAIN_TOOLS.md",
|
||||
}
|
||||
|
||||
_TOOLS_KV_RE = re.compile(r"^(?P<key>[A-Z0-9_]+)=(?P<value>.*)$")
|
||||
_NON_TRANSIENT_GATEWAY_ERROR_MARKERS = ("unsupported file",)
|
||||
_TRANSIENT_GATEWAY_ERROR_MARKERS = (
|
||||
"connect call failed",
|
||||
"connection refused",
|
||||
"errno 111",
|
||||
"econnrefused",
|
||||
"did not receive a valid http response",
|
||||
"no route to host",
|
||||
"network is unreachable",
|
||||
"host is down",
|
||||
"name or service not known",
|
||||
"received 1012",
|
||||
"service restart",
|
||||
"http 503",
|
||||
"http 502",
|
||||
"http 504",
|
||||
"temporar",
|
||||
"timeout",
|
||||
"timed out",
|
||||
"connection closed",
|
||||
"connection reset",
|
||||
)
|
||||
|
||||
_COORDINATION_GATEWAY_TIMEOUT_S = 45.0
|
||||
_COORDINATION_GATEWAY_BASE_DELAY_S = 0.5
|
||||
_COORDINATION_GATEWAY_MAX_DELAY_S = 5.0
|
||||
_SECURE_RANDOM = random.SystemRandom()
|
||||
Reference in New Issue
Block a user