fix(ai): creation dossier+fichier en mode agent (BUG-050)
CI / lint (push) Successful in 1m32s
CI / security (push) Successful in 1m7s
CI / test (push) Successful in 3m6s
CI / build (push) Successful in 55s
CI / e2e (push) Successful in 10m48s

This commit is contained in:
2026-09-16 21:10:38 -04:00
parent 0d4f43a8bf
commit 634d10cdd4
18 changed files with 168 additions and 22 deletions
+30 -1
View File
@@ -109,6 +109,30 @@ def _assistant_tool_message(content: str | None, tool_calls: list[Any]) -> dict[
}
def _deferred_tool_message(call: Any) -> dict[str, Any]:
"""Answer a tool call that was not reached because the run paused.
A single LLM response may carry several tool calls. When one of them is
mutating and pauses the run for confirmation, the assistant message already
lists *all* of them, so every ``tool_call_id`` must get a tool result before
the next LLM call (the OpenAI tool protocol rejects dangling ids). The calls
that were not reached get a synthetic ``deferred`` result; the model
re-issues them once the confirmed call has been applied (BUG-050).
"""
return {
"role": "tool",
"tool_call_id": call.id,
"name": call.name,
"content": json.dumps({
"status": "deferred",
"reason": (
"Not executed: the run paused to confirm an earlier tool call. "
"Re-issue this call if it is still needed."
),
}, ensure_ascii=False),
}
def _execute_confirmed(
ctx: ToolContext,
confirm_pending: dict[str, Any],
@@ -248,7 +272,7 @@ async def run_agent(
_emit_note(response.content or "")
convo.append(_assistant_tool_message(response.content, response.tool_calls))
for call in response.tool_calls:
for index, call in enumerate(response.tool_calls):
if quota is not None and len(executed) >= quota:
logger.warning(f"Agent reached the tool-call quota ({quota})")
return AgentResult(
@@ -268,6 +292,11 @@ async def run_agent(
pending = e.to_dict()
# Include the tool-call id so the client can echo it back.
pending["error"]["id"] = call.id
# BUG-050: the assistant message lists every tool call of this
# batch, so answer the ones we did not reach to keep the
# conversation valid for the resumed turn.
for skipped in response.tool_calls[index + 1:]:
convo.append(_deferred_tool_message(skipped))
return AgentResult(
content=response.content or "",
messages=convo,