from langchain.messages import AIMessage def format_block(block: dict) -> str: block_type = block.get("type", "unknown") if block_type == "reasoning": return f"reasoning: {block.get('reasoning', '')}" if block_type == "text": return f"text: {block.get('text', '')}" if block_type == "tool_call": return f"tool_call: {block.get('name')} args={block.get('args')}" return f"{block_type}: {block}" response = AIMessage( content=[ { "type": "reasoning", "id": "rs_demo", "reasoning": "Need the order ID before calling the lookup tool.", }, { "type": "text", "text": "I will check the order status.", "id": "msg_demo", }, ], tool_calls=[{ "name": "lookup_order", "args": {"order_id": "A1001"}, "id": "call_demo", }], ) for position, block in enumerate(response.content_blocks, start=1): print(f"{position}. {format_block(block)}")