Repository navigation
fix(py): enforce generate invariants for system=, docs= media, restart input, and max_turns - #83
Merged
Conversation
huangjeff5
force-pushed
the
fix/py-1.0-pr3b-generate-loop-invariants
branch
from
November 11, 2026 06:22
92d4a2d to
1b4c470
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr3b-generate-loop-invariants
branch
from
November 11, 2026 18:38
1b4c470 to
0e716c1
Compare
…t input, and max_turns - max_turns: validated up front. True, nan, inf, and 2.5 raise INVALID_ARGUMENT instead of running as 1 or leaking a ValidationError. A whole float like 3.0 from a .prompt file still works. Default stays 50 tool rounds. - restart(replace_input=...): history and the model's next turn carry the input the tool ran with. replacedInput is stripped from the history part so it doesn't read as a pending restart. A restart that pauses again pauses on the approved input. - system= with messages=: prepended; system messages already in history are sent as stored. system='' adds nothing. - prompt= with resume_respond/resume_restart: fails FAILED_PRECONDITION / INVALID_RESUME before the model runs, and the message names prompt=. - docs=: text only, `- [ref]: text`; metadata and media stay out of the prompt. Skipping docs= because a context part already exists now logs. - AgentInterrupt.metadata exposes the Interrupt(...) payload. - A bare restart() reads as resumed in ctx.is_resumed() and on the span. - Resume validation errors in reject_unanswered_interrupts set reason=INVALID_RESUME.
huangjeff5
force-pushed
the
fix/py-1.0-pr3b-generate-loop-invariants
branch
from
November 12, 2026 06:37
0e716c1 to
c387d9d
Compare
huangjeff5
changed the base branch from
fix/py-1.0-pr3-generation-loop
to
main
November 12, 2026 06:40
apascal07
approved these changes
Nov 12, 2026
…tions, and interrupt metadata
Merged
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.
Prompt sanitization keeps vector embeddings and database ACLs out of model prompts,
system=messages with history are prepended instead of clobbered, human-in-the-loop restarts record the approved input, andmax_turnsis validated up front.Main Changes
docs=[Document(...)]intoai.generate()allowed internal document metadata (vector embeddings, database ACLs, tenant IDs) to bleed into provider prompt text. We now format documents strictly as- [ref]: <text>using onlyref/idand text content, preventing sensitive backend metadata from leaking to model providers.restart(replace_input=...), conversation history and the next model turn retained the original, unapproved request. We now rewrite the stored tool request to the approved input and stripreplacedInputso subsequent turns do not misinterpret it as an unhandled interrupt.system=prepends cleanly to existing history: Previously, passing bothsystem='...'andmessages=[...]clobbered or mishandled existing system messages in conversation history. We now prepend the new system message to the front of history, matching Go and JS behavior. Passingsystem=''is a no-op.prompt=alongsideresume_respondorresume_restartfailed deep in generation with an obscure message-role error becauseprompt=appends a user turn after the paused tool request. We now fail immediately before calling the model withFAILED_PRECONDITIONandINVALID_RESUME, explicitly namingprompt=in the error message. Unanswered interrupts passed toreject_unanswered_interruptsalso carryreason=ErrorReason.INVALID_RESUME.max_turns: Previously, the check only validatedmax_turns < 0, so Python'sisinstance(True, int)causedmax_turns=Trueto run as1tool turn, whilenanand2.5caused internal runtime errors. We now validate thatmax_turnsis a non-negative whole number, while continuing to accept whole floats (3.0) loaded from.promptfiles.