Fix mislabeled proposal recommendations via structured crew output#29
Open
Kishore-2572 wants to merge 1 commit into
Open
Fix mislabeled proposal recommendations via structured crew output#29Kishore-2572 wants to merge 1 commit into
Kishore-2572 wants to merge 1 commit into
Conversation
run_crew_evaluation() parsed the proposal-review crew's decision by
scanning its free-text output for the substring "accept" before
"counter". Negotiation writeups routinely contain that substring
elsewhere ("not acceptable as submitted", "Decision (Accept/Counter/
Reject)"), so a real "Counter" decision was frequently mislabeled as
"accept" -- confirmed across 6 of 16 cases in a Gemini test matrix,
always in that direction, and reproduced independently on GPT-4o.
Adds ProposalDecision/ProposalReviewOutput (models/flow_state.py) and
wires them in as the crew's final task output_pydantic schema
(crews/inventory_crews.py), so the decision is read from a typed field
instead of grepped out of prose.
Also fixes crew.kickoff() -> await crew.kickoff_async() in the same
function: the sync call raises immediately when invoked from this
async context, which was silently caught and fell back to rule-based
evaluation -- a prerequisite for the crew ever actually running here.
Verified against real API calls: GPT-4o returns a clean
ProposalDecision.COUNTER directly, and re-running gemini-2.5-flash's
previously-mislabeled below-floor scenario now correctly returns
Counter instead of the old parser's false Accept.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Fix mislabeled proposal recommendations via structured crew output
Problem: POST /proposals runs an AI crew to negotiate a proposal and returns its decision (accept/counter/reject) in the recommendation field. The code read this by scanning the AI's full text response for the word "accept" — but negotiation write-ups routinely contain that word elsewhere ("not acceptable as submitted", "Decision (Accept/Counter/Reject)"), so a real Counter decision was often reported as accept. Confirmed in 6 of 16 test cases, always in that direction — never the reverse.
Fix: the crew's final task now returns a typed, structured decision (via CrewAI's output_pydantic) instead of free text to scan. recommendation is read directly from that field, so there's nothing left to misparse. Also fixed a related bug in the same function — a blocking crew call from async code, which crashed silently and masked the AI's real decision behind a rule-based guess.
Verified: re-ran the previously-mislabeled case — now correctly reports counter instead of accept. No change to the response shape; recommendation still returns the same three values, just reliably now.