Skip to content

Add pi.runWhenIdle() to schedule work after the agent has fully settled #2023

Description

@ronyrus

What happened?

The example examples/extensions/reload-runtime.ts demonstrates an LLM-callable tool that queues /reload-runtime via sendUserMessage:

  pi.sendUserMessage("/reload-runtime", { deliverAs: "followUp" });
  return { content: [{ type: "text", text: "Queued /reload-runtime as a follow-up command." }] };

This does not work. The /reload-runtime string is sent to the LLM as a literal user message instead of dispatching the command.

The root cause is that sendUserMessage calls prompt() with expandPromptTemplates: false (agent-session.ts:1178), which skips the command dispatch branch at line 811:

  if (expandPromptTemplates && text.startsWith("/")) {
      const handled = await this._tryExecuteExtensionCommand(text);

Steps to reproduce

  1. Enable the shipped reload-runtime example extension
  2. Ask the agent to reload its runtime (trigger the reload_runtime tool)
  3. Observe that /reload-runtime is sent to the LLM as text, not executed as a command

Expected behavior

/reload-runtime dispatched as a slash commands

Version

0.57.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpossibly-openclaw-clankerUser has activity on openclaw/openclaw

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions