Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AMAP ML SkillClaw OpenClawRunner

From Leeroopedia
Knowledge Sources
Domains External_Tool_Integration, Subprocess_Management
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for running the OpenClaw agent CLI as a subprocess within a prepared workspace, provided by the SkillClaw evolve server package.

Description

The OpenClawRunner class manages the execution of the external OpenClaw CLI tool as a subprocess. It prepares an isolated `OPENCLAW_HOME` directory, writes an `openclaw.json` config with LLM provider and workspace settings, builds the subprocess environment, and invokes `openclaw agent --message ... --json --local` with a timeout. The agent reads the prepared workspace (sessions, skills, methodology) and edits skill files in-place. Supports fresh mode (wipe home each run) and persistent session mode (multi-round evolution).

Usage

Import and use when you need to:

  • Run the OpenClaw agent for skill evolution
  • Configure OpenClaw subprocess environment and LLM settings
  • Understand the CLI command structure and timeout handling

Code Reference

Source Location

  • Repository: SkillClaw
  • File: `evolve_server/engines/openclaw_runner.py:L27-209`

Signature

class OpenClawRunner:
    """Manage OpenClaw agent subprocess execution."""

    def __init__(
        self,
        openclaw_bin: str = "openclaw",
        openclaw_home: str | Path = "",
        *,
        fresh: bool = True,
        timeout: int = 600,
        llm_api_key: str = "",
        llm_base_url: str = "https://api.openai.com/v1",
        llm_model: str = "gpt-5.4",
        llm_api_type: str = "openai-completions",
    ) -> None:

    def run(
        self,
        workspace_path: Path,
        message: str,
        session_id: str | None = None,
    ) -> subprocess.CompletedProcess[str]:
        """Run an OpenClaw agent with the given message.

        Returns subprocess.CompletedProcess with returncode, stdout, stderr.
        """

Import

from evolve_server.engines.openclaw_runner import OpenClawRunner

I/O Contract

Inputs

Name Type Required Description
openclaw_bin str No Path to openclaw binary (default "openclaw")
openclaw_home Path No HOME directory for OpenClaw (default ./.openclaw_home)
fresh bool No Wipe home before each run (default True)
timeout int No /// Max agent runtime in seconds (default 600)
llm_api_key str No /// API key for the LLM provider
llm_base_url str No /// LLM API base URL
llm_model str No /// LLM model name
llm_api_type str No /// API type (default "openai-completions")
workspace_path Path Yes (run) /// Path to prepared workspace directory
message str Yes (run) /// Instruction message for the agent
session_id None No /// Session ID (None = fresh UUID)

Outputs

Name Type Description
run() returns subprocess.CompletedProcess[str] returncode, stdout (JSON), stderr

Usage Examples

Run Agent for Skill Evolution

from evolve_server.engines.openclaw_runner import OpenClawRunner

runner = OpenClawRunner(
    openclaw_bin="openclaw",
    openclaw_home="/tmp/openclaw_home",
    fresh=True,
    timeout=600,
    llm_api_key="sk-...",
    llm_base_url="https://api.openai.com/v1",
    llm_model="gpt-4o",
    llm_api_type="openai-completions",
)

result = runner.run(
    workspace_path=Path("/tmp/agent_workspace"),
    message="Review the session evidence and improve skills in the skills/ directory.",
    session_id=None,  # Fresh session
)

print(f"Exit code: {result.returncode}")
print(f"Stdout: {result.stdout[:500]}")

Multi-Round Evolution

# Use persistent session for multi-round evolution
runner = OpenClawRunner(
    fresh=False,  # Keep home between rounds
    timeout=300,
    # ... other params ...
)

# Same session_id across rounds lets agent continue from previous context
for round_num in range(3):
    result = runner.run(
        workspace_path=workspace_path,
        message=f"Round {round_num + 1}: Continue evolving skills.",
        session_id="evolve-my-team",  # Persistent session
    )

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment