in computer-use-demo/computer_use_demo/streamlit.py [0:0]
def maybe_add_interruption_blocks():
if not st.session_state.in_sampling_loop:
return []
# If this function is called while we're in the sampling loop, we can assume that the previous sampling loop was interrupted
# and we should annotate the conversation with additional context for the model and heal any incomplete tool use calls
result = []
last_message = st.session_state.messages[-1]
previous_tool_use_ids = [
block["id"] for block in last_message["content"] if block["type"] == "tool_use"
]
for tool_use_id in previous_tool_use_ids:
st.session_state.tools[tool_use_id] = ToolResult(error=INTERRUPT_TOOL_ERROR)
result.append(
BetaToolResultBlockParam(
tool_use_id=tool_use_id,
type="tool_result",
content=INTERRUPT_TOOL_ERROR,
is_error=True,
)
)
result.append(BetaTextBlockParam(type="text", text=INTERRUPT_TEXT))
return result