Skip to content

llm/shellm: add OpenAI Responses completion protocol - #101

Open
24601 wants to merge 6 commits into
laude-institute:mainfrom
24601:feat/responses-api
Open

llm/shellm: add OpenAI Responses completion protocol#101
24601 wants to merge 6 commits into
laude-institute:mainfrom
24601:feat/responses-api

Conversation

@24601

@24601 24601 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What

Adds an opt-in OpenAI Responses completion protocol to the existing bin/llm provider seam and lets shellm continue Responses state safely within one run. Chat Completions remains the default and is unchanged.

Set LLM_API_FORMAT=responses for llm, or SHELLM_API_FORMAT=responses for shellm. This preserves native reasoning and response state across shellm turns and unlocks models and features available only through Responses.

Completion contract

  • Native OpenAI and OpenRouter select their Responses endpoints; openai-compatible uses the configured endpoint.
  • Typed Responses input is preserved rather than flattened, including multimodal messages, reasoning items, function calls, and function outputs.
  • LLM_RESPONSES_BODY_FILE accepts a bounded compatible create surface, including tools, include, store, text format, metadata, truncation, service tier, and provider extensions. CLI-owned fields remain deterministic; conversation state and background mode are rejected.
  • Every request augments include with reasoning.encrypted_content so stateless replay can preserve reasoning.
  • Buffered and SSE paths handle visible text, refusals, reasoning summaries, function-only output, incomplete/failed state, errors, and usage.
  • LLM_RESPONSE_FILE atomically records the full terminal Response or error envelope as mode 0600.

shellm continuation

shellm keeps response state process-local. Native OpenAI and compatible endpoints use previous_response_id while retaining an exact typed replay chain. If continuation is rejected, shellm retries once from that replay and remains stateless for the rest of the run. OpenRouter starts in replay mode because its Responses API is stateless. Remote response IDs are not written to the durable trajectory.

Retrieve, cancel, delete, input-item listing, Conversations, background jobs, compaction, and WebSocket lifecycle operations remain out of scope.

Verification

  • bash tests/test_llm_responses.sh — 27 passed, 0 failed
  • bash tests/test_shellm_responses_continuation.sh — 14 passed, 0 failed

@24601
24601 force-pushed the feat/responses-api branch 2 times, most recently from 343cf9e to 6f41636 Compare September 2, 2026 15:01
24601 and others added 3 commits September 3, 2026 04:37
Add opt-in Responses create and SSE support for OpenAI, OpenRouter, and generic compatible endpoints. Preserve typed items, terminal response state, usage, reasoning summaries, and shellm continuation with exact replay fallback while keeping Chat Completions as the default.

Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Basit Mustafa <basit.mustafa@gmail.com>
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Basit Mustafa <basit.mustafa@gmail.com>
Keep --stop-after-code-block on chat so shellm still cuts the stream
at the first fence, but skip it for Responses (continuation needs the
terminal event). Deduplicate previous_response_id error matching.
Raise LOC_LIMIT to 11500 and the README/philosophy line-count claim
so the protocol can land without silent core growth.

Amp-Thread-ID: https://ampcode.com/threads/T-01a06587-820b-734b-a505-b10d58712e10
Co-authored-by: Basit Mustafa <basit.mustafa@gmail.com>
@24601
24601 force-pushed the feat/responses-api branch from 6f41636 to 678a8bc Compare September 3, 2026 04:47
ampagent and others added 3 commits September 3, 2026 15:25
Resolve Responses protocol overlaps with upstream context-scope help and cached-token accounting. Preserve cache_tok for both buffered and streamed Responses and add regression coverage.

Co-authored-by: Basit Mustafa <basit.mustafa@gmail.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a0679e-60c1-72ca-a36f-2428be671374
Require terminal Responses events before accepting streamed output or executing it in shellm. Track the prior rendered context so continuation deltas cannot silently resend pinned prompts when bounded context drops their boundary.

Preserve upstream cached-token accounting for buffered and streamed Responses.

Co-authored-by: Basit Mustafa <basit.mustafa@gmail.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a0679e-60c1-72ca-a36f-2428be671374
Amp-Thread-ID: https://ampcode.com/threads/T-01a0679e-60c1-72ca-a36f-2428be671374
Co-authored-by: Basit Mustafa <basit.mustafa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants