From da1559fc981c0631732eddf7ac00276d005c3995 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Sun, 8 Feb 2026 00:47:46 +0530 Subject: [PATCH] feat: persist agent's soul_template to prevent overwriting on reprovision --- backend/app/api/agent.py | 7 +++++++ templates/HEARTBEAT_LEAD.md | 1 + 2 files changed, 8 insertions(+) diff --git a/backend/app/api/agent.py b/backend/app/api/agent.py index 1c4ed53..88921a0 100644 --- a/backend/app/api/agent.py +++ b/backend/app/api/agent.py @@ -17,6 +17,7 @@ from app.api import tasks as tasks_api from app.api.deps import ActorContext, get_board_or_404, get_task_or_404 from app.core.agent_auth import AgentAuthContext, get_agent_auth_context from app.core.config import settings +from app.core.time import utcnow from app.db.pagination import paginate from app.db.session import get_session from app.integrations.openclaw_gateway import GatewayConfig as GatewayClientConfig @@ -572,6 +573,12 @@ async def update_agent_soul( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="content is required", ) + + # Persist the SOUL in the DB so future reprovision/update doesn't overwrite it. + target.soul_template = content + target.updated_at = utcnow() + session.add(target) + await session.commit() try: await openclaw_call( "agents.files.set", diff --git a/templates/HEARTBEAT_LEAD.md b/templates/HEARTBEAT_LEAD.md index bb9da90..95f56d8 100644 --- a/templates/HEARTBEAT_LEAD.md +++ b/templates/HEARTBEAT_LEAD.md @@ -321,6 +321,7 @@ Tools: - Update an agent's SOUL.md (lead-only): PUT $BASE_URL/api/v1/agent/boards/$BOARD_ID/agents//soul Body: {"content":"","source_url":"","reason":""} + Notes: this persists as the agent's `soul_template` so future reprovision won't overwrite it. ## Memory Maintenance (every 2-3 days) Lightweight consolidation (modeled on human "sleep consolidation"):