Skip to content

Commit 9f3cfe0

Browse files
committed
Add skip_bootstrap option to OpenClawAdapter to allow users to bypass the initial identity setup
1 parent caf4e31 commit 9f3cfe0

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

lagent/adapters/openclaw.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class OpenClawAdapter(CLIAgentAdapter):
5555
json_output: Pass ``--json`` and parse the JSON envelope to
5656
extract ``sessionId`` (multi-turn) and the reply text.
5757
Default: True.
58+
skip_bootstrap: Skip OpenClaw's first-run identity ritual by
59+
removing ``BOOTSTRAP.md`` and pre-seeding ``IDENTITY.md`` /
60+
``USER.md``. Default: True (recommended for headless /
61+
programmatic use).
5862
openclaw_home: OpenClaw state/config directory. Default:
5963
``OPENCLAW_HOME`` / ``OPENCLAW_STATE_DIR`` / ``~/.openclaw``.
6064
nvm_dir: If set, wrap the spawn in ``bash -lc`` and source
@@ -73,6 +77,7 @@ def __init__(
7377
thinking: str = 'medium',
7478
agent_id: Optional[str] = 'main',
7579
json_output: bool = True,
80+
skip_bootstrap: bool = True,
7681
openclaw_home: Optional[str] = None,
7782
nvm_dir: Optional[str] = None,
7883
node_version: str = '22',
@@ -88,6 +93,7 @@ def __init__(
8893
self.thinking = thinking
8994
self.agent_id = agent_id
9095
self.json_output = json_output
96+
self.skip_bootstrap = skip_bootstrap
9197
self.nvm_dir = nvm_dir
9298
self.node_version = node_version
9399
self.provider = 'custom-openai'
@@ -158,6 +164,49 @@ def reset_session(self) -> None:
158164
"""Forget the captured session id; the next call starts fresh."""
159165
self._cli_session_id = None
160166

167+
_IDENTITY_TEMPLATE_MARKER = 'Fill this in during your first conversation'
168+
_USER_TEMPLATE_MARKER = '_Learn about the person you'
169+
_MINIMAL_IDENTITY = """\
170+
# IDENTITY.md - Who Am I?
171+
172+
- **Name:** OpenClaw
173+
- **Creature:** AI assistant
174+
- **Vibe:** Helpful and direct
175+
- **Emoji:** 🤖
176+
"""
177+
_MINIMAL_USER = """\
178+
# USER.md - About Your Human
179+
180+
- **Name:** User
181+
- **What to call them:** User
182+
"""
183+
184+
def _prepare_workspace(self, workspace: str) -> None:
185+
"""Remove bootstrap ritual files so headless calls skip onboarding."""
186+
if not self.skip_bootstrap:
187+
return
188+
189+
root = Path(workspace).expanduser()
190+
bootstrap = root / 'BOOTSTRAP.md'
191+
if bootstrap.is_file():
192+
bootstrap.unlink()
193+
194+
identity = root / 'IDENTITY.md'
195+
if identity.is_file():
196+
text = identity.read_text(encoding='utf-8')
197+
if self._IDENTITY_TEMPLATE_MARKER in text:
198+
identity.write_text(self._MINIMAL_IDENTITY, encoding='utf-8')
199+
else:
200+
identity.write_text(self._MINIMAL_IDENTITY, encoding='utf-8')
201+
202+
user = root / 'USER.md'
203+
if user.is_file():
204+
text = user.read_text(encoding='utf-8')
205+
if self._USER_TEMPLATE_MARKER in text:
206+
user.write_text(self._MINIMAL_USER, encoding='utf-8')
207+
else:
208+
user.write_text(self._MINIMAL_USER, encoding='utf-8')
209+
161210
def _write_openclaw_config(self) -> None:
162211
env = self._build_env()
163212
base_url = (env.get('OPENAI_BASE_URL') or '').rstrip('/')
@@ -174,6 +223,7 @@ def _write_openclaw_config(self) -> None:
174223
agent_id = self.agent_id or 'main'
175224
model_ref = f'{self.provider}/{self.model}'
176225
workspace = self.working_dir or os.environ.get('TASK_WORKSPACE') or os.getcwd()
226+
self._prepare_workspace(workspace)
177227
agents = {
178228
'defaults': {
179229
'model': {'primary': model_ref},

0 commit comments

Comments
 (0)