Skip to content

fix: read tools and system prompt from TranscriptContext for pi v0.86.0+ - #108

Merged
patlux merged 3 commits into
patlux:mainfrom
domye:fix/v0860-transcript-context
Sep 24, 2026
Merged

patlux merged 3 commits into
patlux:mainfrom
domye:fix/v0860-transcript-context

Conversation

@domye

@domye domye commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

pi v0.86.0 changed the stream input from Context to TranscriptContext, where system prompt and tool declarations are embedded in context.messages instead of top-level properties. Use getCurrentTools/getCurrentSystemPrompt from @earendil-works/pi-ai to extract them, falling back to direct properties for backward compatibility.

pi v0.86.0 changed the stream input from Context to TranscriptContext,
where system prompt and tool declarations are embedded in context.messages
instead of top-level properties. Use getCurrentTools/getCurrentSystemPrompt
from @earendil-works/pi-ai to extract them, falling back to direct
properties for backward compatibility.
@transtone

Copy link
Copy Markdown

not fixed yet:

 The user wants me to read a document. Let me use the read_file tool properly. It seems my previous attempts had malformed tool calls. Let me do it correctly.

 <invoke name="read_file">
 <parameter name="path">xx.md</parameter>
 </invoke>
 </invoke>

@pierreraby

Copy link
Copy Markdown
Collaborator

Independently reproduced the same root cause and verified the fix end-to-end (pi 0.87.1, provider 0.7.1):

  • normalizeContext() returns a context whose only key is messages — context.tools and context.systemPrompt are undefined on any TranscriptContext host.
  • I fed such a context into createStreamCommandCode with a stub fetch and intercepted the /alpha/generate body: tools: [], system: "", while reasoning_effort was still forwarded. With no tool declarations the model answers with prose tool calls the host cannot execute — exactly the symptom in cant make tool calls. #110 and can't read file #109.
  • getCurrentTools / getCurrentSystemPrompt over the transcript restore both; messagesToCC already skips system messages, so passing the full transcript message list is safe.

One concern with this PR as written: it imports the readers in src/core.ts, which is deliberately free of pi-ai imports — cf. the calculateCost copy in src/cost.ts, kept because Oh My Pi's pi-ai shim does not export everything (issue #24). A named ESM import from a package missing the export fails at load, not at call, so this could break extension loading on OMP. Resolving the context in the host-aware layer (index.ts, which already works around host differences), with the readers kept optional and short-circuiting when the context already carries both fields, would keep legacy/OMP hosts working.

Also note the reporter of #109 says this approach resolves their case, which matches my verification.

pi 0.86+ passes providers a TranscriptContext whose system prompt and tool
declarations live in system messages, so the /alpha/generate request sent
no tools and an empty system prompt. Resolve them in index.ts through pi-ai's
transcript readers, probed at runtime like registerApiProvider, instead of a
named import in core.ts that failed typecheck and extension loading on Oh My
Pi. Hosts that still pass the flat fields are unchanged.
@patlux
patlux merged commit cec9dc1 into patlux:main Sep 24, 2026
13 checks passed
@patlux

patlux commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Shipped in [email protected] / GitHub release v0.7.2.

Thanks @domye for finding the TranscriptContext change and @pierreraby for the verification and the host-aware suggestion. I moved the lookup into index.ts with a runtime probe so Oh My Pi keeps loading, and added a real-pi regression test for the generate fallback.

Anhydrite added a commit to Anhydrite/pi-commandcode-provider that referenced this pull request Oct 6, 2026
…i >= 0.86

pi 0.86 replaced the flat Context (systemPrompt/tools) with a TranscriptContext
where prompt and tool declarations live in role="system" transcript messages.
The generate transport builds its own request body and read context.tools
directly, so on pi >= 0.86 it declared no tools at all and models wrote tool
calls as plain text instead of calling them.

Resolve the pi-ai transcript readers at runtime (probed, so pi < 0.86 still
loads) and replay the current prompt and tools before building the request.

Ported from upstream patlux/pi-commandcode-provider patlux#108.
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.

4 participants