Skip to content

feat(plugin-sdk): add LLM completion API to plugin#64294

Merged
jalehman merged 13 commits into
openclaw:mainfrom
DaevMithran:plugin-sdk-llm
May 8, 2026
Merged

feat(plugin-sdk): add LLM completion API to plugin#64294
jalehman merged 13 commits into
openclaw:mainfrom
DaevMithran:plugin-sdk-llm

Conversation

@DaevMithran

@DaevMithran DaevMithran commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Plugins and context engines cannot make LLM calls
  • Why it matters: Context engines and Plugins that want custom LLM-driven compaction or relevance scoring, must either delegate to the runtime or go through the agent loop (costing an LLM turn).
  • What changed: Added api.runtime.llm.complete() for single-shot LLM inference on PluginRuntimeCore. Extended ContextEngineRuntimeContext so context engines receive these capabilities in compact(), afterTurn(), and maintain().
  • What did NOT change (scope boundary): No changes to the agent loop, tool execution, streaming, or session persistence. No new auth system — both APIs reuse the agent's existing credentials and model resolution. No changes to existing plugin registration APIs.

Change Type

  • Feature

Scope (select all touched areas)

  • Skills / tool execution
  • API / contracts

User-visible / Behavior Changes

  • Plugins gain api.runtime.llm.complete() — single-shot LLM completion using the agent's auth and model config.
  • Context engines receive runtimeContext.llm in compact(), afterTurn(), and maintain() hooks.
  • New SDK type exports: PluginLlmCompleteParams, PluginLlmCompleteResult, PluginLlmCompleteMessage.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? Yes — plugins can now invoke LLM completions.
  • Secrets/tokens handling changed? No — reuses existing agent auth profiles.
  • New/changed network calls? No — uses the same model inference path.
  • Data access scope changed? No

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Apr 10, 2026
@greptile-apps

greptile-apps Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds api.runtime.llm.complete() and api.runtime.sandbox.exec() to PluginRuntimeCore, and wires both capabilities into ContextEngineRuntimeContext so context engines receive them in compact(), afterTurn(), and maintain(). The implementation uses proper policy checks (isToolAllowed) for sandbox execution and lazy loading via *.runtime.ts boundaries.

Confidence Score: 5/5

Safe to merge — the new LLM and sandbox APIs are correctly gated by existing policy checks and use proven lazy-loading patterns; all remaining findings are P2 style suggestions.

Both APIs correctly delegate policy enforcement to existing mechanisms (isToolAllowed for sandbox, agent auth for LLM). The process-wide capability caching is sound because the factories are stateless (config is read inside each call closure). No correctness, data-integrity, or security defects were found. The two flagged items are a codebase-style rule violation (dynamic vs. static import mixing) and a missing test isolation mock — neither affects runtime behavior.

src/agents/pi-embedded-runner/compact.ts (dynamic import inconsistency) and src/agents/pi-embedded-runner/run/attempt.test.ts (missing capabilities mock).

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/compact.ts
Line: 1329-1331

Comment:
**Dynamic import mixed with static imports of the same module**

`context-engine-capabilities.js` is imported statically in `context-engine-maintenance.ts` and `attempt.prompt-helpers.ts`, but dynamically here in `compact.ts`. The repo's dynamic-import guardrail in `CLAUDE.md` prohibits mixing `await import("x")` and `import ... from "x"` for the same module in production code paths.

Since the static imports elsewhere already pull this module into the bundle at load time, the dynamic import here buys no laziness. Convert to a static import at the top of `compact.ts` to stay consistent:

```suggestion
          ...(await resolveContextEngineCapabilities()),
```

(With a corresponding static `import { resolveContextEngineCapabilities } from "./context-engine-capabilities.js";` added at the top of the file.)

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.test.ts
Line: 1895

Comment:
**Missing mock for `context-engine-capabilities.js`**

`buildAfterTurnRuntimeContext` now calls `resolveContextEngineCapabilities()`, which dynamically imports the real `runtime-llm.runtime.ts` and `runtime-sandbox.runtime.ts` modules on its first invocation during these tests. `context-engine-maintenance.test.ts` correctly guards against this with a `vi.mock` stub, but this file does not. Add the same mock near the top of this file so tests stay isolated from those runtime surfaces:

```ts
vi.mock("../context-engine-capabilities.js", () => ({
  resolveContextEngineCapabilities: async () => ({ llm: undefined, sandbox: undefined }),
}));
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(plugin-sdk): add LLM completion and..." | Re-trigger Greptile

Comment thread src/agents/pi-embedded-runner/compact.ts Outdated
Comment thread src/agents/pi-embedded-runner/run/attempt.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d68dc4563d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/plugins/runtime/runtime-sandbox.runtime.ts Outdated
Comment thread src/plugins/runtime/runtime-sandbox.runtime.ts Outdated
Comment thread src/plugins/runtime/runtime-llm.runtime.ts Outdated
@DaevMithran DaevMithran changed the title feat(plugin-sdk): add LLM completion and sandbox exec APIs to plugin … feat(plugin-sdk): add LLM completion API to plugin Apr 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc1c91ee1d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/plugins/runtime/runtime-llm.runtime.ts
@clawsweeper

clawsweeper Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
Adds api.runtime.llm.complete to plugin and context-engine runtime contexts, with SDK types, per-plugin config policy, docs, tests, generated baselines, and changelog coverage.

Reproducibility: not applicable. this is a feature PR, not a bug report. Source inspection shows current main lacks the LLM runtime API while the PR head adds the SDK, runtime, context-engine, docs, config, and test surfaces.

Real behavior proof
Needs real behavior proof before merge: The PR body/comments do not include after-fix real behavior proof showing api.runtime.llm.complete working in a real setup. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Human review is needed because this external feature PR lacks required real behavior proof and changes public SDK/config contracts.

Security
Cleared: No concrete security or supply-chain regression was found; the diff adds no dependencies, workflows, scripts, or lockfile changes, and model/agent overrides are config-gated.

Review details

Best possible solution:

Land this PR or a maintainer-owned replacement once live proof and API approval are in place, preserving the request-scoped identity and config-gated override policy.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this is a feature PR, not a bug report. Source inspection shows current main lacks the LLM runtime API while the PR head adds the SDK, runtime, context-engine, docs, config, and test surfaces.

Is this the best way to solve the issue?

Unclear as a merge decision: the implementation direction is plausible and latest checks are green, but the PR still needs real behavior proof and maintainer approval for the public API/config shape.

Acceptance criteria:

  • pnpm check:test-types
  • pnpm test src/plugins/runtime/runtime-llm.runtime.test.ts src/agents/pi-embedded-runner/compact.hooks.test.ts src/config/config-misc.test.ts src/plugins/config-state.test.ts
  • pnpm check:changed
  • pnpm build

What I checked:

Likely related people:

  • steipete: Recent current-main history repeatedly touches plugin runtime contracts and the simple-completion runtime path this PR builds on. (role: plugin runtime and simple-completion adjacent owner; confidence: high; commits: 5aefe6abd6be, 67a447c17530, de20d3a02412; files: src/plugins/runtime/types-core.ts, src/plugins/runtime/index.ts, src/agents/simple-completion-runtime.ts)
  • jalehman: Current-main history introduced and maintained context-engine runtime/maintenance context, and the PR’s later hardening commits also route through this area. (role: context-engine runtime maintainer; confidence: high; commits: 751d5b7849ca, 75e7fc97f804, e46e32b98c04; files: src/context-engine/types.ts, src/agents/pi-embedded-runner/context-engine-maintenance.ts, src/agents/pi-embedded-runner/run/attempt.prompt-helpers.ts)
  • vincentkoc: Recent current-main commits split plugin SDK/runtime contract and cycle-sensitive seams relevant to adding a lazy public runtime surface. (role: adjacent SDK and import-boundary maintainer; confidence: medium; commits: 43a2156d1f50, 74e7b8d47b18, 7308e72fac98; files: src/plugin-sdk/index.ts, src/plugins/runtime/types-core.ts, src/plugins/runtime/index.ts)

Remaining risk / open question:

  • The PR still lacks required after-fix real behavior proof from a live OpenClaw plugin or context-engine completion path.
  • This adds a new public SDK capability and config policy surface, so maintainer API/product approval is still needed before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 6cfb08680e71.

@jalehman jalehman self-assigned this May 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: line Channel integration: line app: web-ui App: web-ui gateway Gateway runtime extensions: memory-core Extension: memory-core commands Command implementations plugin: file-transfer size: XL and removed size: M labels May 4, 2026
@openclaw-barnacle openclaw-barnacle Bot removed channel: line Channel integration: line app: web-ui App: web-ui extensions: memory-core Extension: memory-core commands Command implementations labels May 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 5, 2026
@jalehman jalehman force-pushed the plugin-sdk-llm branch 2 times, most recently from 78509a3 to 3042195 Compare May 8, 2026 02:13
…runtime

Signed-off-by: DaevMithran <daevmithran1999@gmail.com>
Signed-off-by: DaevMithran <daevmithran1999@gmail.com>
@jalehman jalehman merged commit 9e1e597 into openclaw:main May 8, 2026
98 of 99 checks passed
@jalehman

jalehman commented May 8, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

Thanks @DaevMithran!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
rogerdigital pushed a commit to rogerdigital/openclaw that referenced this pull request May 9, 2026
lykeion-dev pushed a commit to lykeion-dev/openclaw--rev that referenced this pull request May 14, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime plugin: file-transfer size: XL triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants