fix(sdk): add Query.continue() to resume after a failed model turn#82
Open
amish-pratap-singh-lyzr wants to merge 1 commit into
Open
Conversation
Previously, when the model returned stopReason "error"/"aborted", query() surfaced a system error message and ended the session with no way to retry or resume — Query.steer() was also a no-op stub. Both are now wired into pi-agent-core's Agent instance: - steer(message) queues a steering message via agent.steer(). - continue(message?) resumes a session that has gone idle. With no argument it retries the exact turn the model failed to answer (dropping the failed assistant message so the transcript ends on the user/tool-result message it never responded to, per pi-agent-core's continue() contract). With a message, it queues a follow-up turn. The internal message channel can now reopen after finishing, since a completed query's async iterator may be resumed by continue().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
query()had no way to recover when the model failed to return output. When a turn ended withstopReason: "error"(or"aborted"), the SDK just emitted a system error message and ended the session — no retry, no continuation.Query.steer()was also a no-op stub (steer(_message) {}), despite the underlying@mariozechner/pi-agent-coreAgentalready exposing workingsteer()/followUp()/continue()primitives that were simply never wired up.This PR wires both up:
steer(message)now actually queues a steering message viaagent.steer(...)instead of doing nothing. Effective while the agent is still actively running a turn.continue(message?)(new) resumes a session that has gone idle — most importantly after a failed turn:agent.continue()re-sends it (matchespi-agent-core's documentedcontinue()contract: "Continue from the current transcript. The last message must be a user or tool-result message.").agent.followUp(...)and resumes.reopen()so a query whose async iterator already reachedagent_end/done: truecan resume streaming oncecontinue()is called.Test plan
npm run build(tsc) — clean, no type errorsnpm test— all existing 27 tests pass unchanged; added 4 new tests covering thecontinue()/steer()guard paths (method presence, rejecting before the agent has loaded, matching priorsteer()behavior)pi-agent-core's realAgentclass with a fakestreamFnthat fails once then succeeds — confirmedcontinue()produces a clean transcript (user message + successful assistant reply) rather than leaving the failed message in place