fix: Dont return another no-op tc if no-op already in state (#1011)

This commit is contained in:
Brace Sproul 2026-03-04 18:15:00 -08:00 • committed by GitHub
parent c0f17d32d8
commit f2dc5950f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,12 +38,23 @@ def check_if_confirming_completion(messages: list[AnyMessage]) -> bool:
return False
def check_if_no_op(messages: list[AnyMessage]) -> bool:
for msg in messages:
if msg.type == "tool" and msg.name == "no_op":
return True
return False
@after_model
def ensure_no_empty_msg(state: AgentState, runtime: Runtime) -> dict[str, Any] | None:
last_msg = state["messages"][-1]
has_contents = bool(last_msg.text())
has_tool_calls = bool(last_msg.tool_calls)
if not has_tool_calls and not has_contents:
messages_since_last_human = get_every_message_since_last_human(state)
if check_if_no_op(messages_since_last_human):
return None
tc_id = str(uuid4())
last_msg.tool_calls = [{"name": "no_op", "args": {}, "id": tc_id}]
no_op_tool_msg = ToolMessage(