Principle:AMAP ML SkillClaw External Agent Execution
| Knowledge Sources | |
|---|---|
| Domains | External_Tool_Integration, Subprocess_Management |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
A subprocess execution pattern for running external CLI agent tools with isolated configuration, timeout enforcement, and persistent session support for multi-round workflows.
Description
External agent execution addresses the problem of invoking external CLI tools (like OpenClaw) from within a Python application. The SkillClaw pattern creates an isolated HOME directory, writes a configuration file with LLM provider and workspace settings, builds the subprocess environment, and invokes the CLI with `--json --local` flags. A timeout (plus a 30-second grace period) prevents runaway processes. Persistent session IDs enable multi-round evolution where the agent retains context across invocations. The pattern handles both fresh mode (wipe home each run) and persistent mode (keep state).
Usage
Use this principle when designing systems that need:
- Subprocess invocation of external agent CLIs
- Isolated execution environments
- Timeout enforcement with graceful capture
- Multi-round agent sessions with persistent context
Theoretical Basis
The subprocess execution pattern:
# Abstract algorithm (NOT real implementation)
def run_agent(bin, workspace, message, timeout, session_id, llm_config):
home = prepare_isolated_home()
write_config(home, llm_config, workspace)
env = build_env(home)
cmd = [bin, "agent", "--message", message, "--session-id", session_id]
result = subprocess.run(cmd, cwd=workspace, env=env, timeout=timeout+30)
return result