session_state = {} # session_id -> {"step_a_done": False}

def tool_b(session_id, **kwargs):

state = session_state.setdefault(session_id, {"step_a_done": False})

if not state["step_a_done"]:

a normal tool error, not an exception that kills the connection

return {

"isError": True,

"content": [{"type": "text", "text": "call tool_a first — tool_b requires its output"}],

}

... do the real work

原文来源:dev.to