Resume the agent run after code execution and stream SSE chunks. Reconstructs the agent context with the provided execution result, runs the agent, emits tool events, and finally yields the agent's final output (or an error event if none was produced).
(
base: dict[str, Any], task_id: str, exec_result: str, oidc_token: str | None = None
)
| 223 | |
| 224 | |
| 225 | async def resume_agent_flow( |
| 226 | base: dict[str, Any], task_id: str, exec_result: str, oidc_token: str | None = None |
| 227 | ) -> AsyncGenerator[str, None]: |
| 228 | """Resume the agent run after code execution and stream SSE chunks. |
| 229 | |
| 230 | Reconstructs the agent context with the provided execution result, runs the |
| 231 | agent, emits tool events, and finally yields the agent's final output (or an |
| 232 | error event if none was produced). |
| 233 | """ |
| 234 | try: |
| 235 | logger.info( |
| 236 | "resume[%s] model=%s files=%d history=%d", |
| 237 | task_id, |
| 238 | base.get("model"), |
| 239 | len(base.get("project", {})), |
| 240 | len(base.get("message_history", [])), |
| 241 | ) |
| 242 | except Exception: |
| 243 | pass |
| 244 | |
| 245 | # Filter project on resume as well (the resume token may carry previous project) |
| 246 | original_project = base.get("project", {}) or {} |
| 247 | is_ignored = make_ignore_predicate(original_project) |
| 248 | filtered_project = { |
| 249 | p: c |
| 250 | for p, c in original_project.items() |
| 251 | if (not is_ignored(p)) or (p in {".gitignore", ".agentignore"}) |
| 252 | } |
| 253 | |
| 254 | base_payload = { |
| 255 | "user_id": base["user_id"], |
| 256 | "query": base["query"], |
| 257 | "project": filtered_project, |
| 258 | "message_history": base.get("message_history", []), |
| 259 | "model": base.get("model"), |
| 260 | } |
| 261 | |
| 262 | # Truncate very large execution logs to keep prompts under token limits |
| 263 | trimmed_result = exec_result or "" |
| 264 | if len(trimmed_result) > 100_000: |
| 265 | trimmed_result = trimmed_result[-100_000:] |
| 266 | |
| 267 | context = IDEContext( |
| 268 | project=filtered_project, |
| 269 | base_payload=base_payload, |
| 270 | exec_result=trimmed_result, |
| 271 | ) |
| 272 | |
| 273 | history = base.get("message_history", []) |
| 274 | assistant_only = [ |
| 275 | m["content"] |
| 276 | for m in history |
| 277 | if m.get("role") == "assistant" and m.get("content") |
| 278 | ] |
| 279 | input_text = build_project_input( |
| 280 | base["query"], filtered_project, history or assistant_only |
| 281 | ) |
| 282 |
no test coverage detected