fix(agent): finalize max-iteration turns without tools
This commit is contained in:
@@ -70,14 +70,36 @@ def should_stream_budget_response(
|
||||
message_metadata: Mapping[str, Any] | None = None,
|
||||
) -> bool:
|
||||
"""Return whether the budget-boundary response should be sent to the user."""
|
||||
return not _continuation_available(
|
||||
stop_reason=stop_reason,
|
||||
if stop_reason != "max_iterations":
|
||||
return True
|
||||
return should_finalize_on_max_iterations(
|
||||
pending_queue_available=pending_queue_available,
|
||||
session_metadata=session_metadata,
|
||||
message_metadata=message_metadata,
|
||||
)
|
||||
|
||||
|
||||
def should_finalize_on_max_iterations(
|
||||
*,
|
||||
pending_queue_available: bool,
|
||||
session_metadata: Mapping[str, Any] | None,
|
||||
message_metadata: Mapping[str, Any] | None = None,
|
||||
) -> bool:
|
||||
"""Return whether a max-iteration boundary should produce a final response.
|
||||
|
||||
When a sustained goal can continue internally, the current runner slice
|
||||
should stop without spending an extra no-tools finalization call. The next
|
||||
queued continuation slice owns the eventual user-visible response.
|
||||
"""
|
||||
return not (
|
||||
pending_queue_available
|
||||
and _goal_continuation_available(
|
||||
session_metadata,
|
||||
message_metadata=message_metadata,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def maybe_continue_turn(ctx: Any) -> bool:
|
||||
"""Queue an internal continuation for *ctx* when policy allows it."""
|
||||
if ctx.session is None or ctx.pending_queue is None:
|
||||
|
||||
Reference in New Issue
Block a user