Skip to content

feat(maf): emit final response as result update - #11

Merged
zxyao145 merged 1 commit into
mainfrom
feature/final-response-result-update
Sep 17, 2026
Merged

zxyao145 merged 1 commit into
mainfrom
feature/final-response-result-update

Conversation

@zxyao145

Copy link
Copy Markdown
Owner

Summary

Surfaces the Codex agent's final response as a result update so consumers no longer have to reassemble streamed text to know the answer.

  • RunStreamingAsync now emits a result AgentResponseUpdate immediately before the terminal update (turn.completed, turn.failed or thread error). The update is intentionally not re-saving anything to chat history.
  • RunAsync appends the same final response as a result chat message, so it is part of AgentResponse.Messages.
  • On failure the result carries the error message instead of the agent message (last agent_message wins on success; turn.failed / thread error message wins otherwise).
  • New shared helper ThreadEventExtensions.CreateResultUpdate sets type = "result", ChatRole.Assistant, AuthorName = "codex" and the normalized model name.

Changes

  • src/CodexSdk.MAF/CodexAIAgent.cs — track the final response in both the streaming and non-streaming paths and emit/append it.
  • src/CodexSdk.MAF/Internal/ThreadEventExtensions.cs — add CreateResultUpdate.
  • tests/CodexSdk.MAF.Tests/CodexAIAgentResultUpdateTests.cs (new) — streaming/RunAsync success and failure coverage.
  • tests/CodexSdk.MAF.Tests/ThreadEventExtensionsTests.cs — unit test for CreateResultUpdate.
  • tests/FakeCodexCli/Program.cs — failure injection via CODEX_TEST_FAILURE (turn, thread).
  • tests/Support/FakeCodexCli.cs — expose CreateOptions() and forward the failure mode.

Verification

  • dotnet test: 47 passed, 0 failed (CodexSdk.Tests 12, CodexSdk.MAF.Tests 35).
  • New tests assert that on success exactly one result update is emitted, positioned directly before turn.completed, with Role = Assistant and AuthorName = codex.
  • Failure paths are covered for both turn.failed ("model unavailable") and thread error ("stream disconnected"), asserting the result text equals the error message in both the streaming and RunAsync paths.

Surface the last agent message as a "result" AgentResponseUpdate right
before the terminal event, and include it as a chat message in
AgentResponse. On failures (turn.failed / thread error) the result
carries the error message instead.

Extend FakeCodexCli with failure injection and add tests covering the
success, turn failure and thread error paths.
@zxyao145
zxyao145 enabled auto-merge September 17, 2026 15:32
@zxyao145
zxyao145 merged commit 5b923c9 into main Sep 17, 2026
4 checks passed
@zxyao145
zxyao145 deleted the feature/final-response-result-update branch September 19, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant