Repository navigation
fix(agent): run on_response_received when resumed history holds SDK models - #40
Merged
Merged
Conversation
…odels A live turn stores the SDK's pydantic function_call item in conversation state. The resume path only matched dict-like history items, so with an in-memory state accessor the caller's function_call_output skipped the tool's on_response_received hook and output validation and was sent to the model unchanged. Read history and output items through their dumped form so both representations match.
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
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
Risk: an app that uses a HITL tool's
on_response_receivedhook to strip private fields from a human/backend result, and keepsConversationStatein memory betweencall_model()calls, sent the raw unfilteredfunction_call_outputto the model. The hook and the tool'soutput_schemavalidation were both skipped.Cause: a live turn stores the generated SDK's pydantic
OutputFunctionCallItemin state.apply_on_response_received_hooksbuilt itscallId -> tool namemap only fromMappingitems, so on resume the historical call was not found and the output passed through unchanged. A serialize/deserialize round trip turns the history into dicts, which is why persisted state was not affected.Fix:
apply_on_response_received_hooksmatchesfunction_callandfunction_call_outputitems throughdump(item)when they are not mappings. Items it doesn't rewrite are returned as they came in (pydantic models stay pydantic;_sendstill normalizes at the transport boundary).The TypeScript agent is not affected: its history items are plain objects and
isFunctionCallItemchecksitem.typedirectly.Tests:
tests/unit/test_hitl_model_history.pyadds a unit test for the hook dispatcher with a pydantic history item and an end-to-end test that uses the realOpenRouterclient and SSE decoder overhttpx.MockTransportwith an in-memory state accessor. Both fail onmainand pass with this change.ruff check,ruff format --check,mypy src testsandpytest tests/unitpass locally.