Preserve agent question answers and plan output

This commit is contained in:
Ryan Ward
2026-08-25 12:56:25 -05:00
parent b29f35e0fb
commit 78b60af988
5 changed files with 90 additions and 6 deletions
+32 -1
View File
@@ -294,13 +294,44 @@ impl AIAgentActionResultType {
| Self::FetchConversation(_)
| Self::StartAgent(_)
| Self::SendMessageToAgent(_)
| Self::AskUserQuestion(_)
| Self::WaitForEvents(_) => self.to_string(),
Self::AskUserQuestion(result) => ask_user_question_result_content(result),
Self::RunAgents(result) => result.model_content(),
}
}
}
fn ask_user_question_result_content(result: &AskUserQuestionResult) -> String {
match result {
AskUserQuestionResult::Success { answers } => {
let answers = answers
.iter()
.map(|answer| match answer {
AskUserQuestionAnswerItem::Answered {
question_id,
selected_options,
other_text,
} => serde_json::json!({
"question_id": question_id,
"selected_options": selected_options,
"other_text": other_text,
}),
AskUserQuestionAnswerItem::Skipped { question_id } => serde_json::json!({
"question_id": question_id,
"skipped": true,
}),
})
.collect::<Vec<_>>();
serde_json::json!({ "answers": answers }).to_string()
}
AskUserQuestionResult::SkippedByAutoApprove { question_ids } => serde_json::json!({
"skipped_by_auto_approve": question_ids,
})
.to_string(),
AskUserQuestionResult::Error(_) | AskUserQuestionResult::Cancelled => result.to_string(),
}
}
fn command_result_content(command: Option<&str>, output: &str, exit_code: i32) -> String {
let command = command
.map(|command| format!("Command: {command}\n"))
+20 -3
View File
@@ -1,9 +1,26 @@
use super::{
AIAgentActionResultType, RequestCommandOutputResult, RunAgentsAgentOutcome,
RunAgentsAgentOutcomeKind, RunAgentsLaunchedExecutionMode, RunAgentsResult, StartAgentResult,
StartAgentVersion,
AIAgentActionResultType, AskUserQuestionAnswerItem, AskUserQuestionResult,
RequestCommandOutputResult, RunAgentsAgentOutcome, RunAgentsAgentOutcomeKind,
RunAgentsLaunchedExecutionMode, RunAgentsResult, StartAgentResult, StartAgentVersion,
};
#[test]
fn ask_user_question_model_content_includes_selected_answers() {
let result = AIAgentActionResultType::AskUserQuestion(AskUserQuestionResult::Success {
answers: vec![AskUserQuestionAnswerItem::Answered {
question_id: "scope".to_string(),
selected_options: vec!["Provider-neutral pane plus agent tool".to_string()],
other_text: String::new(),
}],
});
let content: serde_json::Value = serde_json::from_str(&result.model_content()).unwrap();
assert_eq!(
content["answers"][0]["selected_options"][0],
"Provider-neutral pane plus agent tool"
);
}
#[test]
fn shell_execution_error_is_failed_but_not_cancelled() {
let result =