Improve agent provider resilience
This commit is contained in:
@@ -1010,6 +1010,29 @@ impl ProviderRun {
|
||||
Ok(ModelFailureDisposition::RunFailed)
|
||||
}
|
||||
|
||||
/// Parks a failed model call so its transcript can be compacted before retrying it.
|
||||
/// The run and current work identity are intentionally unchanged.
|
||||
pub fn prepare_context_compaction(
|
||||
&mut self,
|
||||
work_id: &ExternalWorkId,
|
||||
) -> Result<(), ProviderRunProtocolError> {
|
||||
let call = match &self.state {
|
||||
ProviderRunState::AwaitingModel { call } => call,
|
||||
ProviderRunState::ReadyToCallModel
|
||||
| ProviderRunState::ResolvingModel { .. }
|
||||
| ProviderRunState::AwaitingTools { .. }
|
||||
| ProviderRunState::AwaitingDriver { .. }
|
||||
| ProviderRunState::Done { .. }
|
||||
| ProviderRunState::Failed { .. }
|
||||
| ProviderRunState::Cancelled { .. } => {
|
||||
return Err(self.unexpected_state(ProviderRunPhase::AwaitingModel));
|
||||
}
|
||||
};
|
||||
validate_work_id(&call.work_id, work_id)?;
|
||||
self.state = ProviderRunState::ReadyToCallModel;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn request_tool_permission(
|
||||
&mut self,
|
||||
work_id: &ExternalWorkId,
|
||||
|
||||
@@ -1265,6 +1265,19 @@ fn transcript_compaction_is_rejected_during_a_model_call() {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_compaction_preserves_run_and_work_identity() {
|
||||
let mut run = run();
|
||||
let call = next_model_call(&mut run);
|
||||
let run_id = run.id().clone();
|
||||
|
||||
run.prepare_context_compaction(&call.work_id).unwrap();
|
||||
|
||||
assert_eq!(run.id(), &run_id);
|
||||
assert_eq!(run.ready_work_id(), Some(call.work_id));
|
||||
assert_eq!(run.state().phase(), ProviderRunPhase::ReadyToCallModel);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_normalization_commits_a_fully_resolved_batch() {
|
||||
let mut run = run();
|
||||
|
||||
Reference in New Issue
Block a user