| 160 | } |
| 161 | |
| 162 | fn format_task_result_for_context(result: &TaskResult) -> (String, bool) { |
| 163 | let (output, truncated) = compact_task_output(&result.output); |
| 164 | let status = if result.success { |
| 165 | "completed" |
| 166 | } else { |
| 167 | "failed" |
| 168 | }; |
| 169 | let artifact_id = task_artifact_id(result); |
| 170 | let artifact_uri = task_artifact_uri(result); |
| 171 | let mut formatted = format!( |
| 172 | "Task {status}: {}\nAgent: {}\nSession: {}\nTask ID: {}\nArtifact ID: {}\nArtifact URI: {}\n", |
| 173 | result.task_id, result.agent, result.session_id, result.task_id, artifact_id, artifact_uri |
| 174 | ); |
| 175 | if truncated { |
| 176 | formatted.push_str( |
| 177 | "Output excerpt: truncated for parent context. Use the artifact URI or child run session/events if exact omitted content is needed.\n", |
| 178 | ); |
| 179 | } else { |
| 180 | formatted.push_str("Output:\n"); |
| 181 | } |
| 182 | formatted.push_str(&output); |
| 183 | (formatted, truncated) |
| 184 | } |
| 185 | |
| 186 | /// Task executor for delegated child runs. |
| 187 | pub struct TaskExecutor { |