feat: expose final_message step output for defense-in-depth review workflows#1355
Open
stanley1208 wants to merge 1 commit into
Open
feat: expose final_message step output for defense-in-depth review workflows#1355stanley1208 wants to merge 1 commit into
stanley1208 wants to merge 1 commit into
Conversation
Adds a final_message output containing the agent's final text response. The use case is read-only review workflows where the AI job runs with contents:read only, and a separate job with pull-requests:write posts the response (defense-in-depth). Today the only way to get this text is parsing execution_file, which has no documented format. Follows the same pattern as openai/codex-action's final-message output that anthropics#1317 references. Includes 10 unit tests for the extraction helper. Closes anthropics#1317
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.
Closes #1317.
Adds a
final_messagestep output containing the agent's final text response, pulled from the last message in the SDK stream.The use case the issue describes is read-only review workflows: run the AI job with
contents: readonly, then post the response from a separate job that haspull-requests: write. Right now you can't really do that. The only way to get the response text is to parseexecution_file, which has no documented format. Theopenai/codex-actionrepo solves it with afinal-messageoutput, which is what the issue references.Usage
A note on naming
The issue uses
final-message(kebab-case) because that's what codex-action uses. I went withfinal_message(snake_case) to match the other outputs in this repo (execution_file,structured_output,session_id). Easy to swap if you'd rather match codex-action.How it works
A small helper called
extractFinalAssistantMessageinbase-action/src/run-claude-sdk.tswalks the message stream backwards, finds the last assistant message, and joins its text blocks. If the last action was a tool call (no text), the output is undefined. The intent is that "final message" should mean what the agent actually said.Wired through both layers (the standalone base-action and the parent action). Added 10 unit tests for the edge cases: empty stream, multiple text blocks, text + tool_use mixed, tool-only last message, malformed content.
Checks
Ran
bun test(10 new pass, no regressions),bun run typecheck, andbun run format:check.